Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 5 additions & 7 deletions src/utils/imageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,7 @@ export async function uploadImage(
}
const ext = mime.split("/")[1];

let filename: string;
if (fileUrl) {
const { fileName } = extractFilePathAndNameFromUrl(fileUrl);
filename = fileName;
} else {
filename = `${uuidv4()}.${ext}`;
}
const filename:string = `${uuidv4()}.${ext}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix type annotation spacing.

The type annotation is missing a space after the colon, and there's an extra space before the equals sign.

Apply this diff to fix the formatting:

-  const filename:string =  `${uuidv4()}.${ext}`;
+  const filename: string = `${uuidv4()}.${ext}`;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const filename:string = `${uuidv4()}.${ext}`;
const filename: string = `${uuidv4()}.${ext}`;
🤖 Prompt for AI Agents
In src/utils/imageUtils.ts around line 40, the const declaration's type
annotation has incorrect spacing; remove the extra space before the equals sign
and add a single space after the colon so the declaration uses standard spacing
for type annotations and assignment (i.e., make the colon followed by one space
and no space before =).


const filePath = `${folder}/${filename}`;

Expand All @@ -66,6 +60,10 @@ export async function uploadImage(
throw new ApiError("Failed to get public URL", 500);
}

if (fileUrl) {
await deleteImage(supabase, fileUrl);
}

return urlData.publicUrl;
}

Expand Down
5 changes: 3 additions & 2 deletions tests/imageUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("imageUtils", () => {
storageMock = {
from: jest.fn().mockReturnThis(),
upload: jest.fn(),
getPublicUrl: jest.fn(),
getPublicUrl: jest.fn(),
remove: jest.fn(),
};

Expand Down Expand Up @@ -61,6 +61,7 @@ describe("imageUtils", () => {
storageMock.getPublicUrl.mockReturnValue({
data: { publicUrl: "https://public.url/existing.png" },
});
storageMock.remove.mockReturnValue({error:null});

const url = await uploadImage(
mockSupabase as SupabaseClient,
Expand All @@ -70,7 +71,7 @@ describe("imageUtils", () => {
);
// Should use filename 'existing.png' instead of generating with uuid
expect(storageMock.upload).toHaveBeenCalledWith(
"folder/existing.png",
"folder/test-uuid.png",
dummyFile.buffer,
{ contentType: dummyFile.mimetype, upsert: true },
);
Expand Down