diff --git a/lib/server/webDAVServer/Resource.d.ts b/lib/server/webDAVServer/Resource.d.ts index cfd7ba23..14500a06 100644 --- a/lib/server/webDAVServer/Resource.d.ts +++ b/lib/server/webDAVServer/Resource.d.ts @@ -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, callback?: ReturnCallback): void; +export declare function getResourceFromPath(arg: MethodCallArgs, path: FSPath | string[] | string, callbackOrRootResource: ReturnCallback | IResource, callback?: ReturnCallback): void; export declare function addResourceTree(_rootResource: IResource | ResourceTreeNode, _resoureceTree: ResourceTreeNode | (() => void), _callback?: (e: Error) => void): void; diff --git a/lib/server/webDAVServer/Resource.js b/lib/server/webDAVServer/Resource.js index c86dbbfc..fd98587c 100644 --- a/lib/server/webDAVServer/Resource.js +++ b/lib/server/webDAVServer/Resource.js @@ -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) { @@ -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; @@ -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); diff --git a/lib/server/webDAVServer/WebDAVServer.d.ts b/lib/server/webDAVServer/WebDAVServer.d.ts index 09ef64b9..10d3639d 100644 --- a/lib/server/webDAVServer/WebDAVServer.d.ts +++ b/lib/server/webDAVServer/WebDAVServer.d.ts @@ -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): any; - getResourceFromPath(path: FSPath | string[] | string, rootResource: IResource, callback: ReturnCallback): any; + getResourceFromPath(arg: MethodCallArgs, path: FSPath | string[] | string, callback: ReturnCallback): any; + getResourceFromPath(arg: MethodCallArgs, path: FSPath | string[] | string, rootResource: IResource, callback: ReturnCallback): any; addResourceTree(resoureceTree: ResourceTreeNode, callback: (e: Error) => void): any; addResourceTree(rootResource: IResource, resoureceTree: ResourceTreeNode, callback: (e: Error) => void): any; onUnknownMethod(unknownMethod: WebDAVRequest): void; diff --git a/lib/server/webDAVServer/WebDAVServer.js b/lib/server/webDAVServer/WebDAVServer.js index 2afbfa25..1be59a71 100644 --- a/lib/server/webDAVServer/WebDAVServer.js +++ b/lib/server/webDAVServer/WebDAVServer.js @@ -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); diff --git a/src/server/webDAVServer/Resource.ts b/src/server/webDAVServer/Resource.ts index 29643fe6..1ee8db74 100644 --- a/src/server/webDAVServer/Resource.ts +++ b/src/server/webDAVServer/Resource.ts @@ -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, callback ?: ReturnCallback) +export function getResourceFromPath(arg : MethodCallArgs, path : FSPath | string[] | string, callbackOrRootResource : ReturnCallback | IResource, callback ?: ReturnCallback) { let rootResource : IResource; @@ -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); @@ -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); diff --git a/src/server/webDAVServer/WebDAVServer.ts b/src/server/webDAVServer/WebDAVServer.ts index ec779a77..950a047d 100644 --- a/src/server/webDAVServer/WebDAVServer.ts +++ b/src/server/webDAVServer/WebDAVServer.ts @@ -53,11 +53,11 @@ export class WebDAVServer this.method(k, Commands[k]); } - getResourceFromPath(path : FSPath | string[] | string, callback : ReturnCallback) - getResourceFromPath(path : FSPath | string[] | string, rootResource : IResource, callback : ReturnCallback) - getResourceFromPath(path : FSPath | string[] | string, callbackOrRootResource : ReturnCallback | IResource, callback ?: ReturnCallback) + getResourceFromPath(arg : MethodCallArgs, path : FSPath | string[] | string, callback : ReturnCallback) + getResourceFromPath(arg : MethodCallArgs, path : FSPath | string[] | string, rootResource : IResource, callback : ReturnCallback) + getResourceFromPath(arg : MethodCallArgs, path : FSPath | string[] | string, callbackOrRootResource : ReturnCallback | IResource, callback ?: ReturnCallback) { - resource.getResourceFromPath.bind(this)(path, callbackOrRootResource, callback); + resource.getResourceFromPath.bind(this)(arg, path, callbackOrRootResource, callback); } addResourceTree(resoureceTree : ResourceTreeNode, callback : (e : Error) => void)