summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarie <github@yuugi.dev>2025-03-28 19:42:25 +0100
committerMarie <github@yuugi.dev>2025-03-28 19:42:25 +0100
commit003c37e84cd0cb5de595db178d8b0da65de30a73 (patch)
treeecd31ddb253909318cc685f97d3129fe4b868b43
parentupd: create usingBunnyCDN (diff)
downloadsharkey-003c37e84cd0cb5de595db178d8b0da65de30a73.tar.gz
sharkey-003c37e84cd0cb5de595db178d8b0da65de30a73.tar.bz2
sharkey-003c37e84cd0cb5de595db178d8b0da65de30a73.zip
upd: add comment, throw on missing details
-rw-r--r--packages/backend/src/core/BunnyService.ts15
1 files changed, 8 insertions, 7 deletions
diff --git a/packages/backend/src/core/BunnyService.ts b/packages/backend/src/core/BunnyService.ts
index 3931ccfdd1..4787954eef 100644
--- a/packages/backend/src/core/BunnyService.ts
+++ b/packages/backend/src/core/BunnyService.ts
@@ -21,8 +21,16 @@ export class BunnyService {
@bindThis
public getBunnyInfo(meta: MiMeta) {
+ if (!meta.objectStorageEndpoint || !meta.objectStorageBucket || !meta.objectStorageSecretKey) {
+ throw new Error('One of the following fields is empty: Endpoint, Bucket, Secret Key');
+ }
+
return {
endpoint: meta.objectStorageEndpoint,
+ /*
+ The way S3 works is that the Secret Key is essentially the password for the API but Bunny calls their password AccessKey so we call it accessKey here.
+ Bunny also doesn't specify a username/s3 access key when doing HTTP API requests so we end up not using our Access Key field from the form.
+ */
accessKey: meta.objectStorageSecretKey,
zone: meta.objectStorageBucket,
fullUrl: `https://${meta.objectStorageEndpoint}/${meta.objectStorageBucket}`,
@@ -38,10 +46,6 @@ export class BunnyService {
public async upload(meta: MiMeta, path: string, input: fs.ReadStream | Buffer) {
const client = this.getBunnyInfo(meta);
- if (!client.endpoint || !client.zone || !client.accessKey) {
- return console.error('Missing Information');
- }
-
// Required to convert the buffer from webpublic and thumbnail to a ReadableStream for PUT
const data = Buffer.isBuffer(input) ? Readable.from(input) : input;
@@ -76,9 +80,6 @@ export class BunnyService {
@bindThis
public delete(meta: MiMeta, file: string) {
const client = this.getBunnyInfo(meta);
- if (!client.endpoint || !client.zone || !client.accessKey) {
- return;
- }
return this.httpRequestService.send(`${client.fullUrl}/${file}`, { method: 'DELETE', headers: { AccessKey: client.accessKey } });
}
}