Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 3m0s
- 安装 cos-nodejs-sdk-v5,封装 CosStorageProvider(upload/download/delete/healthCheck)
- 重写 StorageService,新增 createUploadUrl/verifyUpload/getDownloadUrl/deleteObject
- 创建 FilesModule:POST /files/upload-url, POST /files/complete, GET /files/:id, DELETE /files/:id
- UploadedFile 新增 objectKey/bucket 字段
- 对象键格式 {userId}/{YYYYMM}/{sanitizedName}.{ext}
- 接入文件类型校验(ALLOWED_FILE_TYPES)+ 上传限流(10次/小时/用户)
- 配置文件 cos.longde.cloud → zhixi-1259685406 / ap-guangzhou
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
40 lines
981 B
TypeScript
40 lines
981 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { PrismaService } from '../../infrastructure/database/prisma.service';
|
|
|
|
@Injectable()
|
|
export class FilesRepository {
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
async create(data: {
|
|
userId: string;
|
|
filename: string;
|
|
mimeType?: string;
|
|
storagePath: string;
|
|
objectKey: string;
|
|
bucket: string;
|
|
sizeBytes: number;
|
|
checksum?: string;
|
|
}) {
|
|
return this.prisma.uploadedFile.create({ data });
|
|
}
|
|
|
|
async findById(id: string) {
|
|
return this.prisma.uploadedFile.findUnique({ where: { id } });
|
|
}
|
|
|
|
async findByObjectKey(objectKey: string) {
|
|
return this.prisma.uploadedFile.findFirst({ where: { objectKey } });
|
|
}
|
|
|
|
async findByUserId(userId: string) {
|
|
return this.prisma.uploadedFile.findMany({
|
|
where: { userId },
|
|
orderBy: { createdAt: 'desc' },
|
|
});
|
|
}
|
|
|
|
async delete(id: string) {
|
|
return this.prisma.uploadedFile.delete({ where: { id } });
|
|
}
|
|
}
|