File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
apps/sim/lib/uploads/contexts/workspace Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -209,8 +209,9 @@ export async function uploadWorkspaceFile(
209209
210210/**
211211 * Track a file that was already uploaded to workspace S3 as a chat-scoped upload.
212- * Creates a workspaceFiles record with context='mothership' and the given chatId.
213- * No S3 operations -- the file is already in storage from the presigned/upload step.
212+ * Links the existing workspaceFiles metadata record (created by the storage service
213+ * during upload) to the chat by setting chatId and context='mothership'.
214+ * Falls back to inserting a new record if none exists for the key.
214215 */
215216export async function trackChatUpload (
216217 workspaceId : string ,
@@ -221,6 +222,17 @@ export async function trackChatUpload(
221222 contentType : string ,
222223 size : number
223224) : Promise < void > {
225+ const updated = await db
226+ . update ( workspaceFiles )
227+ . set ( { chatId, context : 'mothership' } )
228+ . where ( and ( eq ( workspaceFiles . key , s3Key ) , isNull ( workspaceFiles . deletedAt ) ) )
229+ . returning ( { id : workspaceFiles . id } )
230+
231+ if ( updated . length > 0 ) {
232+ logger . info ( `Linked existing file record to chat: ${ fileName } for chat ${ chatId } ` )
233+ return
234+ }
235+
224236 const fileId = `wf_${ Date . now ( ) } _${ Math . random ( ) . toString ( 36 ) . substring ( 2 , 9 ) } `
225237
226238 await db . insert ( workspaceFiles ) . values ( {
You can’t perform that action at this time.
0 commit comments