Skip to content

Commit

Permalink
Added the ability to a resource to provide its own sub-tree based on …
Browse files Browse the repository at this point in the history
…the requested path (Gateway)
  • Loading branch information
AdrienCastex committed Jun 19, 2017
1 parent 8d4df3e commit 485b270
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
3 changes: 2 additions & 1 deletion lib/server/webDAVServer/Resource.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ResourceTreeNode } from './Types';
import { IResource, ReturnCallback } from '../../resource/IResource';
import { MethodCallArgs } from '../MethodCallArgs';
import { FSPath } from '../../manager/FSManager';
export declare function getResourceFromPath(path: FSPath | string[] | string, callbackOrRootResource: ReturnCallback<IResource> | IResource, callback?: ReturnCallback<IResource>): void;
export declare function getResourceFromPath(arg: MethodCallArgs, path: FSPath | string[] | string, callbackOrRootResource: ReturnCallback<IResource> | IResource, callback?: ReturnCallback<IResource>): void;
export declare function addResourceTree(_rootResource: IResource | ResourceTreeNode, _resoureceTree: ResourceTreeNode | (() => void), _callback?: (e: Error) => void): void;
8 changes: 6 additions & 2 deletions lib/server/webDAVServer/Resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
var FSManager_1 = require("../../manager/FSManager");
var Errors_1 = require("../../Errors");
function getResourceFromPath(path, callbackOrRootResource, callback) {
function getResourceFromPath(arg, path, callbackOrRootResource, callback) {
var _this = this;
var rootResource;
if (callbackOrRootResource instanceof Function) {
Expand All @@ -16,6 +16,10 @@ function getResourceFromPath(path, callbackOrRootResource, callback) {
paths = path;
else
paths = new FSManager_1.FSPath(path);
if (rootResource.gateway && rootResource.gateway.constructor === Function) {
rootResource.gateway(arg, paths, function (e, r) { return callback(e ? Errors_1.Errors.ResourceNotFound : null, r); });
return;
}
if (paths.isRoot()) {
callback(null, rootResource);
return;
Expand Down Expand Up @@ -43,7 +47,7 @@ function getResourceFromPath(path, callbackOrRootResource, callback) {
if (name === paths.rootName()) {
found = true;
paths.removeRoot();
_this.getResourceFromPath(paths, children[k], callback);
_this.getResourceFromPath(arg, paths, children[k], callback);
return;
}
process.nextTick(done);
Expand Down
4 changes: 2 additions & 2 deletions lib/server/webDAVServer/WebDAVServer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export declare class WebDAVServer {
protected unknownMethod: WebDAVRequest;
protected server: http.Server | https.Server;
constructor(options?: WebDAVServerOptions);
getResourceFromPath(path: FSPath | string[] | string, callback: ReturnCallback<IResource>): any;
getResourceFromPath(path: FSPath | string[] | string, rootResource: IResource, callback: ReturnCallback<IResource>): any;
getResourceFromPath(arg: MethodCallArgs, path: FSPath | string[] | string, callback: ReturnCallback<IResource>): any;
getResourceFromPath(arg: MethodCallArgs, path: FSPath | string[] | string, rootResource: IResource, callback: ReturnCallback<IResource>): any;
addResourceTree(resoureceTree: ResourceTreeNode, callback: (e: Error) => void): any;
addResourceTree(rootResource: IResource, resoureceTree: ResourceTreeNode, callback: (e: Error) => void): any;
onUnknownMethod(unknownMethod: WebDAVRequest): void;
Expand Down
4 changes: 2 additions & 2 deletions lib/server/webDAVServer/WebDAVServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ var WebDAVServer = (function () {
else
this.method(k, Commands_1.default[k]);
}
WebDAVServer.prototype.getResourceFromPath = function (path, callbackOrRootResource, callback) {
resource.getResourceFromPath.bind(this)(path, callbackOrRootResource, callback);
WebDAVServer.prototype.getResourceFromPath = function (arg, path, callbackOrRootResource, callback) {
resource.getResourceFromPath.bind(this)(arg, path, callbackOrRootResource, callback);
};
WebDAVServer.prototype.addResourceTree = function (_rootResource, _resoureceTree, _callback) {
resource.addResourceTree.bind(this)(_rootResource, _resoureceTree, _callback);
Expand Down
11 changes: 9 additions & 2 deletions src/server/webDAVServer/Resource.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ResourceTreeNode, IResourceTreeNode } from './Types'
import { IResource, ReturnCallback } from '../../resource/IResource'
import { MethodCallArgs } from '../MethodCallArgs'
import { FSPath } from '../../manager/FSManager'
import { Errors } from '../../Errors'

export function getResourceFromPath(path : FSPath | string[] | string, callbackOrRootResource : ReturnCallback<IResource> | IResource, callback ?: ReturnCallback<IResource>)
export function getResourceFromPath(arg : MethodCallArgs, path : FSPath | string[] | string, callbackOrRootResource : ReturnCallback<IResource> | IResource, callback ?: ReturnCallback<IResource>)
{
let rootResource : IResource;

Expand All @@ -21,6 +22,12 @@ export function getResourceFromPath(path : FSPath | string[] | string, callbackO
else
paths = new FSPath(path);

if(rootResource.gateway && rootResource.gateway.constructor === Function)
{
rootResource.gateway(arg, paths, (e, r) => callback(e ? Errors.ResourceNotFound : null, r));
return;
}

if(paths.isRoot())
{
callback(null, rootResource);
Expand Down Expand Up @@ -58,7 +65,7 @@ export function getResourceFromPath(path : FSPath | string[] | string, callbackO
{
found = true;
paths.removeRoot();
this.getResourceFromPath(paths, children[k], callback);
this.getResourceFromPath(arg, paths, children[k], callback);
return;
}
process.nextTick(done);
Expand Down
8 changes: 4 additions & 4 deletions src/server/webDAVServer/WebDAVServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export class WebDAVServer
this.method(k, Commands[k]);
}

getResourceFromPath(path : FSPath | string[] | string, callback : ReturnCallback<IResource>)
getResourceFromPath(path : FSPath | string[] | string, rootResource : IResource, callback : ReturnCallback<IResource>)
getResourceFromPath(path : FSPath | string[] | string, callbackOrRootResource : ReturnCallback<IResource> | IResource, callback ?: ReturnCallback<IResource>)
getResourceFromPath(arg : MethodCallArgs, path : FSPath | string[] | string, callback : ReturnCallback<IResource>)
getResourceFromPath(arg : MethodCallArgs, path : FSPath | string[] | string, rootResource : IResource, callback : ReturnCallback<IResource>)
getResourceFromPath(arg : MethodCallArgs, path : FSPath | string[] | string, callbackOrRootResource : ReturnCallback<IResource> | IResource, callback ?: ReturnCallback<IResource>)
{
resource.getResourceFromPath.bind(this)(path, callbackOrRootResource, callback);
resource.getResourceFromPath.bind(this)(arg, path, callbackOrRootResource, callback);
}

addResourceTree(resoureceTree : ResourceTreeNode, callback : (e : Error) => void)
Expand Down

0 comments on commit 485b270

Please sign in to comment.