diff --git a/src/common/adapters/fastify.adapter.ts b/src/common/adapters/fastify.adapter.ts index 65db5c9..a2caadc 100644 --- a/src/common/adapters/fastify.adapter.ts +++ b/src/common/adapters/fastify.adapter.ts @@ -13,7 +13,7 @@ app.register(FastifyMultipart, { attachFieldsToBody:true, limits: { fields: 10, // Max number of non-file fields - fileSize: 1024 * 1024 * 6, // limit size 6M + fileSize: 1024 * 1024 * 30, // limit size 6M files: 5 // Max number of file fields } }); diff --git a/src/modules/tools/upload/upload.service.ts b/src/modules/tools/upload/upload.service.ts index 8186817..0d79f9c 100644 --- a/src/modules/tools/upload/upload.service.ts +++ b/src/modules/tools/upload/upload.service.ts @@ -7,6 +7,7 @@ import { Repository } from 'typeorm'; import { Storage } from '~/modules/tools/storage/storage.entity'; import { + UploadFileType, fileRename, getExtname, getFilePath, @@ -37,7 +38,7 @@ export class UploadService { const size = getSize(file.file.bytesRead); const extName = getExtname(fileName); const type = getFileType(extName); - const name = fileRename(fileName); + const name = type !== UploadFileType.APK ? fileRename(fileName) : fileName; const path = getFilePath(name); saveLocalFile(await file.toBuffer(), name); diff --git a/src/utils/file.util.ts b/src/utils/file.util.ts index b7a41c5..73fe482 100644 --- a/src/utils/file.util.ts +++ b/src/utils/file.util.ts @@ -5,11 +5,12 @@ import { MultipartFile } from '@fastify/multipart'; import dayjs from 'dayjs'; -enum Type { +export enum UploadFileType { IMAGE = '图片', TXT = '文档', MUSIC = '音乐', VIDEO = '视频', + APK = 'apk', OTHER = '其他' } @@ -18,15 +19,17 @@ export function getFileType(extName: string) { const music = 'mp3 wav wma mpa ram ra aac aif m4a'; const video = 'avi mpg mpe mpeg asf wmv mov qt rm mp4 flv m4v webm ogv ogg'; const image = 'bmp dib pcp dif wmf gif jpg tif eps psd cdr iff tga pcd mpt png jpeg'; - if (image.includes(extName)) return Type.IMAGE; + const apk = 'apk'; + if (image.includes(extName)) return UploadFileType.IMAGE; - if (documents.includes(extName)) return Type.TXT; + if (documents.includes(extName)) return UploadFileType.TXT; - if (music.includes(extName)) return Type.MUSIC; + if (music.includes(extName)) return UploadFileType.MUSIC; - if (video.includes(extName)) return Type.VIDEO; + if (video.includes(extName)) return UploadFileType.VIDEO; - return Type.OTHER; + if (apk.includes(extName)) return UploadFileType.APK; + return UploadFileType.OTHER; } export function getName(fileName: string) {