feat: upload apk

This commit is contained in:
louis 2024-04-07 16:28:14 +08:00
parent cdf010b96a
commit 2d71fdf001
3 changed files with 12 additions and 8 deletions

View File

@ -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
}
});

View File

@ -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);

View File

@ -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) {