Skip to content

Commit 681e1d7

Browse files
committed
fix(uploads): preserve fallback size and reuse existing display name on re-register
1 parent 91c0772 commit 681e1d7

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

apps/sim/lib/uploads/contexts/workspace/workspace-file-manager.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export async function registerUploadedWorkspaceFile(params: {
299299
if (!head) {
300300
throw new Error('Uploaded object not found in storage')
301301
}
302-
verifiedSize = head.size ?? size
302+
verifiedSize = head.size > 0 ? head.size : size
303303
}
304304

305305
const cleanupOrphan = async (reason: string) => {
@@ -322,22 +322,23 @@ export async function registerUploadedWorkspaceFile(params: {
322322
throw new Error(quotaCheck.error || 'Storage limit exceeded')
323323
}
324324

325-
const uniqueName = await allocateUniqueWorkspaceFileName(workspaceId, originalName)
326-
327325
let fileId = `wf_${generateShortId()}`
326+
let displayName: string
328327
const existing = await getFileMetadataByKey(key, 'workspace')
329328
if (existing) {
330329
fileId = existing.id
330+
displayName = existing.originalName
331331
logger.info(`Using existing metadata record for direct upload: ${key}`)
332332
} else {
333+
displayName = await allocateUniqueWorkspaceFileName(workspaceId, originalName)
333334
try {
334335
await insertFileMetadata({
335336
id: fileId,
336337
key,
337338
userId,
338339
workspaceId,
339340
context: 'workspace',
340-
originalName: uniqueName,
341+
originalName: displayName,
341342
contentType,
342343
size: verifiedSize,
343344
})
@@ -362,7 +363,7 @@ export async function registerUploadedWorkspaceFile(params: {
362363

363364
return {
364365
id: fileId,
365-
name: uniqueName,
366+
name: displayName,
366367
size: verifiedSize,
367368
type: contentType,
368369
url: serveUrl,

0 commit comments

Comments
 (0)