65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import * as plugins from './plugins.js';
|
|
import * as paths from './paths.js';
|
|
import { Smarts3Server } from './classes/smarts3-server.js';
|
|
|
|
export interface ISmarts3ContructorOptions {
|
|
port?: number;
|
|
cleanSlate?: boolean;
|
|
}
|
|
|
|
export class Smarts3 {
|
|
// STATIC
|
|
public static async createAndStart(
|
|
optionsArg: ConstructorParameters<typeof Smarts3>[0],
|
|
) {
|
|
const smartS3Instance = new Smarts3(optionsArg);
|
|
await smartS3Instance.start();
|
|
return smartS3Instance;
|
|
}
|
|
|
|
// INSTANCE
|
|
public options: ISmarts3ContructorOptions;
|
|
public s3Instance: Smarts3Server;
|
|
|
|
constructor(optionsArg: ISmarts3ContructorOptions) {
|
|
this.options = optionsArg;
|
|
}
|
|
|
|
public async start() {
|
|
this.s3Instance = new Smarts3Server({
|
|
port: this.options.port || 3000,
|
|
address: '0.0.0.0',
|
|
directory: paths.bucketsDir,
|
|
cleanSlate: this.options.cleanSlate || false,
|
|
silent: false,
|
|
});
|
|
await this.s3Instance.start();
|
|
console.log('s3 server is running');
|
|
}
|
|
|
|
public async getS3Descriptor(
|
|
optionsArg?: Partial<plugins.tsclass.storage.IS3Descriptor>,
|
|
): Promise<plugins.tsclass.storage.IS3Descriptor> {
|
|
const descriptor = this.s3Instance.getS3Descriptor();
|
|
return {
|
|
...descriptor,
|
|
...(optionsArg ? optionsArg : {}),
|
|
};
|
|
}
|
|
|
|
public async createBucket(bucketNameArg: string) {
|
|
const smartbucketInstance = new plugins.smartbucket.SmartBucket(
|
|
await this.getS3Descriptor(),
|
|
);
|
|
const bucket = await smartbucketInstance.createBucket(bucketNameArg);
|
|
return bucket;
|
|
}
|
|
|
|
public async stop() {
|
|
await this.s3Instance.stop();
|
|
}
|
|
}
|
|
|
|
// Export the custom server class for direct use
|
|
export { Smarts3Server } from './classes/smarts3-server.js';
|