diff options
| author | Marie <github@yuugi.dev> | 2025-05-07 08:49:50 +0000 |
|---|---|---|
| committer | Marie <github@yuugi.dev> | 2025-05-07 08:49:50 +0000 |
| commit | 4eab54d2ca1a02949d825583fedf1c29060e59aa (patch) | |
| tree | 0e7a9f67b033099da4a727e00f579c32cce5d209 /packages/backend/src/core/DriveService.ts | |
| parent | merge: remove http/https protocol in uri on masto api (!980) (diff) | |
| parent | update comment (diff) | |
| download | sharkey-4eab54d2ca1a02949d825583fedf1c29060e59aa.tar.gz sharkey-4eab54d2ca1a02949d825583fedf1c29060e59aa.tar.bz2 sharkey-4eab54d2ca1a02949d825583fedf1c29060e59aa.zip | |
merge: Add BunnyCDN Edge Storage support (!952)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/952
Closes #1020
Approved-by: Hazelnoot <acomputerdog@gmail.com>
Approved-by: dakkar <dakkar@thenautilus.net>
Diffstat (limited to 'packages/backend/src/core/DriveService.ts')
| -rw-r--r-- | packages/backend/src/core/DriveService.ts | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/packages/backend/src/core/DriveService.ts b/packages/backend/src/core/DriveService.ts index a65059b417..bca8c576f0 100644 --- a/packages/backend/src/core/DriveService.ts +++ b/packages/backend/src/core/DriveService.ts @@ -44,6 +44,7 @@ import { correctFilename } from '@/misc/correct-filename.js'; import { isMimeImage } from '@/misc/is-mime-image.js'; import { ModerationLogService } from '@/core/ModerationLogService.js'; import { UtilityService } from '@/core/UtilityService.js'; +import { BunnyService } from '@/core/BunnyService.js'; type AddFileArgs = { /** User who wish to add file */ @@ -121,6 +122,7 @@ export class DriveService { private downloadService: DownloadService, private internalStorageService: InternalStorageService, private s3Service: S3Service, + private bunnyService: BunnyService, private imageProcessingService: ImageProcessingService, private videoProcessingService: VideoProcessingService, private globalEventService: GlobalEventService, @@ -405,20 +407,28 @@ export class DriveService { ); if (this.meta.objectStorageSetPublicRead) params.ACL = 'public-read'; - await this.s3Service.upload(this.meta, params) - .then( - result => { - if ('Bucket' in result) { // CompleteMultipartUploadCommandOutput - this.registerLogger.debug(`Uploaded: ${result.Bucket}/${result.Key} => ${result.Location}`); - } else { // AbortMultipartUploadCommandOutput - this.registerLogger.error(`Upload Result Aborted: key = ${key}, filename = ${filename}`); - } - }) - .catch( + if (this.bunnyService.usingBunnyCDN(this.meta)) { + await this.bunnyService.upload(this.meta, key, stream).catch( err => { this.registerLogger.error(`Upload Failed: key = ${key}, filename = ${filename}`, err); }, ); + } else { + await this.s3Service.upload(this.meta, params) + .then( + result => { + if ('Bucket' in result) { // CompleteMultipartUploadCommandOutput + this.registerLogger.debug(`Uploaded: ${result.Bucket}/${result.Key} => ${result.Location}`); + } else { // AbortMultipartUploadCommandOutput + this.registerLogger.error(`Upload Result Aborted: key = ${key}, filename = ${filename}`); + } + }) + .catch( + err => { + this.registerLogger.error(`Upload Failed: key = ${key}, filename = ${filename}`, err); + }, + ); + } } // Expire oldest file (without avatar or banner) of remote user @@ -814,8 +824,11 @@ export class DriveService { Bucket: this.meta.objectStorageBucket, Key: key, } as DeleteObjectCommandInput; - - await this.s3Service.delete(this.meta, param); + if (this.bunnyService.usingBunnyCDN(this.meta)) { + await this.bunnyService.delete(this.meta, key); + } else { + await this.s3Service.delete(this.meta, param); + } } catch (err: any) { if (err.name === 'NoSuchKey') { this.deleteLogger.warn(`The object storage had no such key to delete: ${key}. Skipping this.`, err as Error); |