@@ -61,7 +61,7 @@ export const GET: RequestHandler = async ({ params, request }) => {
6161 const files = await conn
6262 . selectFrom ( 'folder_files' )
6363 . innerJoin ( 'files' , 'files.id' , 'folder_files.file_id' )
64- . select ( [ 'files.id' , 'files.original_name' , 'files.size' ] )
64+ . select ( [ 'files.id' , 'files.original_name' , 'files.size' , 'files.path' ] )
6565 . where ( 'folder_files.folder_id' , '=' , id )
6666 . execute ( ) ;
6767
@@ -78,7 +78,10 @@ export const GET: RequestHandler = async ({ params, request }) => {
7878 const fileStat = await stat ( filePath ) . catch ( ( ) => null ) ;
7979
8080 if ( fileStat ) {
81- const entry = pack . entry ( { name : file . original_name , size : fileStat . size } ) ;
81+ const tarName = file . path
82+ ? path . posix . join ( file . path , file . original_name )
83+ : file . original_name ;
84+ const entry = pack . entry ( { name : tarName , size : fileStat . size } ) ;
8285 const rs = createReadStream ( filePath ) ;
8386 rs . pipe ( entry ) ;
8487 await new Promise < void > ( ( resolve , reject ) => {
@@ -139,6 +142,8 @@ export const POST: RequestHandler = async ({ params, request }) => {
139142 }
140143
141144 const originalName = path . basename ( header . name ) ;
145+ const relativePath = path . dirname ( header . name ) ;
146+ const dbPath = relativePath === '.' ? '' : relativePath ;
142147
143148 // Check if file with same name exists in folder
144149 const existingFile = await conn
@@ -221,7 +226,8 @@ export const POST: RequestHandler = async ({ params, request }) => {
221226 original_name : originalName ,
222227 mime_type : mimeType ,
223228 size : buffer . length ,
224- uploaded_by : user . id
229+ uploaded_by : user . id ,
230+ path : dbPath
225231 } )
226232 . execute ( ) ;
227233
0 commit comments