Skip to content

Commit

Permalink
Merge pull request #37 from complexdatacollective/fix/protocol-delete
Browse files Browse the repository at this point in the history
Bug Fix: Proper handling of empty assets in `deleteProtocols`
  • Loading branch information
jthrilly authored Dec 4, 2023
2 parents 040d793 + 16ea1da commit a3f8390
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions server/routers/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ export const deleteProtocols = async (hashes: string[]) => {
select: { key: true },
});

if (assets.length === 0) {
// eslint-disable-next-line no-console
console.log('No assets to delete');
return;
}

await deleteFilesFromUploadThing(assets.map((a) => a.key));
} catch (error) {
// eslint-disable-next-line no-console
Expand All @@ -66,13 +60,19 @@ export const deleteProtocols = async (hashes: string[]) => {
export const deleteFilesFromUploadThing = async (
fileKey: string | string[],
) => {
if (fileKey.length === 0) {
// eslint-disable-next-line no-console
console.log('No assets to delete');
return;
}

const response = await utapi.deleteFiles(fileKey);

if (!response.success) {
throw new Error('Failed to delete files from uploadthing');
}

return response;
return;
};

export const protocolRouter = router({
Expand Down

0 comments on commit a3f8390

Please sign in to comment.