2021-12-18 00:41:50 +00:00
|
|
|
import * as plugins from './smarts3.plugins';
|
|
|
|
import * as paths from './paths';
|
|
|
|
|
|
|
|
export interface ISmarts3ContructorOptions {
|
|
|
|
port?: number;
|
|
|
|
cleanSlate?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Smarts3 {
|
|
|
|
public options: ISmarts3ContructorOptions;
|
|
|
|
public s3Instance: plugins.s3rver;
|
|
|
|
|
|
|
|
constructor(optionsArg: ISmarts3ContructorOptions) {
|
|
|
|
this.options = optionsArg;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async start() {
|
|
|
|
if (this.options.cleanSlate) {
|
|
|
|
await plugins.smartfile.fs.ensureEmptyDir(paths.bucketsDir);
|
|
|
|
} else {
|
|
|
|
await plugins.smartfile.fs.ensureDir(paths.bucketsDir);
|
|
|
|
}
|
|
|
|
this.s3Instance = new plugins.s3rver({
|
|
|
|
port: this.options.port || 3000,
|
|
|
|
address: '0.0.0.0',
|
|
|
|
silent: false,
|
2021-12-18 00:48:03 +00:00
|
|
|
directory: paths.bucketsDir
|
2021-12-18 00:41:50 +00:00
|
|
|
})
|
|
|
|
await this.s3Instance.run();
|
|
|
|
console.log('s3 server is running');
|
|
|
|
}
|
|
|
|
|
|
|
|
public async stop() {
|
|
|
|
await this.s3Instance.close();
|
|
|
|
}
|
|
|
|
}
|