fix: 修复上传文件名乱码的问题
自动部署 / build (push) Failing after 2s
Details
自动部署 / build (push) Failing after 2s
Details
parent
2fd52a3d98
commit
785ed04ccb
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -11,12 +11,12 @@ export class LoginLogInterceptor implements NestInterceptor {
|
||||||
tap({
|
tap({
|
||||||
next: (data) => {
|
next: (data) => {
|
||||||
const status = true;
|
const status = true;
|
||||||
const description = '登录成功';
|
const description = '用户登录成功';
|
||||||
this.recordLoginLog(context, { status, description });
|
this.recordLoginLog(context, { status, description });
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
const status = false;
|
const status = false;
|
||||||
const description = err?.message || '登录失败';
|
const description = err?.message || '用户登录失败';
|
||||||
this.recordLoginLog(context, { status, description });
|
this.recordLoginLog(context, { status, description });
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,35 @@
|
||||||
import { ConfigService } from '@/config';
|
import { ConfigService } from '@/config';
|
||||||
|
import { dayjs } from '@/libraries';
|
||||||
import { Module, forwardRef } from '@nestjs/common';
|
import { Module, forwardRef } from '@nestjs/common';
|
||||||
import { MulterModule } from '@nestjs/platform-express';
|
import { MulterModule } from '@nestjs/platform-express';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { existsSync, mkdirSync } from 'fs';
|
import { existsSync, mkdirSync } from 'fs';
|
||||||
import { diskStorage } from 'multer';
|
import { diskStorage } from 'multer';
|
||||||
import { extname, join } from 'path';
|
import { extname, join } from 'path';
|
||||||
|
import { FileCategoryModule } from '../fileCategory';
|
||||||
import { File } from './entities/file.entity';
|
import { File } from './entities/file.entity';
|
||||||
import { FileController } from './file.controller';
|
import { FileController } from './file.controller';
|
||||||
import { FileService } from './file.service';
|
import { FileService } from './file.service';
|
||||||
import { dayjs } from '@/libraries';
|
|
||||||
import { FileCategoryModule } from '../fileCategory';
|
|
||||||
|
|
||||||
const MulteredModule = MulterModule.registerAsync({
|
const MulteredModule = MulterModule.registerAsync({
|
||||||
useFactory: (config: ConfigService) => {
|
useFactory: (config: ConfigService) => ({
|
||||||
return {
|
storage: diskStorage({
|
||||||
storage: diskStorage({
|
destination: (req, file, next) => {
|
||||||
destination: (req, file, next) => {
|
const dest = join(config.uploadDir, dayjs().format(dayjs.DATE));
|
||||||
const dest = join(config.uploadDir, dayjs().format(dayjs.DATE));
|
if (!existsSync(dest)) {
|
||||||
if (!existsSync(dest)) {
|
mkdirSync(dest, { recursive: true });
|
||||||
mkdirSync(dest, { recursive: true });
|
}
|
||||||
}
|
next(null, dest);
|
||||||
next(null, dest);
|
},
|
||||||
},
|
filename: (req, file, next) => {
|
||||||
filename: (req, file, next) => {
|
next(null, Date.now() + extname(file.originalname));
|
||||||
next(null, Date.now() + extname(file.originalname));
|
},
|
||||||
},
|
}),
|
||||||
}),
|
fileFilter(req, file, callback) {
|
||||||
};
|
file.originalname = Buffer.from(file.originalname, 'latin1').toString('utf-8');
|
||||||
},
|
callback(null, true);
|
||||||
|
},
|
||||||
|
}),
|
||||||
inject: [ConfigService],
|
inject: [ConfigService],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue