Skip to content

Commit

Permalink
Added a method in the server to give the listing of resources
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Aug 19, 2017
1 parent 481413d commit 18f0e3a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/server/v2/webDAVServer/WebDAVServer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export declare class WebDAVServer {
subPath: Path;
};
onUnknownMethod(unknownMethod: HTTPMethod): void;
listResources(callback: (paths: string[]) => void): void;
listResources(root: string | Path, callback: (paths: string[]) => void): void;
start(port: number): any;
start(callback: WebDAVServerStartCallback): any;
start(port: number, callback: WebDAVServerStartCallback): any;
Expand Down
22 changes: 22 additions & 0 deletions lib/server/v2/webDAVServer/WebDAVServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,28 @@ var WebDAVServer = (function () {
WebDAVServer.prototype.onUnknownMethod = function (unknownMethod) {
this.unknownMethod = unknownMethod;
};
WebDAVServer.prototype.listResources = function (_root, _callback) {
var _this = this;
var root = new Path_1.Path(_callback ? _root : '/');
var callback = _callback ? _callback : _root;
var output = [];
output.push(root.toString());
this.getResource(this.createExternalContext(), root, function (e, resource) {
resource.readDir(true, function (e, files) {
if (e || files.length === 0)
return callback(output);
var nb = files.length;
files.forEach(function (fileName) {
var childPath = root.getChildPath(fileName);
_this.listResources(childPath, function (outputs) {
outputs.forEach(function (o) { return output.push(o); });
if (--nb === 0)
callback(output);
});
});
});
});
};
WebDAVServer.prototype.start = function (port, callback) {
startStop.start.bind(this)(port, callback);
};
Expand Down
29 changes: 29 additions & 0 deletions src/server/v2/webDAVServer/WebDAVServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,35 @@ export class WebDAVServer
this.unknownMethod = unknownMethod;
}

listResources(callback : (paths : string[]) => void) : void
listResources(root : string | Path, callback : (paths : string[]) => void) : void
listResources(_root : string | Path | ((paths : string[]) => void), _callback ?: (paths : string[]) => void) : void
{
const root = new Path(_callback ? _root as (string | Path) : '/');
const callback = _callback ? _callback : _root as ((paths : string[]) => void);

const output = [];
output.push(root.toString());

this.getResource(this.createExternalContext(), root, (e, resource) => {
resource.readDir(true, (e, files) => {
if(e || files.length === 0)
return callback(output);

let nb = files.length;

files.forEach((fileName) => {
const childPath = root.getChildPath(fileName);
this.listResources(childPath, (outputs) => {
outputs.forEach((o) => output.push(o));
if(--nb === 0)
callback(output);
})
})
});
});
}

// Start / Stop
start(port : number)
start(callback : WebDAVServerStartCallback)
Expand Down

0 comments on commit 18f0e3a

Please sign in to comment.