From 481413da9cdb03856153b7f0b75347902efa9624 Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Sat, 19 Aug 2017 11:41:35 +0200 Subject: [PATCH] Added a 'autoSave' method to the server to start the auto-save without starting the HTTP server --- lib/server/v2/webDAVServer/StartStop.js | 4 +--- lib/server/v2/webDAVServer/WebDAVServer.d.ts | 12 ++++++++++- lib/server/v2/webDAVServer/WebDAVServer.js | 8 +++++++- src/server/v2/webDAVServer/StartStop.ts | 3 +-- src/server/v2/webDAVServer/WebDAVServer.ts | 21 +++++++++++++++++++- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/lib/server/v2/webDAVServer/StartStop.js b/lib/server/v2/webDAVServer/StartStop.js index 6d775a45..6fea4448 100644 --- a/lib/server/v2/webDAVServer/StartStop.js +++ b/lib/server/v2/webDAVServer/StartStop.js @@ -2,7 +2,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); var WebDAVRequest_1 = require("../WebDAVRequest"); var Errors_1 = require("../../../Errors"); -var Persistence_1 = require("./Persistence"); var https = require("https"); var http = require("http"); function start(port, callback) { @@ -72,8 +71,7 @@ function start(port, callback) { } }); }); - if (this.options.autoSave) - Persistence_1.autoSave.bind(this)(this.options.autoSave); + this.autoSave(); } this.server.listen(_port, this.options.hostname, function () { if (_callback) diff --git a/lib/server/v2/webDAVServer/WebDAVServer.d.ts b/lib/server/v2/webDAVServer/WebDAVServer.d.ts index 2baab73d..d3a9437e 100644 --- a/lib/server/v2/webDAVServer/WebDAVServer.d.ts +++ b/lib/server/v2/webDAVServer/WebDAVServer.d.ts @@ -1,6 +1,6 @@ /// import { ExternalRequestContext, RequestContextExternalOptions, RequestContext } from '../RequestContext'; -import { WebDAVServerOptions } from '../WebDAVServerOptions'; +import { WebDAVServerOptions, IAutoSave } from '../WebDAVServerOptions'; import { HTTPMethod } from '../WebDAVRequest'; import { HTTPAuthentication } from '../../../user/v2/authentication/HTTPAuthentication'; import { PrivilegeManager } from '../../../user/v2/privilege/PrivilegeManager'; @@ -72,6 +72,16 @@ export declare class WebDAVServer { start(callback: WebDAVServerStartCallback): any; start(port: number, callback: WebDAVServerStartCallback): any; stop: typeof startStop.stop; + /** + * Start the auto-save feature of the server. Use the server's options as settings. + */ + autoSave(): any; + /** + * Start the auto-save feature of the server. + * + * @param options Settings of the auto-save. + */ + autoSave(options: IAutoSave): any; autoLoad: typeof persistence.autoLoad; load: typeof persistence.load; save: typeof persistence.save; diff --git a/lib/server/v2/webDAVServer/WebDAVServer.js b/lib/server/v2/webDAVServer/WebDAVServer.js index d939a0e4..29c7e013 100644 --- a/lib/server/v2/webDAVServer/WebDAVServer.js +++ b/lib/server/v2/webDAVServer/WebDAVServer.js @@ -10,7 +10,6 @@ var startStop = require("./StartStop"); var WebDAVServer = (function () { function WebDAVServer(options) { this.stop = startStop.stop; - // Persistence this.autoLoad = persistence.autoLoad; this.load = persistence.load; this.save = persistence.save; @@ -166,6 +165,13 @@ var WebDAVServer = (function () { WebDAVServer.prototype.start = function (port, callback) { startStop.start.bind(this)(port, callback); }; + WebDAVServer.prototype.autoSave = function (options) { + var fn = persistence.autoSave.bind(this); + if (options) + fn(options); + else if (this.options.autoSave) + fn(this.options.autoSave); + }; WebDAVServer.prototype.method = function (name, manager) { this.methods[this.normalizeMethodName(name)] = manager; }; diff --git a/src/server/v2/webDAVServer/StartStop.ts b/src/server/v2/webDAVServer/StartStop.ts index 6f3c9f7c..7516eff5 100644 --- a/src/server/v2/webDAVServer/StartStop.ts +++ b/src/server/v2/webDAVServer/StartStop.ts @@ -98,8 +98,7 @@ export function start(port ?: number | WebDAVServerStartCallback, callback ?: We }) }) - if(this.options.autoSave) - autoSave.bind(this)(this.options.autoSave); + this.autoSave(); } this.server.listen(_port, this.options.hostname, () => { diff --git a/src/server/v2/webDAVServer/WebDAVServer.ts b/src/server/v2/webDAVServer/WebDAVServer.ts index cd70701e..ce38dfa1 100644 --- a/src/server/v2/webDAVServer/WebDAVServer.ts +++ b/src/server/v2/webDAVServer/WebDAVServer.ts @@ -1,5 +1,5 @@ import { HTTPRequestContext, ExternalRequestContext, RequestContextExternalOptions, RequestContext } from '../RequestContext' -import { WebDAVServerOptions, setDefaultServerOptions } from '../WebDAVServerOptions' +import { WebDAVServerOptions, setDefaultServerOptions, IAutoSave } from '../WebDAVServerOptions' import { HTTPCodes, HTTPMethod } from '../WebDAVRequest' import { HTTPAuthentication } from '../../../user/v2/authentication/HTTPAuthentication' import { PrivilegeManager } from '../../../user/v2/privilege/PrivilegeManager' @@ -264,6 +264,25 @@ export class WebDAVServer stop = startStop.stop // Persistence + /** + * Start the auto-save feature of the server. Use the server's options as settings. + */ + autoSave() + /** + * Start the auto-save feature of the server. + * + * @param options Settings of the auto-save. + */ + autoSave(options : IAutoSave) + autoSave(options ?: IAutoSave) + { + const fn = persistence.autoSave.bind(this); + + if(options) + fn(options); + else if(this.options.autoSave) + fn(this.options.autoSave); + } autoLoad = persistence.autoLoad load = persistence.load save = persistence.save