feat(smarts3-server): Introduce native custom S3 server implementation (Smarts3Server) with routing, middleware, context, filesystem store, controllers and XML utilities; add SmartXml and AWS SDK test; keep optional legacy s3rver backend.
This commit is contained in:
63
ts/index.ts
63
ts/index.ts
@@ -1,9 +1,11 @@
|
||||
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;
|
||||
useCustomServer?: boolean; // Feature flag for custom server
|
||||
}
|
||||
|
||||
export class Smarts3 {
|
||||
@@ -18,41 +20,63 @@ export class Smarts3 {
|
||||
|
||||
// INSTANCE
|
||||
public options: ISmarts3ContructorOptions;
|
||||
public s3Instance: plugins.s3rver;
|
||||
public s3Instance: plugins.s3rver | Smarts3Server;
|
||||
|
||||
constructor(optionsArg: ISmarts3ContructorOptions) {
|
||||
this.options = optionsArg;
|
||||
this.options = {
|
||||
...this.options,
|
||||
useCustomServer: true, // Default to custom server
|
||||
...optionsArg,
|
||||
};
|
||||
}
|
||||
|
||||
public async start() {
|
||||
if (this.options.cleanSlate) {
|
||||
await plugins.smartfile.fs.ensureEmptyDir(paths.bucketsDir);
|
||||
if (this.options.useCustomServer) {
|
||||
// Use new custom server
|
||||
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 (custom implementation)');
|
||||
} else {
|
||||
await plugins.smartfile.fs.ensureDir(paths.bucketsDir);
|
||||
// Use legacy s3rver
|
||||
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,
|
||||
directory: paths.bucketsDir,
|
||||
});
|
||||
await (this.s3Instance as plugins.s3rver).run();
|
||||
console.log('s3 server is running (legacy s3rver)');
|
||||
}
|
||||
this.s3Instance = new plugins.s3rver({
|
||||
port: this.options.port || 3000,
|
||||
address: '0.0.0.0',
|
||||
silent: false,
|
||||
directory: paths.bucketsDir,
|
||||
});
|
||||
await this.s3Instance.run();
|
||||
console.log('s3 server is running');
|
||||
}
|
||||
|
||||
public async getS3Descriptor(
|
||||
optionsArg?: Partial<plugins.tsclass.storage.IS3Descriptor>,
|
||||
): Promise<plugins.tsclass.storage.IS3Descriptor> {
|
||||
if (this.options.useCustomServer && this.s3Instance instanceof Smarts3Server) {
|
||||
const descriptor = this.s3Instance.getS3Descriptor();
|
||||
return {
|
||||
...descriptor,
|
||||
...(optionsArg ? optionsArg : {}),
|
||||
};
|
||||
}
|
||||
|
||||
// Legacy s3rver descriptor
|
||||
return {
|
||||
...{
|
||||
accessKey: 'S3RVER',
|
||||
accessSecret: 'S3RVER',
|
||||
endpoint: '127.0.0.1',
|
||||
port: this.options.port,
|
||||
port: this.options.port || 3000,
|
||||
useSsl: false,
|
||||
},
|
||||
...(optionsArg ? optionsArg : {}),
|
||||
@@ -68,6 +92,13 @@ export class Smarts3 {
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
await this.s3Instance.close();
|
||||
if (this.s3Instance instanceof Smarts3Server) {
|
||||
await this.s3Instance.stop();
|
||||
} else {
|
||||
await (this.s3Instance as plugins.s3rver).close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Export the custom server class for direct use
|
||||
export { Smarts3Server } from './classes/smarts3-server.js';
|
||||
|
||||
Reference in New Issue
Block a user