From 94077ae36e85a891c61098a398e3e0eb74423e38 Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Tue, 20 Jun 2017 14:43:01 +0200 Subject: [PATCH] Compiled with comments --- lib/index.js | 1 + lib/manager/FSPath.js | 2 +- lib/resource/export.js | 5 +++++ lib/resource/lock/Lock.js | 6 ++++++ lib/resource/physical/PhysicalFile.js | 4 ++++ lib/resource/physical/PhysicalFolder.js | 4 ++++ lib/resource/physical/PhysicalResource.js | 1 + lib/resource/std/RootResource.js | 4 ++++ lib/resource/std/resourceTester/Children.js | 1 + lib/resource/std/resourceTester/Content.js | 1 + lib/resource/std/resourceTester/Locks.js | 1 + lib/resource/std/resourceTester/Properties.js | 1 + .../std/resourceTester/ResourceTester.js | 6 ++++++ lib/resource/std/resourceTester/StdMetaData.js | 1 + lib/resource/virtual/VirtualFile.js | 3 +++ lib/resource/virtual/VirtualFolder.js | 3 +++ lib/resource/virtualStored/VirtualStoredFile.js | 3 +++ .../virtualStored/VirtualStoredFolder.js | 3 +++ lib/server/MethodCallArgs.js | 2 ++ lib/server/commands/Copy.js | 4 +++- lib/server/webDAVServer/StartStop.js | 1 + lib/server/webDAVServer/WebDAVServer.js | 4 ++++ .../authentication/HTTPDigestAuthentication.js | 2 +- lib/user/privilege/notused/Privilege.js | 16 ++++++++++++++++ 24 files changed, 76 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index bdbbaeca..395ac079 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,4 +1,5 @@ "use strict"; +// the order matters because of import dependencies function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } diff --git a/lib/manager/FSPath.js b/lib/manager/FSPath.js index a8e04c20..a43ef5b7 100644 --- a/lib/manager/FSPath.js +++ b/lib/manager/FSPath.js @@ -10,7 +10,7 @@ var FSPath = (function () { this.paths = sPath.replace(/(^\/|\/$)/g, '').split('/'); } else if (path.constructor === FSPath) - this.paths = path.paths.filter(function (x) { return true; }); + this.paths = path.paths.filter(function (x) { return true; }); // clone else this.paths = path; } diff --git a/lib/resource/export.js b/lib/resource/export.js index 79b99d7f..82764276 100644 --- a/lib/resource/export.js +++ b/lib/resource/export.js @@ -3,20 +3,25 @@ function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } Object.defineProperty(exports, "__esModule", { value: true }); +// Physical resources __export(require("./physical/PhysicalResource")); __export(require("./physical/PhysicalFolder")); __export(require("./physical/PhysicalFile")); +// Virtual resources __export(require("./virtual/VirtualResource")); __export(require("./virtual/VirtualFolder")); __export(require("./virtual/VirtualFile")); +// Virtual stored resources __export(require("./virtualStored/VirtualStoredResource")); __export(require("./virtualStored/VirtualStoredFolder")); __export(require("./virtualStored/VirtualStoredFile")); +// Standard classes __export(require("./std/StandardResource")); __export(require("./std/ResourceChildren")); __export(require("./std/RootResource")); __export(require("./std/resourceTester/ResourceTester")); __export(require("./IResource")); +// Locks __export(require("./lock/LockScope")); __export(require("./lock/LockKind")); __export(require("./lock/LockType")); diff --git a/lib/resource/lock/Lock.js b/lib/resource/lock/Lock.js index 54b06fe4..50a32c20 100644 --- a/lib/resource/lock/Lock.js +++ b/lib/resource/lock/Lock.js @@ -20,11 +20,17 @@ var Lock = (function () { return str; } var uuid = 'urn:uuid:'; + // time_low uuid += pad(expirationDate & 0xFFFFFFFF, 8); + // time_mid uuid += '-' + pad((expirationDate >> 32) & 0xFFFF, 4); + // time_hi_and_version uuid += '-' + pad(((expirationDate >> (32 + 16)) & 0x0FFF) + 0x1000, 4); + // clock_seq_hi_and_reserved uuid += '-' + pad((rnd1 >> 16) & 0xFF, 2); + // clock_seq_low uuid += pad(rnd1 & 0xFF, 2); + // node uuid += '-' + pad(rnd2, 12); return uuid; }; diff --git a/lib/resource/physical/PhysicalFile.js b/lib/resource/physical/PhysicalFile.js index 620e8612..7c344845 100644 --- a/lib/resource/physical/PhysicalFile.js +++ b/lib/resource/physical/PhysicalFile.js @@ -20,9 +20,11 @@ var PhysicalFile = (function (_super) { function PhysicalFile(realPath, parent, fsManager) { return _super.call(this, realPath, parent, fsManager) || this; } + // ****************************** Std meta-data ****************************** // PhysicalFile.prototype.type = function (callback) { callback(null, IResource_1.ResourceType.File); }; + // ****************************** Actions ****************************** // PhysicalFile.prototype.create = function (callback) { if (!fs.constants || !fs.constants.O_CREAT) { fs.writeFile(this.realPath, '', callback); @@ -47,6 +49,7 @@ var PhysicalFile = (function (_super) { _this.removeFromParent(callback); }); }; + // ****************************** Content ****************************** // PhysicalFile.prototype.write = function (targetSource, callback) { var _this = this; fs.open(this.realPath, 'w', function (e, fd) { @@ -76,6 +79,7 @@ var PhysicalFile = (function (_super) { PhysicalFile.prototype.size = function (targetSource, callback) { fs.stat(this.realPath, function (e, s) { return callback(e, s ? s.size : null); }); }; + // ****************************** Children ****************************** // PhysicalFile.prototype.addChild = function (resource, callback) { callback(Errors_1.Errors.InvalidOperation); }; diff --git a/lib/resource/physical/PhysicalFolder.js b/lib/resource/physical/PhysicalFolder.js index 7e649253..e5e712d2 100644 --- a/lib/resource/physical/PhysicalFolder.js +++ b/lib/resource/physical/PhysicalFolder.js @@ -56,9 +56,11 @@ var PhysicalFolder = (function (_super) { _this.children = new ResourceChildren_1.ResourceChildren(); return _this; } + // ****************************** Std meta-data ****************************** // PhysicalFolder.prototype.type = function (callback) { callback(null, IResource_1.ResourceType.Directory); }; + // ****************************** Actions ****************************** // PhysicalFolder.prototype.create = function (callback) { fs.mkdir(this.realPath, callback); }; @@ -102,6 +104,7 @@ var PhysicalFolder = (function (_super) { }); }); }; + // ****************************** Content ****************************** // PhysicalFolder.prototype.write = function (targetSource, callback) { callback(Errors_1.Errors.InvalidOperation, null); }; @@ -114,6 +117,7 @@ var PhysicalFolder = (function (_super) { PhysicalFolder.prototype.size = function (targetSource, callback) { callback(Errors_1.Errors.NoSizeForAFolder, null); }; + // ****************************** Children ****************************** // PhysicalFolder.prototype.addChild = function (resource, callback) { var _this = this; this.children.add(resource, function (e) { diff --git a/lib/resource/physical/PhysicalResource.js b/lib/resource/physical/PhysicalResource.js index 302e003c..1603fcf8 100644 --- a/lib/resource/physical/PhysicalResource.js +++ b/lib/resource/physical/PhysicalResource.js @@ -68,6 +68,7 @@ var PhysicalResource = (function (_super) { callback(null, oldName, newName); }); }; + // ****************************** Std meta-data ****************************** // PhysicalResource.prototype.webName = function (callback) { callback(null, path.basename(this.name)); }; diff --git a/lib/resource/std/RootResource.js b/lib/resource/std/RootResource.js index fd219527..a3e3433f 100644 --- a/lib/resource/std/RootResource.js +++ b/lib/resource/std/RootResource.js @@ -22,6 +22,7 @@ var RootResource = (function (_super) { _this.children = new ResourceChildren_1.ResourceChildren(); return _this; } + // ****************************** Actions ****************************** // RootResource.prototype.create = function (callback) { callback(Errors_1.Errors.InvalidOperation); }; @@ -34,12 +35,14 @@ var RootResource = (function (_super) { RootResource.prototype.rename = function (newName, callback) { callback(Errors_1.Errors.InvalidOperation, null, null); }; + // ****************************** Std meta-data ****************************** // RootResource.prototype.webName = function (callback) { callback(null, ''); }; RootResource.prototype.type = function (callback) { callback(null, IResource_1.ResourceType.Directory); }; + // ****************************** Content ****************************** // RootResource.prototype.write = function (targetSource, callback) { callback(Errors_1.Errors.InvalidOperation, null); }; @@ -52,6 +55,7 @@ var RootResource = (function (_super) { RootResource.prototype.size = function (targetSource, callback) { StandardResource_1.StandardResource.sizeOfSubFiles(this, targetSource, callback); }; + // ****************************** Children ****************************** // RootResource.prototype.addChild = function (resource, callback) { var _this = this; this.children.add(resource, function (e) { diff --git a/lib/resource/std/resourceTester/Children.js b/lib/resource/std/resourceTester/Children.js index 453625be..3c445325 100644 --- a/lib/resource/std/resourceTester/Children.js +++ b/lib/resource/std/resourceTester/Children.js @@ -2,6 +2,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); var VirtualFolder_1 = require("../../virtual/VirtualFolder"); var VirtualFile_1 = require("../../virtual/VirtualFile"); +// ****************************** Children ****************************** // function addChild(callback) { var _this = this; callback = this.multiple(callback, 3); diff --git a/lib/resource/std/resourceTester/Content.js b/lib/resource/std/resourceTester/Content.js index fa3eb708..b0725d1b 100644 --- a/lib/resource/std/resourceTester/Content.js +++ b/lib/resource/std/resourceTester/Content.js @@ -1,5 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +// ****************************** Content ****************************** // function writeRead(callback) { var _this = this; callback = this.multiple(callback, 1); diff --git a/lib/resource/std/resourceTester/Locks.js b/lib/resource/std/resourceTester/Locks.js index 8d8425ec..c1d6c523 100644 --- a/lib/resource/std/resourceTester/Locks.js +++ b/lib/resource/std/resourceTester/Locks.js @@ -4,6 +4,7 @@ var LockScope_1 = require("../../lock/LockScope"); var LockKind_1 = require("../../lock/LockKind"); var LockType_1 = require("../../lock/LockType"); var Lock_1 = require("../../lock/Lock"); +// ****************************** Locks ****************************** // function lock(callback) { var _this = this; if (!this.options.canLock) { diff --git a/lib/resource/std/resourceTester/Properties.js b/lib/resource/std/resourceTester/Properties.js index 2dabb58e..acf8e174 100644 --- a/lib/resource/std/resourceTester/Properties.js +++ b/lib/resource/std/resourceTester/Properties.js @@ -1,6 +1,7 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var XML_1 = require("../../../helper/XML"); +// ****************************** Properties ****************************** // function setProperty(callback) { callback = this.multiple(callback, 2); this.producer(false, function (r1) { diff --git a/lib/resource/std/resourceTester/ResourceTester.js b/lib/resource/std/resourceTester/ResourceTester.js index 6cd71aa8..79608330 100644 --- a/lib/resource/std/resourceTester/ResourceTester.js +++ b/lib/resource/std/resourceTester/ResourceTester.js @@ -31,20 +31,26 @@ var ResourceTester = (function () { function ResourceTester(options, producer) { this.options = options; this.producer = producer; + // ****************************** Actions ****************************** // this.create = actions.create; this.delete = actions.deleteResource; this.moveTo = actions.moveTo; this.rename = actions.rename; + // ****************************** Content ****************************** // this.writeRead = content.writeRead; this.mimeType = content.mimeType; this.size = content.size; + // ****************************** Locks ****************************** // this.lock = locks.lock; + // ****************************** Children ****************************** // this.addChild = children.addChild; this.removeChild = children.removeChild; this.getChildren = children.getChildren; + // ****************************** Properties ****************************** // this.setProperty = properties.setProperty; this.removeProperty = properties.removeProperty; this.getProperties = properties.getProperties; + // ****************************** Std meta-data ****************************** // this.creationDate = stdMetaData.creationDate; this.lastModifiedDate = stdMetaData.lastModifiedDate; this.webName = stdMetaData.webName; diff --git a/lib/resource/std/resourceTester/StdMetaData.js b/lib/resource/std/resourceTester/StdMetaData.js index d18a1c27..47ff0916 100644 --- a/lib/resource/std/resourceTester/StdMetaData.js +++ b/lib/resource/std/resourceTester/StdMetaData.js @@ -1,5 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +// ****************************** Std meta-data ****************************** // function creationDate(callback) { var _this = this; callback = this.multiple(callback, 1); diff --git a/lib/resource/virtual/VirtualFile.js b/lib/resource/virtual/VirtualFile.js index c61ef1cf..27b65618 100644 --- a/lib/resource/virtual/VirtualFile.js +++ b/lib/resource/virtual/VirtualFile.js @@ -59,9 +59,11 @@ var VirtualFile = (function (_super) { _this.len = 0; return _this; } + // ****************************** Std meta-data ****************************** // VirtualFile.prototype.type = function (callback) { callback(null, IResource_1.ResourceType.File); }; + // ****************************** Content ****************************** // VirtualFile.prototype.write = function (targetSource, callback) { var _this = this; var content = []; @@ -83,6 +85,7 @@ var VirtualFile = (function (_super) { VirtualFile.prototype.size = function (targetSource, callback) { callback(null, this.len); }; + // ****************************** Children ****************************** // VirtualFile.prototype.addChild = function (resource, callback) { callback(Errors_1.Errors.InvalidOperation); }; diff --git a/lib/resource/virtual/VirtualFolder.js b/lib/resource/virtual/VirtualFolder.js index d4881264..e052a196 100644 --- a/lib/resource/virtual/VirtualFolder.js +++ b/lib/resource/virtual/VirtualFolder.js @@ -21,9 +21,11 @@ var VirtualFolder = (function (_super) { _this.children = new ResourceChildren_1.ResourceChildren(); return _this; } + // ****************************** Std meta-data ****************************** // VirtualFolder.prototype.type = function (callback) { callback(null, IResource_1.ResourceType.Directory); }; + // ****************************** Content ****************************** // VirtualFolder.prototype.write = function (targetSource, callback) { callback(Errors_1.Errors.InvalidOperation, null); }; @@ -36,6 +38,7 @@ var VirtualFolder = (function (_super) { VirtualFolder.prototype.size = function (targetSource, callback) { callback(Errors_1.Errors.NoSizeForAFolder, null); }; + // ****************************** Children ****************************** // VirtualFolder.prototype.addChild = function (resource, callback) { var _this = this; this.children.add(resource, function (e) { diff --git a/lib/resource/virtualStored/VirtualStoredFile.js b/lib/resource/virtualStored/VirtualStoredFile.js index 98d62b63..a3a7343f 100644 --- a/lib/resource/virtualStored/VirtualStoredFile.js +++ b/lib/resource/virtualStored/VirtualStoredFile.js @@ -43,9 +43,11 @@ var VirtualStoredFile = (function (_super) { _this.removeFromParent(callback); }); }; + // ****************************** Std meta-data ****************************** // VirtualStoredFile.prototype.type = function (callback) { callback(null, IResource_1.ResourceType.File); }; + // ****************************** Content ****************************** // VirtualStoredFile.prototype.write = function (targetSource, callback) { var _this = this; this.fsManager.contentManager.write(this.contentUid, function (e, w) { @@ -79,6 +81,7 @@ var VirtualStoredFile = (function (_super) { VirtualStoredFile.prototype.size = function (targetSource, callback) { callback(null, this.len); }; + // ****************************** Children ****************************** // VirtualStoredFile.prototype.addChild = function (resource, callback) { callback(Errors_1.Errors.InvalidOperation); }; diff --git a/lib/resource/virtualStored/VirtualStoredFolder.js b/lib/resource/virtualStored/VirtualStoredFolder.js index cb5578df..af40ae65 100644 --- a/lib/resource/virtualStored/VirtualStoredFolder.js +++ b/lib/resource/virtualStored/VirtualStoredFolder.js @@ -21,9 +21,11 @@ var VirtualStoredFolder = (function (_super) { _this.children = new ResourceChildren_1.ResourceChildren(); return _this; } + // ****************************** Std meta-data ****************************** // VirtualStoredFolder.prototype.type = function (callback) { callback(null, IResource_1.ResourceType.Directory); }; + // ****************************** Content ****************************** // VirtualStoredFolder.prototype.write = function (targetSource, callback) { callback(Errors_1.Errors.InvalidOperation, null); }; @@ -36,6 +38,7 @@ var VirtualStoredFolder = (function (_super) { VirtualStoredFolder.prototype.size = function (targetSource, callback) { callback(Errors_1.Errors.NoSizeForAFolder, null); }; + // ****************************** Children ****************************** // VirtualStoredFolder.prototype.addChild = function (resource, callback) { var _this = this; this.children.add(resource, function (e) { diff --git a/lib/server/MethodCallArgs.js b/lib/server/MethodCallArgs.js index 4b9b58c0..e2a7aa25 100644 --- a/lib/server/MethodCallArgs.js +++ b/lib/server/MethodCallArgs.js @@ -153,8 +153,10 @@ var MethodCallArgs = (function () { callback(!this.resource ? Errors_1.Errors.ResourceNotFound : null, this.resource); }; MethodCallArgs.prototype.dateISO8601 = function (ticks) { + // Adding date var date = new Date(ticks); var result = date.toISOString().substring(0, '0000-00-00T00:00:00'.length); + // Adding timezone offset var offset = date.getTimezoneOffset(); result += offset < 0 ? '-' : '+'; offset = Math.abs(offset); diff --git a/lib/server/commands/Copy.js b/lib/server/commands/Copy.js index 6c67a361..14ca08d4 100644 --- a/lib/server/commands/Copy.js +++ b/lib/server/commands/Copy.js @@ -18,6 +18,7 @@ function copyAllProperties(source, destination, callback) { }); } function copy(arg, source, rDest, destination, callback) { + // Error wrapper function _(error, cb) { if (error) process.nextTick(function () { return callback(error); }); @@ -102,7 +103,7 @@ function method(arg, callback) { var startIndex = destination.indexOf('://'); if (startIndex !== -1) { destination = destination.substring(startIndex + '://'.length); - destination = destination.substring(destination.indexOf('/')); + destination = destination.substring(destination.indexOf('/')); // Remove the hostname + port } destination = new FSManager_1.FSPath(destination); arg.server.getResourceFromPath(arg, destination.getParent(), function (e, rDest) { @@ -173,6 +174,7 @@ function method(arg, callback) { done(false); } } + // Find child name collision rDest.getChildren(function (e, children) { return process.nextTick(function () { if (e) { go(e, null); diff --git a/lib/server/webDAVServer/StartStop.js b/lib/server/webDAVServer/StartStop.js index e1a3655b..da11e7c0 100644 --- a/lib/server/webDAVServer/StartStop.js +++ b/lib/server/webDAVServer/StartStop.js @@ -23,6 +23,7 @@ function autoSave(options) { case 'COPY': case 'POST': case 'PUT': + // Avoid concurrent saving if (saving) { saveRequested = true; next(); diff --git a/lib/server/webDAVServer/WebDAVServer.js b/lib/server/webDAVServer/WebDAVServer.js index 1be59a71..c3866bb4 100644 --- a/lib/server/webDAVServer/WebDAVServer.js +++ b/lib/server/webDAVServer/WebDAVServer.js @@ -12,9 +12,11 @@ exports.WebDAVServerOptions = WebDAVServerOptions_2.WebDAVServerOptions; var WebDAVServer = (function () { function WebDAVServer(options) { this.stop = startStop.stop; + // Persistence this.autoLoad = persistence.autoLoad; this.load = persistence.load; this.save = persistence.save; + // Before / After execution this.beforeRequest = beforeAfter.beforeRequest; this.afterRequest = beforeAfter.afterRequest; this.invokeBeforeRequest = beforeAfter.invokeBeforeRequest; @@ -27,6 +29,7 @@ var WebDAVServer = (function () { this.privilegeManager = this.options.privilegeManager; this.rootResource = this.options.rootResource; this.userManager = this.options.userManager; + // Implement all methods in commands/Commands.ts for (var k in Commands_1.default) if (k === 'NotImplemented') this.onUnknownMethod(Commands_1.default[k]); @@ -51,6 +54,7 @@ var WebDAVServer = (function () { WebDAVServer.prototype.normalizeMethodName = function (method) { return method.toLowerCase(); }; + // Events WebDAVServer.prototype.invoke = function (event, arg, subjectResource, details) { events.invoke.bind(this)(event, subjectResource, details); }; diff --git a/lib/user/authentication/HTTPDigestAuthentication.js b/lib/user/authentication/HTTPDigestAuthentication.js index 54b0b186..c23f8e53 100644 --- a/lib/user/authentication/HTTPDigestAuthentication.js +++ b/lib/user/authentication/HTTPDigestAuthentication.js @@ -39,7 +39,7 @@ var HTTPDigestAuthentication = (function () { onError(Errors_1.Errors.WrongHeaderFormat); return; } - authHeader = authHeader.substring(authHeader.indexOf(' ') + 1); + authHeader = authHeader.substring(authHeader.indexOf(' ') + 1); // remove the authentication type from the string var authProps = {}; var rex = /([a-zA-Z]+)\s*=\s*(?:(?:"((?:\\"|[^"])+)")|([^,\s]+))/g; var match = rex.exec(authHeader); diff --git a/lib/user/privilege/notused/Privilege.js b/lib/user/privilege/notused/Privilege.js index b374d957..39425359 100644 --- a/lib/user/privilege/notused/Privilege.js +++ b/lib/user/privilege/notused/Privilege.js @@ -1,5 +1,21 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +/* +[DAV:, all] (aggregate, abstract) + | + +-- [DAV:, read] (aggregate) + | + +-- [DAV:, read-acl] (abstract) + +-- [DAV:, read-current-user-privilege-set] (abstract) + | + +-- [DAV:, write] (aggregate) + | + +-- [DAV:, write-acl] (abstract) + +-- [DAV:, write-properties] + +-- [DAV:, write-content] + | + +-- [DAV:, unlock] +*/ var Privilege = (function () { function Privilege(name, description, isAbstract, subPrivileges) { this.description = description;