Skip to content

Commit 153db8b

Browse files
committed
Simplify delete
1 parent 7450976 commit 153db8b

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

server/routers/api.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -166,30 +166,34 @@ export const shlApiRouter = new oak.Router()
166166
added,
167167
};
168168
})
169+
.delete('/shl/:shlId/file/all', async (context) => {
170+
const managementToken = await context.request.headers.get('authorization')?.split(/bearer /i)[1]!;
171+
const currentFileBody = await context.request.body({type: 'bytes'});
172+
173+
const shl = db.DbLinks.getManagedShl(context.params.shlId, managementToken);
174+
if (!shl) {
175+
throw new Error(`Can't manage SHLink ` + context.params.shlId);
176+
}
177+
178+
const deleted = db.DbLinks.deleteAllFiles(shl.id);
179+
context.response.body = {
180+
...shl,
181+
deleted,
182+
}
183+
})
169184
.delete('/shl/:shlId/file', async (context) => {
170185
const managementToken = await context.request.headers.get('authorization')?.split(/bearer /i)[1]!;
186+
const currentFileBody = await context.request.body({type: 'bytes'});
187+
171188
const shl = db.DbLinks.getManagedShl(context.params.shlId, managementToken);
172189
if (!shl) {
173190
throw new Error(`Can't manage SHLink ` + context.params.shlId);
174191
}
175-
if (!context.request.hasBody) {
176-
console.log("deleting all files for shlink "+shl.id);
177-
const success = db.DbLinks.deleteAllFiles(shl.id);
178-
context.response.body = {
179-
...shl,
180-
success,
181-
}
182-
} else {
183-
const currentFileBody = await context.request.body().value;
184-
console.log("Current file body is: '"+currentFileBody+"'");
185-
if (currentFileBody.length > 0) {
186-
console.log("deleting single file");
187-
const success = db.DbLinks.deleteFile(shl.id, currentFileBody);
188-
context.response.body = {
189-
...shl,
190-
success,
191-
}
192-
}
192+
193+
const deleted = db.DbLinks.deleteFile(shl.id, await currentFileBody.value);
194+
context.response.body = {
195+
...shl,
196+
deleted,
193197
}
194198
})
195199
.post('/shl/:shlId/endpoint', async (context) => {

0 commit comments

Comments
 (0)