summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authorMarie <github@yuugi.dev>2025-03-28 14:31:41 +0100
committerMarie <github@yuugi.dev>2025-03-28 14:31:41 +0100
commit76b0c1ce26cda27f73e49181101b449f5d9d600c (patch)
tree429952f69cc4b6ff3dff1c59f335f7f4ea4db52b /packages/backend/src
parentupd: remove default endpoint value (diff)
downloadsharkey-76b0c1ce26cda27f73e49181101b449f5d9d600c.tar.gz
sharkey-76b0c1ce26cda27f73e49181101b449f5d9d600c.tar.bz2
sharkey-76b0c1ce26cda27f73e49181101b449f5d9d600c.zip
Apply suggestions
Diffstat (limited to 'packages/backend/src')
-rw-r--r--packages/backend/src/core/BunnyService.ts25
1 files changed, 18 insertions, 7 deletions
diff --git a/packages/backend/src/core/BunnyService.ts b/packages/backend/src/core/BunnyService.ts
index 5d7c621cb2..1563bc2711 100644
--- a/packages/backend/src/core/BunnyService.ts
+++ b/packages/backend/src/core/BunnyService.ts
@@ -22,10 +22,10 @@ export class BunnyService {
@bindThis
public getBunnyInfo(meta: MiMeta) {
return {
- endpoint: meta.objectStorageEndpoint ?? '',
- accessKey: meta.objectStorageSecretKey ?? '',
- zone: meta.objectStorageBucket ?? '',
- prefix: meta.objectStoragePrefix ?? '',
+ endpoint: meta.objectStorageEndpoint,
+ accessKey: meta.objectStorageSecretKey,
+ zone: meta.objectStorageBucket,
+ fullUrl: `https://${meta.objectStorageEndpoint}/${meta.objectStorageBucket}`,
};
}
@@ -33,9 +33,16 @@ export class BunnyService {
public async upload(meta: MiMeta, path: string, input: fs.ReadStream | Buffer) {
const client = this.getBunnyInfo(meta);
- // Required to convert the buffer from webpulic and thumbnail to a ReadableStream for PUT
+ 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;
+ const agent = this.httpRequestService.getAgentByUrl(new URL(`${client.fullUrl}/${path}`), !meta.objectStorageUseProxy, true);
+
+ // Seperation of path and host/domain is required here
const options = {
method: 'PUT',
host: client.endpoint,
@@ -44,6 +51,7 @@ export class BunnyService {
AccessKey: client.accessKey,
'Content-Type': 'application/octet-stream',
},
+ agent: agent,
};
const req = https.request(options);
@@ -56,13 +64,16 @@ export class BunnyService {
data.destroy();
});
- // wait till stream gets destroyed upon finish of piping to prevent the UI from showing the upload as success wait too early
+ // wait till stream gets destroyed upon finish of piping to prevent the UI from showing the upload as success way too early
await finished(data);
}
@bindThis
public delete(meta: MiMeta, file: string) {
const client = this.getBunnyInfo(meta);
- return this.httpRequestService.send(`https://${client.endpoint}/${client.zone}/${file}`, { method: 'DELETE', headers: { AccessKey: client.accessKey } });
+ if (!client.endpoint || !client.zone || !client.accessKey) {
+ return;
+ }
+ return this.httpRequestService.send(`${client.fullUrl}/${file}`, { method: 'DELETE', headers: { AccessKey: client.accessKey } });
}
}