2024-06-17 16:01:35 +02:00
|
|
|
// classes.smartbucket.ts
|
|
|
|
|
2024-05-21 01:22:21 +02:00
|
|
|
import * as plugins from './plugins.js';
|
|
|
|
import { Bucket } from './classes.bucket.js';
|
2025-08-18 02:43:29 +00:00
|
|
|
import { normalizeS3Descriptor } from './helpers.js';
|
2018-09-14 18:07:20 +02:00
|
|
|
|
|
|
|
export class SmartBucket {
|
2024-02-10 04:36:34 +01:00
|
|
|
public config: plugins.tsclass.storage.IS3Descriptor;
|
2019-10-14 20:55:07 +02:00
|
|
|
|
2024-06-17 16:01:35 +02:00
|
|
|
public s3Client: plugins.s3.S3Client;
|
2019-10-14 23:53:41 +02:00
|
|
|
|
2024-06-17 16:01:35 +02:00
|
|
|
/**
|
|
|
|
* the constructor of SmartBucket
|
|
|
|
*/
|
2018-09-14 18:07:20 +02:00
|
|
|
/**
|
|
|
|
* the constructor of SmartBucket
|
|
|
|
*/
|
2024-06-17 20:00:57 +02:00
|
|
|
constructor(configArg: plugins.tsclass.storage.IS3Descriptor) {
|
2018-09-14 18:07:20 +02:00
|
|
|
this.config = configArg;
|
2024-06-17 19:57:56 +02:00
|
|
|
|
2025-08-18 02:43:29 +00:00
|
|
|
// Use the normalizer to handle various endpoint formats
|
|
|
|
const { normalized } = normalizeS3Descriptor(configArg);
|
2024-06-17 16:01:35 +02:00
|
|
|
|
|
|
|
this.s3Client = new plugins.s3.S3Client({
|
2025-08-18 02:43:29 +00:00
|
|
|
endpoint: normalized.endpointUrl,
|
|
|
|
region: normalized.region,
|
|
|
|
credentials: normalized.credentials,
|
|
|
|
forcePathStyle: normalized.forcePathStyle, // Necessary for S3-compatible storage like MinIO or Wasabi
|
2019-10-15 14:16:28 +02:00
|
|
|
});
|
2018-09-14 18:07:20 +02:00
|
|
|
}
|
|
|
|
|
2019-10-15 19:23:06 +02:00
|
|
|
public async createBucket(bucketNameArg: string) {
|
|
|
|
const bucket = await Bucket.createBucketByName(this, bucketNameArg);
|
|
|
|
return bucket;
|
2019-10-15 14:16:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public async removeBucket(bucketName: string) {
|
2019-10-15 19:23:06 +02:00
|
|
|
await Bucket.removeBucketByName(this, bucketName);
|
2019-10-15 14:16:28 +02:00
|
|
|
}
|
2019-10-14 23:53:41 +02:00
|
|
|
|
2024-11-24 02:25:08 +01:00
|
|
|
public async getBucketByName(bucketNameArg: string) {
|
|
|
|
return Bucket.getBucketByName(this, bucketNameArg);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async getBucketByNameStrict(...args: Parameters<SmartBucket['getBucketByName']>) {
|
|
|
|
const bucket = await this.getBucketByName(...args);
|
|
|
|
if (!bucket) {
|
|
|
|
throw new Error(`Bucket ${args[0]} does not exist.`);
|
|
|
|
}
|
|
|
|
return bucket;
|
2019-10-14 23:53:41 +02:00
|
|
|
}
|
2024-06-17 20:00:57 +02:00
|
|
|
}
|