完善接单平台上传与物品规则

This commit is contained in:
yml2213
2026-07-25 15:56:18 +08:00
parent f6d3f00f21
commit a2587eda01
40 changed files with 4978 additions and 1008 deletions
+36
View File
@@ -0,0 +1,36 @@
import type { NextFunction, Request, Response } from 'express'
import multer from 'multer'
import { getMaxUploadSizeBytes } from '../services/file-storage/file-storage-service.js'
import { createHttpError, sendRouteError } from '../utils/http.js'
const upload = multer({
storage: multer.memoryStorage(),
limits: {
fileSize: getMaxUploadSizeBytes(),
files: 1,
},
})
export function uploadSingleFile(req: Request, res: Response, next: NextFunction): void {
upload.single('file')(req, res, (error: unknown) => {
if (!error) {
next()
return
}
const normalizedError =
error instanceof multer.MulterError && error.code === 'LIMIT_FILE_SIZE'
? createHttpError('文件超过上传大小限制', {
statusCode: 400,
errorCode: 'upload_file_too_large',
cause: error,
})
: createHttpError('文件上传失败', {
statusCode: 400,
errorCode: 'upload_file_invalid',
cause: error,
})
sendRouteError(res, normalizedError, '文件上传失败', '[files/upload]')
})
}