smarts3/ts/index.ts

56 lines
1.4 KiB
TypeScript
Raw Normal View History

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;
2021-12-18 01:17:42 +00:00
public dataForClient = {
s3AccessKey: 'S3RVER',
s3AccessSecret: 'S3RVER',
port: 3000,
useSsl: false
}
2021-12-18 00:41:50 +00:00
public s3Instance: plugins.s3rver;
constructor(optionsArg: ISmarts3ContructorOptions) {
this.options = optionsArg;
2021-12-18 01:17:42 +00:00
this.options = {
...this.options,
...optionsArg
}
2021-12-18 00:41:50 +00:00
}
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');
}
2021-12-20 15:33:13 +00:00
public async getLocalS3Descriptor(): Promise<plugins.smartbucket.ISmartBucketConfig> {
return {
accessKey: this.dataForClient.s3AccessKey,
accessSecret: this.dataForClient.s3AccessSecret,
endpoint: 'localhost',
port: this.dataForClient.port,
useSsl: this.dataForClient.useSsl,
}
}
2021-12-18 00:41:50 +00:00
public async stop() {
await this.s3Instance.close();
}
}