Skip to content

Commit 6e58ac6

Browse files
committed
Implemented the v2
1 parent 7c7874c commit 6e58ac6

File tree

171 files changed

+12419
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+12419
-0
lines changed

lib/helper/v2/IfParser.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { ReturnCallback } from '../../resource/IResource';
2+
import { RequestContext } from '../../server/v2/RequestContext';
3+
import { Resource } from '../../manager/v2/fileSystem/Resource';
4+
export declare function extractOneToken(ifHeader: string): string;
5+
export declare function parseIfHeader(ifHeader: string): (ctx: RequestContext, resource: Resource, callback: ReturnCallback<boolean>) => void;

lib/helper/v2/IfParser.js

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
var Path_1 = require("../../manager/v2/Path");
4+
var url = require("url");
5+
function NoLock() {
6+
return function (resource, callback) {
7+
resource.lockManager(function (e, lm) {
8+
if (e)
9+
return callback(e, false);
10+
lm.getLocks(function (e, locks) {
11+
callback(e, locks ? locks.length === 0 : false);
12+
});
13+
});
14+
};
15+
}
16+
function Token(token) {
17+
return function (resource, callback) {
18+
resource.lockManager(function (e, lm) {
19+
if (e)
20+
return callback(e, false);
21+
lm.getLock(token, function (e, lock) { return callback(e, !!lock && !e); });
22+
});
23+
};
24+
}
25+
function Tag(tag) {
26+
return function (resource, callback) {
27+
resource.etag(function (e, etag) { return callback(e, !e && etag === tag); });
28+
};
29+
}
30+
function Not(filter) {
31+
return function (resource, callback) {
32+
filter(resource, function (e, v) {
33+
callback(e, !v);
34+
});
35+
};
36+
}
37+
function parseInternal(group) {
38+
var rex = /((not)|<([^>]+)>|\[([^\]]+)\]|<(DAV:no-lock)>)/ig;
39+
var match = rex.exec(group);
40+
var isNot = false;
41+
var andArray = [];
42+
function add(filter) {
43+
andArray.push(isNot ? Not(filter) : filter);
44+
isNot = false;
45+
}
46+
while (match) {
47+
if (match[2]) {
48+
isNot = true;
49+
}
50+
else if (match[3]) {
51+
add(Token(match[3]));
52+
}
53+
else if (match[4]) {
54+
add(Tag(match[4]));
55+
}
56+
else if (match[5]) {
57+
add(NoLock());
58+
}
59+
match = rex.exec(group);
60+
}
61+
if (andArray.length)
62+
return function (r, callback) { return callback(null, true); };
63+
return function (resource, callback) {
64+
var nb = andArray.length;
65+
function done(error, result) {
66+
if (nb <= 0)
67+
return;
68+
if (error) {
69+
nb = -1;
70+
callback(error, false);
71+
return;
72+
}
73+
--nb;
74+
if (nb === 0 || !result) {
75+
nb = -1;
76+
callback(null, result);
77+
}
78+
}
79+
andArray.forEach(function (a) { return a(resource, done); });
80+
};
81+
}
82+
function extractOneToken(ifHeader) {
83+
var match = /^[ ]*\([ ]*<([^>]+)>[ ]*\)[ ]*$/.exec(ifHeader);
84+
if (!match)
85+
return null;
86+
else
87+
return match[1];
88+
}
89+
exports.extractOneToken = extractOneToken;
90+
function parseIfHeader(ifHeader) {
91+
var rex = /(?:<([^>]+)>)?\s*\(([^\)]+)\)/g;
92+
var match = rex.exec(ifHeader);
93+
var orArray = [];
94+
var oldPath = undefined;
95+
while (match) {
96+
if (match[1])
97+
oldPath = url.parse(match[1]).path;
98+
orArray.push({
99+
path: oldPath,
100+
actions: parseInternal(match[2])
101+
});
102+
match = rex.exec(ifHeader);
103+
}
104+
if (orArray.length == 0)
105+
return function (ctx, resource, callback) { return callback(null, true); };
106+
return function (ctx, resource, callback) {
107+
var nb = orArray.length;
108+
function done(error, result) {
109+
if (nb <= 0)
110+
return;
111+
if (error) {
112+
nb = -1;
113+
callback(error, false);
114+
return;
115+
}
116+
--nb;
117+
if (nb === 0 || result) {
118+
nb = -1;
119+
callback(null, result);
120+
}
121+
}
122+
orArray.forEach(function (a) {
123+
if (!a.path)
124+
a.actions(resource, done);
125+
else {
126+
var sPath_1 = new Path_1.Path(a.path);
127+
ctx.server.getFileSystem(sPath_1, function (fs, _, sub) {
128+
a.actions(fs.resource(ctx, sPath_1), done);
129+
});
130+
}
131+
});
132+
};
133+
}
134+
exports.parseIfHeader = parseIfHeader;

