@@ -100,8 +100,10 @@ export class FilesController {
100100 const filePath = `${ dirPath } /${ filename } ` . replace ( / \\ / g, '/' ) ;
101101 await FileUtils . createFileWithPermissions ( filePath , buffer ) ;
102102
103+ const userId = ( request as any ) . user ?. id as string | undefined ;
104+
103105 // Sync file after upload
104- await FilesController . syncFile ( filePath ) ;
106+ await FilesController . syncFile ( filePath , filename , userId ) ;
105107
106108 // Prepare response info
107109 const fileInfo = {
@@ -140,6 +142,7 @@ export class FilesController {
140142 await FileUtils . ensureDirectoryWithPermissions ( dirPath ) ;
141143
142144 const results = [ ] ;
145+ const userId = ( request as any ) . user ?. id as string | undefined ;
143146 for ( const file of files ) {
144147 const { base64, filename, mimetype } = file ;
145148 if ( ! base64 || ! filename || ! mimetype ) {
@@ -160,7 +163,7 @@ export class FilesController {
160163 await FileUtils . createFileWithPermissions ( filePath , buffer ) ;
161164
162165 // Sync file after upload
163- await FilesController . syncFile ( filePath ) ;
166+ await FilesController . syncFile ( filePath , filename , userId ) ;
164167
165168 results . push ( {
166169 fileName : filename ,
@@ -218,6 +221,8 @@ export class FilesController {
218221 }
219222 const sanitizedFiles = ( files as Express . Multer . File [ ] ) . map ( ( { fieldname, ...fileData } ) => fileData ) ;
220223
224+ const userId = ( request as any ) . user ?. id as string | undefined ;
225+
221226 // reduce value of key "path" to be relative to storage directory
222227 for ( const file of sanitizedFiles ) {
223228 // Save original filesystem path before overwriting
@@ -236,7 +241,7 @@ export class FilesController {
236241 Object . assign ( file , sanitizedFile ) ;
237242
238243 // Sync file after upload using the original filesystem path
239- await FilesController . syncFile ( originalFilePath , file . originalname ) ;
244+ await FilesController . syncFile ( originalFilePath , file . originalname , userId ) ;
240245 }
241246
242247 sendSuccess ( response , sanitizedFiles , 'Files uploaded successfully' , 200 ) ;
@@ -248,7 +253,7 @@ export class FilesController {
248253 * @param filePath Path to the file to sync
249254 * @param originalFilename Optional original filename before any transformations
250255 */
251- static async syncFile ( filePath : string , originalFilename ?: string ) : Promise < void > {
256+ static async syncFile ( filePath : string , originalFilename ?: string , userId ?: string ) : Promise < void > {
252257 try {
253258 // Normalize path separators
254259 const normalizedPath = filePath . replace ( / \\ / g, '/' ) ;
@@ -311,6 +316,7 @@ export class FilesController {
311316 createdAt : stats . birthtime . toISOString ( ) ,
312317 modifiedAt : stats . mtime . toISOString ( ) ,
313318 uploadedAt : new Date ( ) . toISOString ( ) ,
319+ userId : userId || null ,
314320 tags : [ storageFolder ] ,
315321 metadata : {
316322 storageFolder : storageFolder
0 commit comments