Skip to content

Commit

Permalink
Added a 'autoSave' method to the server to start the auto-save withou…
Browse files Browse the repository at this point in the history
…t starting the HTTP server
  • Loading branch information
AdrienCastex committed Aug 19, 2017
1 parent 8763396 commit 481413d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
4 changes: 1 addition & 3 deletions lib/server/v2/webDAVServer/StartStop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion lib/server/v2/webDAVServer/WebDAVServer.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="node" />
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';
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion lib/server/v2/webDAVServer/WebDAVServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down
3 changes: 1 addition & 2 deletions src/server/v2/webDAVServer/StartStop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, () => {
Expand Down
21 changes: 20 additions & 1 deletion src/server/v2/webDAVServer/WebDAVServer.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 481413d

Please sign in to comment.