Skip to content

Commit

Permalink
Compiled with comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Jun 20, 2017
1 parent 00aed8c commit 94077ae
Show file tree
Hide file tree
Showing 24 changed files with 76 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -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];
}
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/FSPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/resource/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
6 changes: 6 additions & 0 deletions lib/resource/lock/Lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
4 changes: 4 additions & 0 deletions lib/resource/physical/PhysicalFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
};
Expand Down
4 changes: 4 additions & 0 deletions lib/resource/physical/PhysicalFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -102,6 +104,7 @@ var PhysicalFolder = (function (_super) {
});
});
};
// ****************************** Content ****************************** //
PhysicalFolder.prototype.write = function (targetSource, callback) {
callback(Errors_1.Errors.InvalidOperation, null);
};
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions lib/resource/physical/PhysicalResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
Expand Down
4 changes: 4 additions & 0 deletions lib/resource/std/RootResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -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);
};
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions lib/resource/std/resourceTester/Children.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lib/resource/std/resourceTester/Content.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// ****************************** Content ****************************** //
function writeRead(callback) {
var _this = this;
callback = this.multiple(callback, 1);
Expand Down
1 change: 1 addition & 0 deletions lib/resource/std/resourceTester/Locks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions lib/resource/std/resourceTester/Properties.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions lib/resource/std/resourceTester/ResourceTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/resource/std/resourceTester/StdMetaData.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
3 changes: 3 additions & 0 deletions lib/resource/virtual/VirtualFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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);
};
Expand Down
3 changes: 3 additions & 0 deletions lib/resource/virtual/VirtualFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions lib/resource/virtualStored/VirtualStoredFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
};
Expand Down
3 changes: 3 additions & 0 deletions lib/resource/virtualStored/VirtualStoredFolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions lib/server/MethodCallArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion lib/server/commands/Copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); });
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lib/server/webDAVServer/StartStop.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function autoSave(options) {
case 'COPY':
case 'POST':
case 'PUT':
// Avoid concurrent saving
if (saving) {
saveRequested = true;
next();
Expand Down
4 changes: 4 additions & 0 deletions lib/server/webDAVServer/WebDAVServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]);
Expand All @@ -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);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/user/authentication/HTTPDigestAuthentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 94077ae

Please sign in to comment.