1
0

upd: add comment, throw on missing details

This commit is contained in:
Marie
2025-03-28 19:42:25 +01:00
parent 0481b25a62
commit 003c37e84c
+8 -7
View File
@@ -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 } });
}
}