fix: file response
This commit is contained in:
@@ -10,9 +10,8 @@ import {
|
||||
Query,
|
||||
Req,
|
||||
Res,
|
||||
UseGuards,
|
||||
} from '@nestjs/common'
|
||||
import { Throttle, ThrottlerGuard } from '@nestjs/throttler'
|
||||
import { Throttle } from '@nestjs/throttler'
|
||||
|
||||
import { Auth } from '~/common/decorator/auth.decorator'
|
||||
import { HTTPDecorators } from '~/common/decorator/http.decorator'
|
||||
@@ -47,8 +46,7 @@ export class FileController {
|
||||
}
|
||||
|
||||
@Get('/:type/:name')
|
||||
@UseGuards(ThrottlerGuard)
|
||||
@Throttle(10, 60)
|
||||
@Throttle(60, 60)
|
||||
@HTTPDecorators.Bypass
|
||||
async get(@Param() params: FileQueryDto, @Res() reply: FastifyReply) {
|
||||
const { type, name } = params
|
||||
@@ -75,12 +73,13 @@ export class FileController {
|
||||
const { type = 'file' } = query
|
||||
|
||||
const ext = path.extname(file.filename)
|
||||
const filename = md5(file.filename) + ext
|
||||
const filename = md5(file.filename) + ext.toLowerCase()
|
||||
|
||||
await this.service.writeFile(type, filename, file.file)
|
||||
|
||||
return {
|
||||
path: await this.service.resolveFileUrl(type, filename),
|
||||
url: await this.service.resolveFileUrl(type, filename),
|
||||
name: filename,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,8 @@ export class FileService {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const filePath = this.resolveFilePath(type, name)
|
||||
if (await this.checkIsExist(filePath)) {
|
||||
throw new BadRequestException('文件已存在')
|
||||
reject(new BadRequestException('文件已存在'))
|
||||
return
|
||||
}
|
||||
await fs.mkdir(path.dirname(filePath), { recursive: true })
|
||||
|
||||
|
||||
Reference in New Issue
Block a user