@@ -89,8 +89,8 @@ router.post("/files", async (ctx) => {
8989 await Files . create ( {
9090 id : fileId ,
9191 filename : path . basename ( realFilePath ) ,
92- filesize : ( await fsp . stat ( realFilePath ) ) . size ,
93- filelocation : fileUrl ,
92+ file_size : ( await fsp . stat ( realFilePath ) ) . size ,
93+ file_location : fileUrl ,
9494 real_file_location : realFilePath ,
9595 created_by : ctx . query . createdBy || "anonymous" ,
9696 is_public : isFilePublic ,
@@ -179,9 +179,9 @@ router.get("/files", async (ctx) => {
179179 "public_expiration" ,
180180 "updated_at" ,
181181 "updated_by" ,
182- "filesize " ,
182+ "file_size " ,
183183 "filename" ,
184- "filelocation " ,
184+ "file_location " ,
185185 "thumb_location" ,
186186 "is_public" ,
187187 ] ,
@@ -216,12 +216,11 @@ router.get("/files/:id", async (ctx) => {
216216 attributes : [
217217 "id" ,
218218 "filename" ,
219- "is_delete" ,
220219 "is_public" ,
221220 "public_expiration" ,
222221 "is_thumb" ,
223- "filesize " ,
224- "filelocation " ,
222+ "file_size " ,
223+ "file_location " ,
225224 "thumb_location" ,
226225 "mime" ,
227226 "ext" ,
@@ -248,6 +247,69 @@ router.get("/files/:id", async (ctx) => {
248247 }
249248} ) ;
250249
250+ // 编辑文件信息接口
251+ router . put ( '/files/:id' , async ( ctx ) => {
252+ const { id } = ctx . params ;
253+ const {
254+ filename,
255+ is_public,
256+ updated_by,
257+ public_expiration,
258+ public_by,
259+ } = ctx . request . body ;
260+
261+ try {
262+ // 查找文件
263+ const file = await Files . findOne ( {
264+ where : {
265+ id,
266+ is_delete : false ,
267+ }
268+ } ) ;
269+
270+ if ( ! file ) {
271+ ctx . status = 404 ;
272+ ctx . body = { message : 'File not found' } ;
273+ return ;
274+ }
275+
276+ // 更新文件信息
277+ await file . update ( {
278+ filename,
279+ is_public,
280+ updated_by,
281+ updated_at : new Date ( ) ,
282+ public_expiration,
283+ public_by,
284+ } ) ;
285+
286+ const updatedFile = {
287+ id : file . id ,
288+ filename : file . filename ,
289+ is_public : file . is_public ,
290+ public_expiration : file . public_expiration ,
291+ is_thumb : file . is_thumb ,
292+ file_size : file . file_size ,
293+ file_location : file . file_location ,
294+ thumb_location : file . thumb_location ,
295+ mime : file . mime ,
296+ ext : file . ext ,
297+ created_at : file . created_at ,
298+ created_by : file . created_by ,
299+ updated_at : file . updated_at ,
300+ updated_by : file . updated_by ,
301+ } ;
302+
303+ // 返回更新后的文件信息
304+ ctx . body = updatedFile ;
305+ } catch ( error ) {
306+ ctx . status = 500 ;
307+ ctx . body = { message : 'Error updating file information' , error : error . message } ;
308+ console . error ( 'Update file error:' , error ) ;
309+ }
310+ } ) ;
311+
312+
251313// 文件预览
252314router . get ( "/files/:id/preview" , async ( ctx ) => {
253315 const { id } = ctx . params ;
@@ -266,7 +328,6 @@ router.get("/files/:id/preview", async (ctx) => {
266328 } ,
267329 attributes : [
268330 "filename" ,
269- "is_delete" ,
270331 "is_public" ,
271332 "public_expiration" ,
272333 "real_file_location" ,
0 commit comments