fix: complete first version issue remediation

This commit is contained in:
hectorzhao
2026-07-11 10:14:37 +08:00
parent 709ac97764
commit 208a6c23f8
73 changed files with 1549 additions and 245 deletions
+12 -2
View File
@@ -66,14 +66,15 @@ export class FilesService {
}
async upload(data: UploadFileDto, file: { originalname: string; mimetype: string; size: number; buffer: Buffer }) {
const safeName = file.originalname.replace(/[^\w.\-\u4e00-\u9fa5]/g, '_');
const fileName = normalizeMultipartFileName(file.originalname);
const safeName = fileName.replace(/[^\w.\-\u4e00-\u9fa5]/g, '_');
const objectKey = `${data.prefix ?? data.purpose}/${Date.now()}-${randomUUID()}-${safeName}`;
await this.objectStorage.putObject(objectKey, file.buffer, file.size, file.mimetype || 'application/octet-stream');
return this.create({
tenantId: data.tenantId,
bucket: this.objectStorage.getBucket(),
objectKey,
fileName: file.originalname,
fileName,
contentType: file.mimetype || 'application/octet-stream',
sizeBytes: file.size,
purpose: data.purpose,
@@ -93,6 +94,15 @@ export class FilesService {
}
}
function normalizeMultipartFileName(value: string) {
if (![...value].some((character) => character.charCodeAt(0) > 0x7f) || [...value].some((character) => character.charCodeAt(0) > 0xff)) {
return value;
}
const decoded = Buffer.from(value, 'latin1').toString('utf8');
return decoded.includes('\uFFFD') ? value : decoded;
}
function serializeFileObject<T extends { sizeBytes: bigint | number | string }>(fileObject: T) {
return {
...fileObject,