mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-04-29 18:16:58 +00:00
only attach file extension for browser-safe file types
This commit is contained in:
parent
ad63f55a0f
commit
0de93c2bde
1 changed files with 18 additions and 4 deletions
|
@ -148,7 +148,6 @@ export class DriveService {
|
||||||
@bindThis
|
@bindThis
|
||||||
private async save(file: MiDriveFile, path: string, name: string, info: FileInfo): Promise<MiDriveFile> {
|
private async save(file: MiDriveFile, path: string, name: string, info: FileInfo): Promise<MiDriveFile> {
|
||||||
const type = info.type.mime;
|
const type = info.type.mime;
|
||||||
const ext = info.type.ext;
|
|
||||||
const hash = info.md5;
|
const hash = info.md5;
|
||||||
const size = info.size;
|
const size = info.size;
|
||||||
|
|
||||||
|
@ -228,9 +227,11 @@ export class DriveService {
|
||||||
|
|
||||||
return await this.driveFilesRepository.insertOne(file);
|
return await this.driveFilesRepository.insertOne(file);
|
||||||
} else { // use internal storage
|
} else { // use internal storage
|
||||||
const accessKey = `${randomUUID()}.${ext}`;
|
const ext = FILE_TYPE_BROWSERSAFE.includes(type) ? info.type.ext : null;
|
||||||
const thumbnailAccessKey = `thumbnail-${randomUUID()}.${ext}`;
|
|
||||||
const webpublicAccessKey = `webpublic-${randomUUID()}.${ext}`;
|
const accessKey = makeFileKey(ext);
|
||||||
|
const thumbnailAccessKey = makeFileKey(ext, 'thumbnail');
|
||||||
|
const webpublicAccessKey = makeFileKey(ext, 'webpublic');
|
||||||
|
|
||||||
// Ugly type is just to help TS figure out that 2nd / 3rd promises are optional.
|
// Ugly type is just to help TS figure out that 2nd / 3rd promises are optional.
|
||||||
const promises: [Promise<string>, ...(Promise<string> | undefined)[]] = [
|
const promises: [Promise<string>, ...(Promise<string> | undefined)[]] = [
|
||||||
|
@ -867,3 +868,16 @@ export class DriveService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makeFileKey(ext: string | null, prefix?: string): string {
|
||||||
|
const parts: string[] = [randomUUID()];
|
||||||
|
|
||||||
|
if (prefix) {
|
||||||
|
parts.unshift(prefix, '-');
|
||||||
|
}
|
||||||
|
if (ext) {
|
||||||
|
parts.push('.', ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts.join('');
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue