mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 20:44:34 +00:00
upd: create usingBunnyCDN
This commit is contained in:
parent
76b0c1ce26
commit
0481b25a62
2 changed files with 8 additions and 3 deletions
|
@ -29,6 +29,11 @@ export class BunnyService {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@bindThis
|
||||||
|
public usingBunnyCDN(meta: MiMeta) {
|
||||||
|
return meta.objectStorageEndpoint && meta.objectStorageEndpoint.includes('bunnycdn.com') ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async upload(meta: MiMeta, path: string, input: fs.ReadStream | Buffer) {
|
public async upload(meta: MiMeta, path: string, input: fs.ReadStream | Buffer) {
|
||||||
const client = this.getBunnyInfo(meta);
|
const client = this.getBunnyInfo(meta);
|
||||||
|
@ -41,7 +46,7 @@ export class BunnyService {
|
||||||
const data = Buffer.isBuffer(input) ? Readable.from(input) : input;
|
const data = Buffer.isBuffer(input) ? Readable.from(input) : input;
|
||||||
|
|
||||||
const agent = this.httpRequestService.getAgentByUrl(new URL(`${client.fullUrl}/${path}`), !meta.objectStorageUseProxy, true);
|
const agent = this.httpRequestService.getAgentByUrl(new URL(`${client.fullUrl}/${path}`), !meta.objectStorageUseProxy, true);
|
||||||
|
|
||||||
// Seperation of path and host/domain is required here
|
// Seperation of path and host/domain is required here
|
||||||
const options = {
|
const options = {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
|
|
|
@ -407,7 +407,7 @@ export class DriveService {
|
||||||
);
|
);
|
||||||
if (this.meta.objectStorageSetPublicRead) params.ACL = 'public-read';
|
if (this.meta.objectStorageSetPublicRead) params.ACL = 'public-read';
|
||||||
|
|
||||||
if (this.meta.objectStorageEndpoint && this.meta.objectStorageEndpoint.includes('bunnycdn.com')) {
|
if (this.bunnyService.usingBunnyCDN(this.meta)) {
|
||||||
await this.bunnyService.upload(this.meta, key, stream);
|
await this.bunnyService.upload(this.meta, key, stream);
|
||||||
} else {
|
} else {
|
||||||
await this.s3Service.upload(this.meta, params)
|
await this.s3Service.upload(this.meta, params)
|
||||||
|
@ -820,7 +820,7 @@ export class DriveService {
|
||||||
Bucket: this.meta.objectStorageBucket,
|
Bucket: this.meta.objectStorageBucket,
|
||||||
Key: key,
|
Key: key,
|
||||||
} as DeleteObjectCommandInput;
|
} as DeleteObjectCommandInput;
|
||||||
if (this.meta.objectStorageEndpoint && this.meta.objectStorageEndpoint.includes('bunnycdn.com')) {
|
if (this.bunnyService.usingBunnyCDN(this.meta)) {
|
||||||
await this.bunnyService.delete(this.meta, key);
|
await this.bunnyService.delete(this.meta, key);
|
||||||
} else {
|
} else {
|
||||||
await this.s3Service.delete(this.meta, param);
|
await this.s3Service.delete(this.meta, param);
|
||||||
|
|
Loading…
Add table
Reference in a new issue