Skip to content

Commit 481413d

Browse files
committed
Added a 'autoSave' method to the server to start the auto-save without starting the HTTP server
1 parent 8763396 commit 481413d

File tree

5 files changed

+40
-8
lines changed

5 files changed

+40
-8
lines changed

lib/server/v2/webDAVServer/StartStop.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Object.defineProperty(exports, "__esModule", { value: true });
33
var WebDAVRequest_1 = require("../WebDAVRequest");
44
var Errors_1 = require("../../../Errors");
5-
var Persistence_1 = require("./Persistence");
65
var https = require("https");
76
var http = require("http");
87
function start(port, callback) {
@@ -72,8 +71,7 @@ function start(port, callback) {
7271
}
7372
});
7473
});
75-
if (this.options.autoSave)
76-
Persistence_1.autoSave.bind(this)(this.options.autoSave);
74+
this.autoSave();
7775
}
7876
this.server.listen(_port, this.options.hostname, function () {
7977
if (_callback)

lib/server/v2/webDAVServer/WebDAVServer.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="node" />
22
import { ExternalRequestContext, RequestContextExternalOptions, RequestContext } from '../RequestContext';
3-
import { WebDAVServerOptions } from '../WebDAVServerOptions';
3+
import { WebDAVServerOptions, IAutoSave } from '../WebDAVServerOptions';
44
import { HTTPMethod } from '../WebDAVRequest';
55
import { HTTPAuthentication } from '../../../user/v2/authentication/HTTPAuthentication';
66
import { PrivilegeManager } from '../../../user/v2/privilege/PrivilegeManager';
@@ -72,6 +72,16 @@ export declare class WebDAVServer {
7272
start(callback: WebDAVServerStartCallback): any;
7373
start(port: number, callback: WebDAVServerStartCallback): any;
7474
stop: typeof startStop.stop;
75+
/**
76+
* Start the auto-save feature of the server. Use the server's options as settings.
77+
*/
78+
autoSave(): any;
79+
/**
80+
* Start the auto-save feature of the server.
81+
*
82+
* @param options Settings of the auto-save.
83+
*/
84+
autoSave(options: IAutoSave): any;
7585
autoLoad: typeof persistence.autoLoad;
7686
load: typeof persistence.load;
7787
save: typeof persistence.save;

lib/server/v2/webDAVServer/WebDAVServer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ var startStop = require("./StartStop");
1010
var WebDAVServer = (function () {
1111
function WebDAVServer(options) {
1212
this.stop = startStop.stop;
13-
// Persistence
1413
this.autoLoad = persistence.autoLoad;
1514
this.load = persistence.load;
1615
this.save = persistence.save;
@@ -166,6 +165,13 @@ var WebDAVServer = (function () {
166165
WebDAVServer.prototype.start = function (port, callback) {
167166
startStop.start.bind(this)(port, callback);
168167
};
168+
WebDAVServer.prototype.autoSave = function (options) {
169+
var fn = persistence.autoSave.bind(this);
170+
if (options)
171+
fn(options);
172+
else if (this.options.autoSave)
173+
fn(this.options.autoSave);
174+
};
169175
WebDAVServer.prototype.method = function (name, manager) {
170176
this.methods[this.normalizeMethodName(name)] = manager;
171177
};

src/server/v2/webDAVServer/StartStop.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ export function start(port ?: number | WebDAVServerStartCallback, callback ?: We
9898
})
9999
})
100100

101-
if(this.options.autoSave)
102-
autoSave.bind(this)(this.options.autoSave);
101+
this.autoSave();
103102
}
104103

105104
this.server.listen(_port, this.options.hostname, () => {

src/server/v2/webDAVServer/WebDAVServer.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { HTTPRequestContext, ExternalRequestContext, RequestContextExternalOptions, RequestContext } from '../RequestContext'
2-
import { WebDAVServerOptions, setDefaultServerOptions } from '../WebDAVServerOptions'
2+
import { WebDAVServerOptions, setDefaultServerOptions, IAutoSave } from '../WebDAVServerOptions'
33
import { HTTPCodes, HTTPMethod } from '../WebDAVRequest'
44
import { HTTPAuthentication } from '../../../user/v2/authentication/HTTPAuthentication'
55
import { PrivilegeManager } from '../../../user/v2/privilege/PrivilegeManager'
@@ -264,6 +264,25 @@ export class WebDAVServer
264264
stop = startStop.stop
265265

266266
// Persistence
267+
/**
268+
* Start the auto-save feature of the server. Use the server's options as settings.
269+
*/
270+
autoSave()
271+
/**
272+
* Start the auto-save feature of the server.
273+
*
274+
* @param options Settings of the auto-save.
275+
*/
276+
autoSave(options : IAutoSave)
277+
autoSave(options ?: IAutoSave)
278+
{
279+
const fn = persistence.autoSave.bind(this);
280+
281+
if(options)
282+
fn(options);
283+
else if(this.options.autoSave)
284+
fn(this.options.autoSave);
285+
}
267286
autoLoad = persistence.autoLoad
268287
load = persistence.load
269288
save = persistence.save

0 commit comments

Comments
 (0)