lib/helper/v2/export.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './IfParser';
2+
export * from '../Workflow';
3+
export * from '../XML';

lib/helper/v2/export.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"use strict";
2+
function __export(m) {
3+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4+
}
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
__export(require("./IfParser"));
7+
__export(require("../Workflow"));
8+
__export(require("../XML"));

lib/manager/export.v2.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './export';

lib/manager/export.v2.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
function __export(m) {
3+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4+
}
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
__export(require("./export"));

lib/manager/v2/Path.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export declare class Path {
2+
paths: string[];
3+
constructor(path: Path | string[] | string);
4+
isRoot(): boolean;
5+
fileName(): string;
6+
rootName(): string;
7+
parentName(): string;
8+
getParent(): Path;
9+
hasParent(): boolean;
10+
removeRoot(): string;
11+
removeFile(): string;
12+
getChildPath(childPath: string | Path): Path;
13+
clone(): Path;
14+
toString(endsWithSlash?: boolean): string;
15+
}

lib/manager/v2/Path.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
var Path = (function () {
4+
function Path(path) {
5+
if (path.constructor === String) {
6+
var sPath = decodeURI(path);
7+
var doubleIndex = void 0;
8+
while ((doubleIndex = sPath.indexOf('//')) !== -1)
9+
sPath = sPath.substr(0, doubleIndex) + sPath.substr(doubleIndex + 1);
10+
this.paths = sPath.replace(/(^\/|\/$)/g, '').split('/');
11+
}
12+
else if (path.constructor === Path)
13+
this.paths = path.paths.filter(function (x) { return true; }); // clone
14+
else
15+
this.paths = path;
16+
this.paths = this.paths.filter(function (p) { return p.length > 0; });
17+
}
18+
Path.prototype.isRoot = function () {
19+
return this.paths.length === 0 || this.paths.length === 1 && this.paths[0].length === 0;
20+
};
21+
Path.prototype.fileName = function () {
22+
return this.paths[this.paths.length - 1];
23+
};
24+
Path.prototype.rootName = function () {
25+
return this.paths[0];
26+
};
27+
Path.prototype.parentName = function () {
28+
return this.paths[this.paths.length - 2];
29+
};
30+
Path.prototype.getParent = function () {
31+
return new Path(this.paths.slice(0, this.paths.length - 1));
32+
};
33+
Path.prototype.hasParent = function () {
34+
return this.paths.length >= 2;
35+
};
36+
Path.prototype.removeRoot = function () {
37+
return this.paths.shift();
38+
};
39+
Path.prototype.removeFile = function () {
40+
return this.paths.pop();
41+
};
42+
Path.prototype.getChildPath = function (childPath) {
43+
var subPath = new Path(childPath);
44+
var path = this.clone();
45+
for (var _i = 0, _a = subPath.paths; _i < _a.length; _i++) {
46+
var subName = _a[_i];
47+
path.paths.push(subName);
48+
}
49+
return path;
50+
};
51+
Path.prototype.clone = function () {
52+
return new Path(this);
53+
};
54+
Path.prototype.toString = function (endsWithSlash) {
55+
if (endsWithSlash === void 0) { endsWithSlash = false; }
56+
var value = '/' + this.paths.join('/');
57+
if (endsWithSlash && value.length > 1)
58+
return value + '/';
59+
return value;
60+
};
61+
return Path;
62+
}());
63+
exports.Path = Path;

lib/manager/v2/export.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export * from './instances/FTPFileSystem';
2+
export * from './instances/PhysicalFileSystem';
3+
export * from './instances/VirtualFileSystem';
4+
export * from './fileSystem/export';
5+
export * from './Path';

lib/manager/v2/export.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use strict";
2+
function __export(m) {
3+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4+
}
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
__export(require("./instances/FTPFileSystem"));
7+
__export(require("./instances/PhysicalFileSystem"));
8+
__export(require("./instances/VirtualFileSystem"));
9+
__export(require("./fileSystem/export"));
10+
__export(require("./Path"));

0 commit comments

Comments
 (0)