Skip to content

Commit

Permalink
Fixed a lot of lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Dec 28, 2017
1 parent 25b3dcc commit 7de911b
Show file tree
Hide file tree
Showing 39 changed files with 143 additions and 280 deletions.
74 changes: 40 additions & 34 deletions lib/server/v2/commands/Get.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,6 @@ var __extends = (this && this.__extends) || (function () {
Object.defineProperty(exports, "__esModule", { value: true });
var WebDAVRequest_1 = require("../WebDAVRequest");
var stream_1 = require("stream");
var MultipleRangedStream = (function (_super) {
__extends(MultipleRangedStream, _super);
function MultipleRangedStream(ranges) {
var _this = _super.call(this) || this;
_this.ranges = ranges;
_this.streams = ranges.map(function (r) {
return {
stream: new RangedStream(r.min, r.max),
range: r
};
});
return _this;
}
MultipleRangedStream.prototype._transform = function (chunk, encoding, callback) {
this.streams.forEach(function (streamRange) {
streamRange.stream.write(chunk, encoding);
});
callback(null, new Buffer(0));
};
MultipleRangedStream.prototype.end = function (chunk, encoding, cb) {
var _this = this;
if (this.onEnded)
process.nextTick(function () { return _this.onEnded(); });
_super.prototype.end.call(this, chunk, encoding, cb);
};
return MultipleRangedStream;
}(stream_1.Transform));
var RangedStream = (function (_super) {
__extends(RangedStream, _super);
function RangedStream(min, max) {
Expand Down Expand Up @@ -73,16 +46,49 @@ var RangedStream = (function (_super) {
};
return RangedStream;
}(stream_1.Transform));
var MultipleRangedStream = (function (_super) {
__extends(MultipleRangedStream, _super);
function MultipleRangedStream(ranges) {
var _this = _super.call(this) || this;
_this.ranges = ranges;
_this.streams = ranges.map(function (r) {
return {
stream: new RangedStream(r.min, r.max),
range: r
};
});
return _this;
}
MultipleRangedStream.prototype._transform = function (chunk, encoding, callback) {
this.streams.forEach(function (streamRange) {
streamRange.stream.write(chunk, encoding);
});
callback(null, new Buffer(0));
};
MultipleRangedStream.prototype.end = function (chunk, encoding, cb) {
var _this = this;
if (this.onEnded)
process.nextTick(function () { return _this.onEnded(); });
_super.prototype.end.call(this, chunk, encoding, cb);
};
return MultipleRangedStream;
}(stream_1.Transform));
function parseRangeHeader(mimeType, size, range) {
var separator = Array.apply(null, { length: 20 })
.map(function () { return String.fromCharCode('a'.charCodeAt(0) + Math.floor(Math.random() * 26)); })
.join('');
var createMultipart = function (range) {
return '--' + separator + '\r\nContent-Type: ' + mimeType + '\r\nContent-Range: bytes ' + range.min + '-' + range.max + '/*\r\n\r\n';
return "--" + separator + "\r\nContent-Type: " + mimeType + "\r\nContent-Range: bytes " + range.min + "-" + range.max + "/*\r\n\r\n";
};
var endMultipart = function () {
return '\r\n--' + separator + '--';
return "\r\n--" + separator + "--";
};
var ranges = range.split(',').map(function (block) { return parseRangeBlock(size, block); });
var separator = Array.apply(null, { length: 20 }).map(function () { return String.fromCharCode('a'.charCodeAt(0) + Math.floor(Math.random() * 26)); }).join('');
var len = ranges.reduce(function (previous, mm) { return mm.max - mm.min + 1 + previous; }, 0) + (ranges.length > 1 ? ranges.reduce(function (previous, mm) { return createMultipart(mm).length + previous; }, endMultipart().length + '\r\n'.length * (ranges.length - 1)) : 0);
var ranges = range
.split(',')
.map(function (block) { return parseRangeBlock(size, block); });
var len = ranges.reduce(function (previous, mm) { return mm.max - mm.min + 1 + previous; }, 0)
+ (ranges.length <= 1 ?
0 : ranges.reduce(function (previous, mm) { return createMultipart(mm).length + previous; }, endMultipart().length + '\r\n'.length * (ranges.length - 1)));
return {
ranges: ranges,
separator: separator,
Expand Down Expand Up @@ -164,11 +170,11 @@ var default_1 = (function () {
ctx.response.setHeader('Content-Length', len.toString());
if (ranges_1.length <= 1) {
ctx.response.setHeader('Content-Type', mimeType);
ctx.response.setHeader('Content-Range', 'bytes ' + ranges_1[0].min + '-' + ranges_1[0].max + '/*');
ctx.response.setHeader('Content-Range', "bytes " + ranges_1[0].min + "-" + ranges_1[0].max + "/*");
rstream.on('end', callback);
return rstream.pipe(new RangedStream(ranges_1[0].min, ranges_1[0].max)).pipe(ctx.response);
}
ctx.response.setHeader('Content-Type', 'multipart/byteranges; boundary=' + separator);
ctx.response.setHeader('Content-Type', "multipart/byteranges; boundary=" + separator);
var multi_1 = new MultipleRangedStream(ranges_1);
rstream.pipe(multi_1);
var current_1 = 0;
Expand Down
4 changes: 2 additions & 2 deletions lib/server/v2/commands/Head.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ var default_1 = (function () {
ctx.response.setHeader('Content-Length', len.toString());
if (ranges.length <= 1) {
ctx.response.setHeader('Content-Type', mimeType);
ctx.response.setHeader('Content-Range', 'bytes ' + ranges[0].min + '-' + ranges[0].max + '/*');
ctx.response.setHeader('Content-Range', "bytes " + ranges[0].min + "-" + ranges[0].max + "/*");
}
else
ctx.response.setHeader('Content-Type', 'multipart/byteranges; boundary=' + separator);
ctx.response.setHeader('Content-Type', "multipart/byteranges; boundary=" + separator);
}
catch (ex) {
ctx.setCode(WebDAVRequest_1.HTTPCodes.BadRequest);
Expand Down
6 changes: 3 additions & 3 deletions lib/server/v2/commands/Lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function createResponse(ctx, lock) {
activelock.ele('D:depth').add(lock.depth === -1 ? 'infinity' : lock.depth.toString());
if (lock.owner)
activelock.ele('D:owner').add(lock.owner);
activelock.ele('D:timeout').add('Second-' + lock.lockKind.timeout);
activelock.ele('D:timeout').add("Second-" + lock.lockKind.timeout);
return prop;
}
function createLock(ctx, data, callback) {
Expand All @@ -42,8 +42,8 @@ function createLock(ctx, data, callback) {
if (Object.keys(locks).length > 0) {
if (LockScope_1.LockScope.Exclusive.isSame(type_1))
return callback(Errors_1.Errors.Locked);
for (var path_1 in locks)
if (locks[path_1].some(function (l) { return LockScope_1.LockScope.Exclusive.isSame(l.lockKind.scope); }))
for (var path in locks)
if (locks[path].some(function (l) { return LockScope_1.LockScope.Exclusive.isSame(l.lockKind.scope); }))
return callback(Errors_1.Errors.Locked);
}
r.lockManager(function (e, lm) {
Expand Down
7 changes: 3 additions & 4 deletions lib/server/v2/commands/Propfind.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function parseRequestBody(ctx, data) {
}
}
function propstatStatus(status) {
return 'HTTP/1.1 ' + status + ' ' + http.STATUS_CODES[status];
return "HTTP/1.1 " + status + " " + http.STATUS_CODES[status];
}
var default_1 = (function () {
function default_1() {
Expand All @@ -78,7 +78,7 @@ var default_1 = (function () {
var errorNumber = WebDAVRequest_1.HTTPRequestContext.defaultStatusCode(e);
if (errorNumber !== null) {
var response_1 = new xml_js_builder_1.XMLElementBuilder('D:response');
response_1.ele('D:propstat').ele('D:status').add('HTTP/1.1 ' + errorNumber + ' ' + http.STATUS_CODES[errorNumber]);
response_1.ele('D:propstat').ele('D:status').add("HTTP/1.1 " + errorNumber + " " + http.STATUS_CODES[errorNumber]);
resource.fs.getFullPath(ctx, resource.path, function (e, path) {
if (e)
return nbOut(e);
Expand Down Expand Up @@ -161,7 +161,7 @@ var default_1 = (function () {
activelock.ele('D:depth').add('Infinity');
if (lock.owner)
activelock.ele('D:owner').add(lock.owner);
activelock.ele('D:timeout').add('Second-' + (lock.expirationDate - Date.now()));
activelock.ele('D:timeout').add("Second-" + (lock.expirationDate - Date.now()));
activelock.ele('D:locktoken').ele('D:href', undefined, true).add(lock.uuid);
activelock.ele('D:lockroot').ele('D:href', undefined, true).add(WebDAVRequest_1.HTTPRequestContext.encodeURL(ctx.fullUri(path)));
}
Expand Down Expand Up @@ -276,7 +276,6 @@ var default_1 = (function () {
default_1.prototype.unchunked = function (ctx, data, callback) {
var _this = this;
ctx.getResource(function (e, resource) {
var lockDiscoveryCache = {};
ctx.checkIfHeader(resource, function () {
var multistatus = new xml_js_builder_1.XMLElementBuilder('D:multistatus', {
'xmlns:D': 'DAV:'
Expand Down
2 changes: 1 addition & 1 deletion lib/server/v2/commands/Proppatch.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var WebDAVRequest_1 = require("../WebDAVRequest");
var xml_js_builder_1 = require("xml-js-builder");
var http_1 = require("http");
var Workflow_1 = require("../../../helper/Workflow");
var xml_js_builder_1 = require("xml-js-builder");
var Errors_1 = require("../../../Errors");
var default_1 = (function () {
function default_1() {
Expand Down
2 changes: 1 addition & 1 deletion lib/server/v2/webDAVServer/Persistence.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SimpleCallback } from '../../../manager/v2/fileSystem/CommonTypes';
import { FileSystemSerializer, SerializedData } from '../../../manager/v2/fileSystem/Serialization';
import { IAutoSave } from '../WebDAVServerOptions';
import { SimpleCallback } from '../../../manager/v2/fileSystem/CommonTypes';
export declare function load(data: SerializedData, serializers: FileSystemSerializer[], callback: (error: Error) => void): void;
export declare function autoLoad(callback: SimpleCallback): void;
export declare function save(callback: (error: Error, obj: SerializedData) => void): void;
Expand Down
2 changes: 1 addition & 1 deletion lib/server/v2/webDAVServer/Persistence.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Serialization_1 = require("../../../manager/v2/fileSystem/Serialization");
var VirtualFileSystem_1 = require("../../../manager/v2/instances/VirtualFileSystem");
var PhysicalFileSystem_1 = require("../../../manager/v2/instances/PhysicalFileSystem");
var VirtualFileSystem_1 = require("../../../manager/v2/instances/VirtualFileSystem");
var zlib = require("zlib");
var fs = require("fs");
function defaultSerializers() {
Expand Down
4 changes: 2 additions & 2 deletions lib/server/v2/webDAVServer/WebDAVServer.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/// <reference types="node" />
import { ExternalRequestContext, RequestContextExternalOptions, RequestContext } from '../RequestContext';
import { WebDAVServerOptions, IAutoSave } from '../WebDAVServerOptions';
import { HTTPMethod } from '../WebDAVRequest';
import { HTTPAuthentication } from '../../../user/v2/authentication/HTTPAuthentication';
import { PrivilegeManager } from '../../../user/v2/privilege/PrivilegeManager';
import { FileSystem } from '../../../manager/v2/fileSystem/FileSystem';
import { ReturnCallback } from '../../../manager/v2/fileSystem/CommonTypes';
import { HTTPMethod } from '../WebDAVRequest';
import { FileSystem } from '../../../manager/v2/fileSystem/FileSystem';
import { Resource } from '../../../manager/v2/fileSystem/Resource';
import { Path } from '../../../manager/v2/Path';
import * as persistence from './Persistence';
Expand Down
12 changes: 6 additions & 6 deletions lib/user/v2/authentication/HTTPDigestAuthentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var HTTPDigestAuthentication = (function () {
};
HTTPDigestAuthentication.prototype.askForAuthentication = function () {
return {
'WWW-Authenticate': 'Digest realm="' + this.realm + '", qop="auth", nonce="' + this.generateNonce() + '", opaque="' + this.generateNonce() + '"'
'WWW-Authenticate': "Digest realm=\"" + this.realm + "\", qop=\"auth\", nonce=\"" + this.generateNonce() + "\", opaque=\"" + this.generateNonce() + "\""
};
};
HTTPDigestAuthentication.prototype.getUser = function (ctx, callback) {
Expand Down Expand Up @@ -51,19 +51,19 @@ var HTTPDigestAuthentication = (function () {
this.userManager.getUserByName(authProps.username, function (e, user) {
if (e)
return onError(e);
var ha1 = md5(authProps.username + ':' + _this.realm + ':' + (user.password ? user.password : ''));
var ha1 = md5(authProps.username + ":" + _this.realm + ":" + (user.password ? user.password : ''));
if (authProps.algorithm === 'MD5-sess')
ha1 = md5(ha1 + ':' + authProps.nonce + ':' + authProps.cnonce);
ha1 = md5(ha1 + ":" + authProps.nonce + ":" + authProps.cnonce);
var ha2;
if (authProps.qop === 'auth-int')
return onError(Errors_1.Errors.WrongHeaderFormat); // ha2 = md5(ctx.request.method.toString().toUpperCase() + ':' + ctx.requested.uri + ':' + md5(...));
else
ha2 = md5(ctx.request.method.toString().toUpperCase() + ':' + ctx.requested.uri);
ha2 = md5(ctx.request.method.toString().toUpperCase() + ":" + ctx.requested.uri);
var result;
if (authProps.qop === 'auth-int' || authProps.qop === 'auth')
result = md5(ha1 + ':' + authProps.nonce + ':' + authProps.nc + ':' + authProps.cnonce + ':' + authProps.qop + ':' + ha2);
result = md5(ha1 + ":" + authProps.nonce + ":" + authProps.nc + ":" + authProps.cnonce + ":" + authProps.qop + ":" + ha2);
else
result = md5(ha1 + ':' + authProps.nonce + ':' + ha2);
result = md5(ha1 + ":" + authProps.nonce + ":" + ha2);
if (result.toLowerCase() === authProps.response.toLowerCase())
callback(Errors_1.Errors.None, user);
else
Expand Down
3 changes: 0 additions & 3 deletions src/helper/v2/IfParser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { RequestContext } from '../../server/v2/RequestContext'
import { Errors } from '../../Errors'
import { FileSystem } from '../../manager/v2/fileSystem/FileSystem'
import { ContextualFileSystem } from '../../manager/v2/fileSystem/ContextualFileSystem'
import { ReturnCallback } from '../../index.v2';
import { Resource } from '../../manager/v2/fileSystem/Resource'
import { Path } from '../../manager/v2/Path'
Expand Down
2 changes: 1 addition & 1 deletion src/manager/v2/Path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Path
if(path.constructor === String)
{
let sPath = path as string;
let doubleIndex;
let doubleIndex : number;
while((doubleIndex = sPath.indexOf('//')) !== -1)
sPath = sPath.substr(0, doubleIndex) + sPath.substr(doubleIndex + 1);
this.paths = sPath.replace(/(^\/|\/$)/g, '').split('/');
Expand Down
11 changes: 0 additions & 11 deletions src/manager/v2/fileSystem/CommonTypes.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import { ReturnCallback, SimpleCallback } from './CommonTypes'
import { Readable, Writable } from 'stream'
import { RequestContext } from '../../../server/v2/RequestContext'
import { XMLElement } from 'xml-js-builder'
import { LockScope } from '../../../resource/v2/lock/LockScope'
import { LockType } from '../../../resource/v2/lock/LockType'
import { LockKind } from '../../../resource/v2/lock/LockKind'
import { Workflow } from '../../../helper/Workflow'
import { Errors } from '../../../Errors'
import { Lock } from '../../../resource/v2/lock/Lock'
import { Path } from '../Path'
import * as mimeTypes from 'mime-types'
import * as crypto from 'crypto'

export type SimpleCallback = (error ?: Error) => void;
export type ReturnCallback<T> = (error ?: Error, data ?: T) => void;
Expand Down
9 changes: 0 additions & 9 deletions src/manager/v2/fileSystem/ContextInfo.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { ResourceType, OpenWriteStreamMode } from './CommonTypes'
import { Readable, Writable } from 'stream'
import { RequestContext } from '../../../server/v2/RequestContext'
import { LockScope } from '../../../resource/v2/lock/LockScope'
import { LockType } from '../../../resource/v2/lock/LockType'
import { LockKind } from '../../../resource/v2/lock/LockKind'
import { Workflow } from '../../../helper/Workflow'
import { Errors } from '../../../Errors'
import { Lock } from '../../../resource/v2/lock/Lock'
import { Path } from '../Path'
import * as mimeTypes from 'mime-types'
import * as crypto from 'crypto'

export interface IContextInfo
{
Expand Down
29 changes: 0 additions & 29 deletions src/manager/v2/fileSystem/ContextualFileSystem.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,15 @@
import {
AvailableLocksInfo,
CopyInfo,
CreateInfo,
CreationDateInfo,
DeleteInfo,
DisplayNameInfo,
ETagInfo,
IContextInfo,
LastModifiedDateInfo,
LockManagerInfo,
MimeTypeInfo,
MoveInfo,
OpenReadStreamInfo,
OpenWriteStreamInfo,
PropertyManagerInfo,
ReadDirInfo,
RenameInfo,
SizeInfo,
TypeInfo,
WebNameInfo
} from './ContextInfo'
import { ReturnCallback, SimpleCallback, Return2Callback, OpenWriteStreamMode, SubTree, ResourceType } from './CommonTypes'
import { FileSystemSerializer, ISerializableFileSystem } from './Serialization'
import { Readable, Writable } from 'stream'
import { IPropertyManager } from './PropertyManager'
import { RequestContext } from '../../../server/v2/RequestContext'
import { ILockManager } from './LockManager'
import { FileSystem } from './FileSystem'
import { LockScope } from '../../../resource/v2/lock/LockScope'
import { Resource } from './Resource'
import { LockType } from '../../../resource/v2/lock/LockType'
import { LockKind } from '../../../resource/v2/lock/LockKind'
import { Workflow } from '../../../helper/Workflow'
import { Errors } from '../../../Errors'
import { Lock } from '../../../resource/v2/lock/Lock'
import { Path } from '../Path'

import * as mimeTypes from 'mime-types'
import * as crypto from 'crypto'

export class ContextualFileSystem implements ISerializableFileSystem
{
constructor(public fs : FileSystem, public context : RequestContext)
Expand Down
7 changes: 1 addition & 6 deletions src/manager/v2/fileSystem/FileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
DeleteInfo,
DisplayNameInfo,
ETagInfo,
IContextInfo,
LastModifiedDateInfo,
LockManagerInfo,
MimeTypeInfo,
Expand All @@ -18,8 +17,7 @@ import {
ReadDirInfo,
RenameInfo,
SizeInfo,
TypeInfo,
WebNameInfo
TypeInfo
} from './ContextInfo'
import {
ResourceType,
Expand All @@ -38,10 +36,8 @@ import { Readable, Writable, Transform } from 'stream'
import { IPropertyManager, PropertyBag } from './PropertyManager'
import { ContextualFileSystem } from './ContextualFileSystem'
import { StandardMethods } from './StandardMethods'
import { IStorageManager } from './StorageManager'
import { RequestContext } from '../../../server/v2/RequestContext'
import { ILockManager } from './LockManager'
import { XMLElement } from 'xml-js-builder'
import { LockScope } from '../../../resource/v2/lock/LockScope'
import { LockType } from '../../../resource/v2/lock/LockType'
import { LockKind } from '../../../resource/v2/lock/LockKind'
Expand All @@ -50,7 +46,6 @@ import { Resource } from './Resource'
import { Errors } from '../../../Errors'
import { Lock } from '../../../resource/v2/lock/Lock'
import { Path } from '../Path'
import * as mimeTypes from 'mime-types'
import * as crypto from 'crypto'

class BufferedIsLocked
Expand Down
Loading

0 comments on commit 7de911b

Please sign in to comment.