Skip to content
Open
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
11 changes: 7 additions & 4 deletions src/r2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,10 +645,13 @@ export const createR2Endpoints = (

// Store file metadata in database
try {
await ctx.context.adapter.create({
const newFile = await ctx.context.adapter.create({
model: modelName,
data: {
id: fileMetadata.id,
// You are trying to create a record with an id.
// This is not allowed as we handle id generation for you.
// The id will be ignored.
// id: fileMetadata.id,
Comment on lines +651 to +654
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

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

This multi-line comment explaining why the ID is commented out should be removed. Commented-out code with explanatory notes is typically not appropriate for production code. If the ID field should not be set, it should simply be omitted rather than left as a commented line with an explanation.

Consider removing lines 651-654 entirely.

Suggested change
// You are trying to create a record with an id.
// This is not allowed as we handle id generation for you.
// The id will be ignored.
// id: fileMetadata.id,

Copilot uses AI. Check for mistakes.
Copy link
Owner

Choose a reason for hiding this comment

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

this would need to be removed, yes

userId: fileMetadata.userId,
filename: fileMetadata.filename,
originalName: fileMetadata.originalName,
Expand All @@ -660,7 +663,7 @@ export const createR2Endpoints = (
},
});

ctx.context.logger?.info("[R2]: File metadata saved to database:", fileMetadata.id);
ctx.context.logger?.info("[R2]: File metadata saved to database:", newFile.id);
} catch (dbError) {
ctx.context.logger?.error("[R2]: Failed to save to database:", dbError);

Expand All @@ -678,7 +681,7 @@ export const createR2Endpoints = (

return ctx.json({
success: true,
data: fileMetadata,
data: { ...fileMetadata, id: newFile.id },
});
} catch (error) {
ctx.context.logger?.error("[R2]: Upload failed:", error);
Expand Down
Loading