fix: 将 RateLimitService 注入从 StorageService 移到 FilesService
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 56s
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 56s
StorageService 在 @Global StorageModule 中,无法注入 AppModule 的 RateLimitService。 将限流调用上移到 FilesService.requestUploadUrl 中。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
c30f7cdb63
commit
ca90d34b22
@ -1,7 +1,6 @@
|
||||
import { Injectable, BadRequestException } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { CosStorageProvider } from './cos-storage.provider';
|
||||
import { RateLimitService } from '../../common/utils/rate-limit.service';
|
||||
import {
|
||||
sanitizeFilename,
|
||||
validateFileUpload,
|
||||
@ -32,7 +31,6 @@ export class StorageService {
|
||||
constructor(
|
||||
private readonly cos: CosStorageProvider,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly rateLimit: RateLimitService,
|
||||
) {}
|
||||
|
||||
getUploadPath(filename: string): string {
|
||||
@ -56,7 +54,6 @@ export class StorageService {
|
||||
expiresIn = 3600,
|
||||
): Promise<UploadUrlResult> {
|
||||
validateFileUpload(input.mimeType, input.sizeBytes);
|
||||
await this.rateLimit.fileUploadLimit(userId);
|
||||
|
||||
const objectKey = this.generateObjectKey(userId, input.filename);
|
||||
const result = await this.cos.generateUploadUrl(objectKey, expiresIn);
|
||||
|
||||
@ -6,6 +6,7 @@ import {
|
||||
import { FilesRepository } from './files.repository';
|
||||
import { StorageService } from '../../infrastructure/storage/storage.service';
|
||||
import { CosStorageProvider } from '../../infrastructure/storage/cos-storage.provider';
|
||||
import { RateLimitService } from '../../common/utils/rate-limit.service';
|
||||
import { CreateUploadUrlDto, CompleteUploadDto } from './dto';
|
||||
|
||||
@Injectable()
|
||||
@ -14,9 +15,11 @@ export class FilesService {
|
||||
private readonly repository: FilesRepository,
|
||||
private readonly storage: StorageService,
|
||||
private readonly cos: CosStorageProvider,
|
||||
private readonly rateLimit: RateLimitService,
|
||||
) {}
|
||||
|
||||
async requestUploadUrl(userId: string, dto: CreateUploadUrlDto) {
|
||||
await this.rateLimit.fileUploadLimit(userId);
|
||||
return this.storage.createUploadUrl(userId, {
|
||||
filename: dto.filename,
|
||||
mimeType: dto.mimeType,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user