From c9eb03dc3180a07863196a41270943c957a8751e Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Wed, 24 Apr 2024 18:14:57 +0200 Subject: [PATCH] fix(core): update --- test/test.ts | 20 ++++++++++---------- ts/00_commitinfo_data.ts | 2 +- ts/classes.exposeprovider.webdav.ts | 3 ++- ts/classes.smartexpose.ts | 28 +++++++++++----------------- 4 files changed, 24 insertions(+), 29 deletions(-) diff --git a/test/test.ts b/test/test.ts index fa4572e..e4098be 100644 --- a/test/test.ts +++ b/test/test.ts @@ -9,17 +9,17 @@ import * as smartexpose from '../ts/index.js' let testSmartexpose: smartexpose.SmartExpose; tap.test('should create a valid instance of smartexpose using Webdav', async () => { - testSmartexpose = await smartexpose.SmartExpose.createWithWebdav({ - webdavCredentials: { - serverUrl: await testQenv.getEnvVarOnDemand('WEBDAV_SERVER_URL'), - password: await testQenv.getEnvVarOnDemand('WEBDAV_SERVER_TOKEN'), + testSmartexpose = new smartexpose.SmartExpose({ + webdav: { + webdavCredentials: { + serverUrl: await testQenv.getEnvVarOnDemand('WEBDAV_SERVER_URL'), + password: await testQenv.getEnvVarOnDemand('WEBDAV_SERVER_TOKEN'), + }, + webdavSubPath: await testQenv.getEnvVarOnDemand('WEBDAV_SUB_PATH'), }, - webdavSubPath: await testQenv.getEnvVarOnDemand('WEBDAV_SUB_PATH'), - exposeOptions: { - deleteAfterMillis: 30000, - privateUrl: true, - exposedBaseUrl: await testQenv.getEnvVarOnDemand('EXPOSED_BASE_URL'), - } + deleteAfterMillis: 30000, + privateUrl: true, + exposedBaseUrl: await testQenv.getEnvVarOnDemand('EXPOSED_BASE_URL'), }); await testSmartexpose.start(); expect(testSmartexpose).toBeInstanceOf(smartexpose.SmartExpose); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 5e857f1..a990df9 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartexpose', - version: '1.0.3', + version: '1.0.4', description: 'a package to expose things to the internet' } diff --git a/ts/classes.exposeprovider.webdav.ts b/ts/classes.exposeprovider.webdav.ts index 9856f19..59915a4 100644 --- a/ts/classes.exposeprovider.webdav.ts +++ b/ts/classes.exposeprovider.webdav.ts @@ -12,8 +12,9 @@ export class WebDavExposeProvider extends ExposeProvider { public webdavClient: plugins.smartwebdav.WebdavClient; public options: IWebdavExposeProviderOptions; - constructor(optionsArg: IWebdavExposeProviderOptions) { + constructor(smartexposeRefArg: SmartExpose, optionsArg: IWebdavExposeProviderOptions) { super(); + this.smartExposeRef = smartexposeRefArg; this.options = optionsArg; } diff --git a/ts/classes.smartexpose.ts b/ts/classes.smartexpose.ts index 2f18b53..b17a91d 100644 --- a/ts/classes.smartexpose.ts +++ b/ts/classes.smartexpose.ts @@ -6,36 +6,30 @@ export interface ISmartExposeOptions { deleteAfterMillis?: number, privateUrl?: boolean, exposedBaseUrl: string, + webdav?: { + webdavCredentials: plugins.smartwebdav.IWebdavClientOptions, + webdavSubPath: string, + } } export class SmartExpose { - // STATIC - public static createWithWebdav(optionsArg: { - webdavCredentials: plugins.smartwebdav.IWebdavClientOptions, - webdavSubPath: string, - exposeOptions: ISmartExposeOptions, - }) { - const provider = new WebDavExposeProvider({ - webdavCredentials: optionsArg.webdavCredentials, - webdavSubPath: optionsArg.webdavSubPath, - }); - const smartexposeInstance = new SmartExpose(provider, optionsArg.exposeOptions); - provider.smartExposeRef = smartexposeInstance; - return smartexposeInstance; - } - // INSTANCE public taskmanager: plugins.taskbuffer.TaskManager; public provider: ExposeProvider; public options: ISmartExposeOptions; - constructor(provider: ExposeProvider, optionsArg: ISmartExposeOptions) { - this.provider = provider; + constructor(optionsArg: ISmartExposeOptions) { this.options = optionsArg; } public async start() { this.taskmanager = new plugins.taskbuffer.TaskManager(); + if (this.options.webdav) { + this.provider = new WebDavExposeProvider(this, { + webdavCredentials: this.options.webdav.webdavCredentials, + webdavSubPath: this.options.webdav.webdavSubPath, + }); + } await this.provider.start(); this.taskmanager.start(); }