diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-05-07 16:33:18 +0000 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-05-07 16:33:18 +0000 |
| commit | d39a56c1b7d74dd07cc78b4c82a6fb6e51036252 (patch) | |
| tree | 24f9c6baa07fadc11c791f1a59bee2c3149cbf56 /packages/backend/src/core/DriveService.ts | |
| parent | merge: Add BunnyCDN Edge Storage support (!952) (diff) | |
| parent | isNotUserHome > isUserHome (diff) | |
| download | sharkey-d39a56c1b7d74dd07cc78b4c82a6fb6e51036252.tar.gz sharkey-d39a56c1b7d74dd07cc78b4c82a6fb6e51036252.tar.bz2 sharkey-d39a56c1b7d74dd07cc78b4c82a6fb6e51036252.zip | |
merge: Merge upstream 2025.4.1 (!955)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/955
Closes #638, #1037, #734, and #766
Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Marie <github@yuugi.dev>
Diffstat (limited to 'packages/backend/src/core/DriveService.ts')
| -rw-r--r-- | packages/backend/src/core/DriveService.ts | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/packages/backend/src/core/DriveService.ts b/packages/backend/src/core/DriveService.ts index bca8c576f0..8cc7df1a81 100644 --- a/packages/backend/src/core/DriveService.ts +++ b/packages/backend/src/core/DriveService.ts @@ -179,7 +179,8 @@ export class DriveService { ?? `${ this.meta.objectStorageUseSSL ? 'https' : 'http' }://${ this.meta.objectStorageEndpoint }${ this.meta.objectStoragePort ? `:${this.meta.objectStoragePort}` : '' }/${ this.meta.objectStorageBucket }`; // for original - const key = `${this.meta.objectStoragePrefix}/${randomUUID()}${ext}`; + const prefix = this.meta.objectStoragePrefix ? `${this.meta.objectStoragePrefix}/` : ''; + const key = `${prefix}${randomUUID()}${ext}`; const url = `${ baseUrl }/${ key }`; // for alts @@ -196,7 +197,7 @@ export class DriveService { ]; if (alts.webpublic) { - webpublicKey = `${this.meta.objectStoragePrefix}/webpublic-${randomUUID()}.${alts.webpublic.ext}`; + webpublicKey = `${prefix}webpublic-${randomUUID()}.${alts.webpublic.ext}`; webpublicUrl = `${ baseUrl }/${ webpublicKey }`; this.registerLogger.info(`uploading webpublic: ${webpublicKey}`); @@ -204,7 +205,7 @@ export class DriveService { } if (alts.thumbnail) { - thumbnailKey = `${this.meta.objectStoragePrefix}/thumbnail-${randomUUID()}.${alts.thumbnail.ext}`; + thumbnailKey = `${prefix}thumbnail-${randomUUID()}.${alts.thumbnail.ext}`; thumbnailUrl = `${ baseUrl }/${ thumbnailKey }`; this.registerLogger.info(`uploading thumbnail: ${thumbnailKey}`); @@ -524,11 +525,23 @@ export class DriveService { const policies = await this.roleService.getUserPolicies(user.id); const driveCapacity = 1024 * 1024 * policies.driveCapacityMb; + const maxFileSize = 1024 * 1024 * policies.maxFileSizeMb; this.registerLogger.debug('drive capacity override applied'); this.registerLogger.debug(`overrideCap: ${driveCapacity}bytes, usage: ${usage}bytes, u+s: ${usage + info.size}bytes`); + if (maxFileSize < info.size) { + if (isLocalUser) { + throw new IdentifiableError('f9e4e5f3-4df4-40b5-b400-f236945f7073', 'Max file size exceeded.'); + } else { + // For remote users, throwing an exception will break Activity processing. + // Instead, force "link" mode which does not cache the file locally. + isLink = true; + } + } + // If usage limit exceeded - if (driveCapacity < usage + info.size) { + // Repeat the "!isLink" check because it could be set to true by the previous block. + if (driveCapacity < usage + info.size && !isLink) { if (isLocalUser) { throw new IdentifiableError('c6244ed2-a39a-4e1c-bf93-f0fbd7764fa6', 'No free space.', true); } |