summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2024-12-19 12:33:11 -0500
committerHazelnoot <acomputerdog@gmail.com>2024-12-19 12:33:11 -0500
commit0de93c2bde78bd4c4c7aed87d42cd7054955b4b2 (patch)
tree148e3ac79164fd7262dfed91f61c3cd4177f5e0f /packages/backend/src
parentadd file extension to locally-stored media (diff)
downloadsharkey-0de93c2bde78bd4c4c7aed87d42cd7054955b4b2.tar.gz
sharkey-0de93c2bde78bd4c4c7aed87d42cd7054955b4b2.tar.bz2
sharkey-0de93c2bde78bd4c4c7aed87d42cd7054955b4b2.zip
only attach file extension for browser-safe file types
Diffstat (limited to 'packages/backend/src')
-rw-r--r--packages/backend/src/core/DriveService.ts22
1 files changed, 18 insertions, 4 deletions
diff --git a/packages/backend/src/core/DriveService.ts b/packages/backend/src/core/DriveService.ts
index 99e0ea98dd..734ce6b88f 100644
--- a/packages/backend/src/core/DriveService.ts
+++ b/packages/backend/src/core/DriveService.ts
@@ -148,7 +148,6 @@ export class DriveService {
@bindThis
private async save(file: MiDriveFile, path: string, name: string, info: FileInfo): Promise<MiDriveFile> {
const type = info.type.mime;
- const ext = info.type.ext;
const hash = info.md5;
const size = info.size;
@@ -228,9 +227,11 @@ export class DriveService {
return await this.driveFilesRepository.insertOne(file);
} else { // use internal storage
- const accessKey = `${randomUUID()}.${ext}`;
- const thumbnailAccessKey = `thumbnail-${randomUUID()}.${ext}`;
- const webpublicAccessKey = `webpublic-${randomUUID()}.${ext}`;
+ const ext = FILE_TYPE_BROWSERSAFE.includes(type) ? info.type.ext : null;
+
+ 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.
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('');
+}