fix:更新优化23
This commit is contained in:
parent
dd9b985917
commit
a1d0a24098
@ -53,15 +53,16 @@ export class UploadMiddleware implements NestMiddleware {
|
||||
|
||||
use(req: Request, _res: Response, next: NextFunction): void {
|
||||
// @types/express 与 @types/multer 内嵌的 @types/express-serve-static-core 版本不一致,
|
||||
// 运行时完全等价,这里用一次类型断言绕过编译期差异
|
||||
const single = this.upload.single('file') as (
|
||||
// 运行时完全等价,用 unknown 中转两次绕过编译期差异
|
||||
const single = this.upload.single('file') as unknown as (
|
||||
req: Request,
|
||||
res: Response,
|
||||
cb: (err: unknown) => void,
|
||||
) => void;
|
||||
single(req, _res, (err) => {
|
||||
if (err) {
|
||||
next(new BadRequestException(err.message ?? '文件上传失败'));
|
||||
const msg = err instanceof Error ? err.message : '文件上传失败';
|
||||
next(new BadRequestException(msg));
|
||||
return;
|
||||
}
|
||||
next();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user