@@ -6,9 +6,11 @@ const sharp = require("sharp");
66const tinify = require ( "tinify" ) ;
77const { Op } = require ( "sequelize" ) ;
88const { v4 : uuidv4 } = require ( "uuid" ) ;
9+ const JSZip = require ( "jszip" ) ;
10+ const { filesize } = require ( "filesize" ) ;
11+
912const { detectFileType } = require ( "../utils/detectFileType" ) ;
1013const Files = require ( "../models/files" ) ;
11- const JSZip = require ( "jszip" ) ;
1214const {
1315 imageMimeTypes,
1416 tinifySupportedMimeTypes,
@@ -224,7 +226,10 @@ router.get("/files", validateQuery(FILES_LIST_GET_QUERY), async (ctx) => {
224226 } ) ;
225227
226228 ctx . body = {
227- items : rows ,
229+ items : rows . map ( ( file ) => ( {
230+ ...file . dataValues ,
231+ file_size : filesize ( file . file_size ) ,
232+ } ) ) ,
228233 total : count ,
229234 } ;
230235 } catch ( error ) {
@@ -432,7 +437,6 @@ router.delete("/files", validateBody(FILES_BODY_BATCH_IDS), async (ctx) => {
432437router . get ( "/files/:id/preview" , validateParams ( FILES_REST_ID ) , async ( ctx ) => {
433438 const { id } = ctx . params ;
434439 const { type } = ctx . query ; // 获取查询参数 'type',可以是 'thumb' 或 'original'
435-
436440 try {
437441 const file = await Files . findOne ( {
438442 where : {
@@ -441,7 +445,7 @@ router.get("/files/:id/preview", validateParams(FILES_REST_ID), async (ctx) => {
441445 [ Op . or ] : [
442446 { public_expiration : null , is_public : true } ,
443447 { public_expiration : { [ Op . gt ] : new Date ( ) } , is_public : true } ,
444- { created_by : ctx . state . user . id } ,
448+ { created_by : ctx . state ? .user ? .id || null } ,
445449 ] ,
446450 } ,
447451 attributes : [
0 commit comments