Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix: Proper handling of empty assets in deleteProtocols #37

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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