@plotdb/registry 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +19 -0
- package/config.ngx +11 -2
- package/package.json +1 -1
- package/provider.js +108 -1
- package/providers/github.js +31 -1
- package/providers/npm.js +21 -2
- package/route.js +33 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v0.0.9
|
|
4
|
+
|
|
5
|
+
- features:
|
|
6
|
+
- support semver range version ( `~x.y.z` / `^x.y.z`, `^` comes url-encoded as `%5E` ):
|
|
7
|
+
range urls are resolved to the latest satisfying version and 302-redirected to the
|
|
8
|
+
specific version url, so content urls stay immutable and range dirs never land on disk.
|
|
9
|
+
- `provider.resolve` resolves a range against the provider chain; version lists are
|
|
10
|
+
cached per provider in `<pkg>/.reg.versions.<provider>` with cachetime-based expiry.
|
|
11
|
+
- providers implement `fetch-version-list`: github via `releases?per_page=100`
|
|
12
|
+
( most recent 100 only ), npm via registry metadata `versions`.
|
|
13
|
+
- ngx config: `proxy_cache_valid` now covers 302 ( ttl of range resolving ) and 400.
|
|
14
|
+
- ngx config: ignore / hide `Set-Cookie` in registry backend proxy -- session middleware
|
|
15
|
+
sets cookie on every response, which silently disabled proxy cache altogether.
|
|
16
|
+
- bug fix:
|
|
17
|
+
- fix npm provider name ( was `github` )
|
|
18
|
+
- route now responds 400 ( instead of 404 ) for invalid version / range syntax,
|
|
19
|
+
and no longer double-sends response on 500.
|
|
20
|
+
- tweaks:
|
|
21
|
+
- move `@plotdb/semver` to dependencies ( requires v0.0.4+, for `max-satisfying` etc. )
|
|
22
|
+
and drop the duplicate devDependencies entry
|
|
23
|
+
- add `build` / `test` npm scripts; add stub-based tests covering range resolving,
|
|
24
|
+
redirect routing, cache reuse and error codes ( `test/index.ls`, no network needed )
|
|
25
|
+
- upgrade `tar` 6 -> 7.5.21 for critical path-traversal / symlink-poisoning advisories
|
|
26
|
+
( registry extracts remote tarballs into an nginx-served dir, so these matter here );
|
|
27
|
+
api usage ( `tar.x {strip, cwd}` ) is unchanged, but node >= 18 is now required
|
|
28
|
+
( `engines` updated; was >= 10 )
|
|
29
|
+
|
|
30
|
+
|
|
3
31
|
## v0.0.8
|
|
4
32
|
|
|
5
33
|
- prevent long package name (>128 chars) and long version (>40 chars)
|
package/README.md
CHANGED
|
@@ -116,6 +116,11 @@ A registry provider object should contain following fields:
|
|
|
116
116
|
- `fetchBundleFile(opt)`: fetch the given package and ectract it.
|
|
117
117
|
- return a promise resolves when bundle file is extracted completely.
|
|
118
118
|
- check `fetchRealVersion` for the definition of `opt`.
|
|
119
|
+
- `fetchVersionList({name})`: ( optional ) list available versions of a given package, for range resolving.
|
|
120
|
+
- return a promise resolves a list of version strings ( e.g., `["1.0.0", "1.1.0"]` ).
|
|
121
|
+
- github provider lists via `releases?per_page=100` ( most recent 100 releases only );
|
|
122
|
+
npm provider lists via registry metadata `versions` field.
|
|
123
|
+
- a provider without `fetchVersionList` is simply skipped when resolving a range.
|
|
119
124
|
|
|
120
125
|
A provider provides following APIs:
|
|
121
126
|
|
|
@@ -129,6 +134,8 @@ A provider provides following APIs:
|
|
|
129
134
|
- in `@plotdb/block` `main` is the locked version, however there is no locked version defined here,
|
|
130
135
|
so `main` is equivalent to `latest`.
|
|
131
136
|
- in github, tags is used for fetching release. tags should be in format `vx.y.z`. e.g., `v1.0.0`.
|
|
137
|
+
- range versions ( e.g. `^1.2.3` ) are rejected with 400: they should be resolved
|
|
138
|
+
to a specific version with `resolve()` first, so range dirs never land on disk.
|
|
132
139
|
- `force`: default false. when true, ignore cache / 404 status and always try fetching package again.
|
|
133
140
|
- `cachetime`: default 3600 seconds. cache for how long (in seconds) since the last fetch attempts.
|
|
134
141
|
- return value: a Promise, resolves if package is found and downloaded. reject `e` in following situation:
|
|
@@ -139,6 +146,18 @@ A provider provides following APIs:
|
|
|
139
146
|
if it's actually 404, nginx will then look up the file and report 404 after found not found.
|
|
140
147
|
- the result will then cached by nginx and won't hit registry backend until cache expires.
|
|
141
148
|
- otherwise, it's an internal exception and should be logged and tracked.
|
|
149
|
+
- `resolve(opt)`: resolve a range version ( `~x.y.z` / `^x.y.z`, also `>` / `>=` ) to the latest
|
|
150
|
+
specific version satisfying it, walking the provider chain like `fetch` does.
|
|
151
|
+
- `opt` takes `root` / `name` / `version` / `force` / `cachetime` as in `fetch`,
|
|
152
|
+
where `version` must be a range.
|
|
153
|
+
- version lists are cached per provider in `<pkg>/.reg.versions.<provider>`,
|
|
154
|
+
expired by mtime + `cachetime` like other cache files.
|
|
155
|
+
- return value: a Promise resolving the version string; rejects 400 for a non-range
|
|
156
|
+
version, 404 if no provider has a satisfying version.
|
|
157
|
+
- `registry.route` uses this to serve range urls: it responds a 302 redirect to the
|
|
158
|
+
specific version url ( `^` arrives url-encoded as `%5E`; `~` needs no encoding ),
|
|
159
|
+
so content urls stay immutable and the redirect ttl is governed by nginx
|
|
160
|
+
`proxy_cache_valid 302`.
|
|
142
161
|
- `check({name, version})`: call the `check()` function provided in constructor.
|
|
143
162
|
- `chain(providers)`: chain given `providers` in this provider.
|
|
144
163
|
- `providers`: either another provider, or a list of other providers.
|
package/config.ngx
CHANGED
|
@@ -36,8 +36,17 @@ location @registry_backend {
|
|
|
36
36
|
proxy_set_header Host $http_host;
|
|
37
37
|
proxy_set_header X-NginX-Proxy true;
|
|
38
38
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
39
|
-
#
|
|
39
|
+
# session middleware ( e.g. express-session ) sets cookie on every response,
|
|
40
|
+
# which by default prevents nginx from caching anything -- so we ignore it.
|
|
41
|
+
# `proxy_hide_header` is REQUIRED along with `proxy_ignore_headers`: without it
|
|
42
|
+
# a cached response would replay one user's session cookie to other users.
|
|
43
|
+
proxy_ignore_headers Set-Cookie;
|
|
44
|
+
proxy_hide_header Set-Cookie;
|
|
45
|
+
# cache 200 / 404 result for `cache-period` so user can't bombard our backend.
|
|
46
|
+
# 302 is the range-version redirect ( e.g. `^1.2.3` -> resolved specific version ):
|
|
47
|
+
# its cache period is effectively the ttl of range resolving.
|
|
48
|
+
# 400 is for invalid range / version syntax.
|
|
40
49
|
proxy_cache !{cache.name};
|
|
41
|
-
proxy_cache_valid 200 404 !{cache.period};
|
|
50
|
+
proxy_cache_valid 200 302 400 404 !{cache.period};
|
|
42
51
|
proxy_pass http://!{upstream};
|
|
43
52
|
}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"author":"zbryikt","name":"@plotdb/registry","license":"MIT","description":"registry","version":"0.0.
|
|
1
|
+
{"author":"zbryikt","name":"@plotdb/registry","license":"MIT","description":"registry","version":"0.0.9","main":"index.js","homepage":"https://github.com/plotdb/registry","repository":{"type":"git","url":"https://github.com/plotdb/registry"},"engines":{"node":">=18","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true","server":"cd web; ../node_modules/.bin/lsc server.ls","build":"lsc -c -o dist src/index.ls src/route.ls src/provider.ls src/unbox.ls src/ngxgen.ls && lsc -c -o dist/providers src/providers/index.ls src/providers/github.ls src/providers/npm.ls && cp src/config.ngx dist/config.ngx","test":"lsc test/index.ls"},"bin":{"registry-ngx":"./../bin/ngxgen"},"dependencies":{"@plotdb/guides":"github:plotdb/guides#master","@plotdb/semver":"^0.0.4","@zbryikt/template":"^2.4.2","fs-extra":"^8.1.0","js-yaml":"^4.1.1","lderror":"^2.4.6","livescript":"^1.6.0","node-fetch":"^2.6.7","pthk":"^0.0.1","tar":"^7.5.21","template-text":"^0.2.0","yargs":"^17.6.0","yauzl":"^2.10.0"},"devDependencies":{"@loadingio/bootstrap.ext":"^0.0.12","@loadingio/debounce.js":"^1.0.1","@loadingio/ldquery":"^3.0.6","@plotdb/block":"^5.6.3","@plotdb/csscope":"^5.0.4","@plotdb/rescope":"^5.0.17","bootstrap":"^4.6.1","bootstrap.native":"^3.0.14","fedep":"^1.7.3","ldcover":"^3.5.6","ldloader":"^3.0.3","ldview":"^1.7.0","proxise":"^1.0.1"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["@loadingio/bootstrap.ext","@loadingio/debounce.js","@loadingio/ldquery","bootstrap","bootstrap.native","@plotdb/block","@plotdb/csscope","@plotdb/rescope","@plotdb/semver","ldcover","ldloader","ldview","proxise"]}}
|
package/provider.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
(function(){
|
|
2
|
-
var nodeFetch, lderror, yauzl, pthk, tar, fs, fetch, getVersionType, provider, ref$;
|
|
2
|
+
var nodeFetch, lderror, yauzl, pthk, tar, semver, fs, fetch, getVersionType, provider, ref$;
|
|
3
3
|
nodeFetch = require('node-fetch');
|
|
4
4
|
lderror = require('lderror');
|
|
5
5
|
yauzl = require('yauzl');
|
|
6
6
|
pthk = require('pthk');
|
|
7
7
|
tar = require('tar');
|
|
8
|
+
semver = require('@plotdb/semver');
|
|
8
9
|
fs = require("fs-extra");
|
|
9
10
|
fetch = nodeFetch;
|
|
10
11
|
getVersionType = function(v){
|
|
@@ -12,6 +13,8 @@
|
|
|
12
13
|
return 'latest';
|
|
13
14
|
} else if (/^\d+\.\d+\.\d+$/.test(v)) {
|
|
14
15
|
return 'specific';
|
|
16
|
+
} else if (/^[~^>]/.test(v) && semver.validRange(v)) {
|
|
17
|
+
return 'range';
|
|
15
18
|
} else {
|
|
16
19
|
return null;
|
|
17
20
|
}
|
|
@@ -22,6 +25,7 @@
|
|
|
22
25
|
this._ps = [].concat(o.chain || []);
|
|
23
26
|
this._fetchRealVersion = o.fetchRealVersion;
|
|
24
27
|
this._fetchBundleFile = o.fetchBundleFile;
|
|
28
|
+
this._fetchVersionList = o.fetchVersionList;
|
|
25
29
|
this._check = o.check;
|
|
26
30
|
this._opt = o.opt || {};
|
|
27
31
|
return this;
|
|
@@ -34,6 +38,7 @@
|
|
|
34
38
|
provider.get = function(n){
|
|
35
39
|
return this._hash[n];
|
|
36
40
|
};
|
|
41
|
+
provider.versionType = getVersionType;
|
|
37
42
|
provider.prototype = (ref$ = Object.create(Object.prototype), ref$.opt = function(o){
|
|
38
43
|
return this._opt = o || {};
|
|
39
44
|
}, ref$.fetch = function(o){
|
|
@@ -50,6 +55,9 @@
|
|
|
50
55
|
if (!versionType) {
|
|
51
56
|
return lderror.reject(400, "incorrect version-type when accessing " + name + "@" + version);
|
|
52
57
|
}
|
|
58
|
+
if (versionType === 'range') {
|
|
59
|
+
return lderror.reject(400, "range version should be resolved before fetch");
|
|
60
|
+
}
|
|
53
61
|
if ((name + "").length > 128 || (version + "").length > 40) {
|
|
54
62
|
return lderror.reject(998);
|
|
55
63
|
}
|
|
@@ -131,6 +139,105 @@
|
|
|
131
139
|
return this._ps.splice.apply(this._ps, [0, 0].concat(Array.isArray(ps)
|
|
132
140
|
? ps
|
|
133
141
|
: [ps]));
|
|
142
|
+
}, ref$.resolve = function(o){
|
|
143
|
+
var this$ = this;
|
|
144
|
+
o == null && (o = {});
|
|
145
|
+
return Promise.resolve().then(function(){
|
|
146
|
+
var root, name, version, force, cachetime, base, list, _;
|
|
147
|
+
root = o.root, name = o.name, version = o.version, force = o.force, cachetime = o.cachetime;
|
|
148
|
+
cachetime = cachetime || 60 * 60;
|
|
149
|
+
if (getVersionType(version) !== 'range') {
|
|
150
|
+
return lderror.reject(400, "not a range version: " + name + "@" + version);
|
|
151
|
+
}
|
|
152
|
+
if ((name + "").length > 128 || (version + "").length > 40) {
|
|
153
|
+
return lderror.reject(404);
|
|
154
|
+
}
|
|
155
|
+
if (!/^(?:@[0-9a-z._-]+\/)?[0-9a-z._-]+$/.test(name)) {
|
|
156
|
+
return lderror.reject(400);
|
|
157
|
+
}
|
|
158
|
+
base = pthk.join(root, pthk.rectify(name));
|
|
159
|
+
list = function(pvd){
|
|
160
|
+
var file;
|
|
161
|
+
if (!pvd._fetchVersionList) {
|
|
162
|
+
return lderror.reject(404);
|
|
163
|
+
}
|
|
164
|
+
file = pthk.join(base, ".reg.versions." + pvd._name);
|
|
165
|
+
return Promise.resolve().then(function(){
|
|
166
|
+
if (force) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
return fs.exists(file).then(function(isExisted){
|
|
170
|
+
if (!isExisted) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
return fs.stat(file).then(function(s){
|
|
174
|
+
if (Date.now() > s.mtime.getTime() + cachetime * 1000) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
return fs.readFile(file).then(function(r){
|
|
178
|
+
return JSON.parse(r);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}).then(function(cached){
|
|
183
|
+
if (cached) {
|
|
184
|
+
return cached.versions;
|
|
185
|
+
}
|
|
186
|
+
return pvd._fetchVersionList({
|
|
187
|
+
name: name
|
|
188
|
+
})['catch'](function(e){
|
|
189
|
+
if (lderror.id(e) === 404) {
|
|
190
|
+
return [];
|
|
191
|
+
} else {
|
|
192
|
+
return Promise.reject(e);
|
|
193
|
+
}
|
|
194
|
+
}).then(function(vs){
|
|
195
|
+
return fs.ensureDir(base).then(function(){
|
|
196
|
+
return fs.writeFile(file, JSON.stringify({
|
|
197
|
+
versions: vs
|
|
198
|
+
}));
|
|
199
|
+
}).then(function(){
|
|
200
|
+
return vs;
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
_ = function(idx){
|
|
206
|
+
var pvd;
|
|
207
|
+
idx == null && (idx = -1);
|
|
208
|
+
pvd = idx < 0
|
|
209
|
+
? this$
|
|
210
|
+
: this$._ps[idx];
|
|
211
|
+
if (!pvd) {
|
|
212
|
+
return lderror.reject(404);
|
|
213
|
+
}
|
|
214
|
+
return pvd.check({
|
|
215
|
+
name: name,
|
|
216
|
+
version: version
|
|
217
|
+
}).then(function(){
|
|
218
|
+
return list(pvd);
|
|
219
|
+
}).then(function(vs){
|
|
220
|
+
var v;
|
|
221
|
+
if (v = semver.maxSatisfying(vs, version)) {
|
|
222
|
+
return v;
|
|
223
|
+
}
|
|
224
|
+
return lderror.reject(404);
|
|
225
|
+
})['catch'](function(e){
|
|
226
|
+
if (lderror.id(e) !== 404) {
|
|
227
|
+
return Promise.reject(e);
|
|
228
|
+
} else {
|
|
229
|
+
return _(idx + 1);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
return _()['catch'](function(e){
|
|
234
|
+
if (lderror.id(e) === 403) {
|
|
235
|
+
return lderror.reject(404);
|
|
236
|
+
} else {
|
|
237
|
+
return Promise.reject(e);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
});
|
|
134
241
|
}, ref$._fetch = function(params){
|
|
135
242
|
var root, name, version, cachetime, force, path, versionType, this$ = this;
|
|
136
243
|
root = params.root, name = params.name, version = params.version, cachetime = params.cachetime, force = params.force, path = params.path, versionType = params.versionType;
|
package/providers/github.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
(function(){
|
|
2
|
-
var nodeFetch, lderror, provider, unbox, getToken, pvd;
|
|
2
|
+
var nodeFetch, lderror, provider, unbox, semver, getToken, pvd;
|
|
3
3
|
nodeFetch = require('node-fetch');
|
|
4
4
|
lderror = require('lderror');
|
|
5
5
|
provider = require('../provider');
|
|
6
6
|
unbox = require('../unbox');
|
|
7
|
+
semver = require('@plotdb/semver');
|
|
7
8
|
getToken = function(arg$){
|
|
8
9
|
var name, opt, ret, scope, token;
|
|
9
10
|
name = arg$.name, opt = arg$.opt;
|
|
@@ -15,6 +16,35 @@
|
|
|
15
16
|
};
|
|
16
17
|
pvd = new provider({
|
|
17
18
|
name: 'github',
|
|
19
|
+
fetchVersionList: function(arg$){
|
|
20
|
+
var name, headers, token, jsonurl;
|
|
21
|
+
name = arg$.name;
|
|
22
|
+
headers = (token = getToken({
|
|
23
|
+
name: name,
|
|
24
|
+
opt: this._opt
|
|
25
|
+
}))
|
|
26
|
+
? {
|
|
27
|
+
"Authorization": "token " + token
|
|
28
|
+
}
|
|
29
|
+
: {};
|
|
30
|
+
jsonurl = "https://api.github.com/repos/" + name.replace('@', '') + "/releases?per_page=100";
|
|
31
|
+
return nodeFetch(jsonurl, {
|
|
32
|
+
method: 'GET',
|
|
33
|
+
headers: headers
|
|
34
|
+
}).then(function(r){
|
|
35
|
+
if (r.status !== 200) {
|
|
36
|
+
return lderror.reject(404);
|
|
37
|
+
} else {
|
|
38
|
+
return r.json();
|
|
39
|
+
}
|
|
40
|
+
}).then(function(rs){
|
|
41
|
+
return rs.map(function(it){
|
|
42
|
+
return (it.tag_name + "").replace(/^v/, '');
|
|
43
|
+
}).filter(function(it){
|
|
44
|
+
return semver.valid(it);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
},
|
|
18
48
|
fetchRealVersion: function(arg$){
|
|
19
49
|
var root, path, name, cachetime, version, versionType, force, headers, token, release, jsonurl;
|
|
20
50
|
root = arg$.root, path = arg$.path, name = arg$.name, cachetime = arg$.cachetime, version = arg$.version, versionType = arg$.versionType, force = arg$.force;
|
package/providers/npm.js
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
(function(){
|
|
2
|
-
var nodeFetch, lderror, provider, unbox, pvd;
|
|
2
|
+
var nodeFetch, lderror, provider, unbox, semver, pvd;
|
|
3
3
|
nodeFetch = require('node-fetch');
|
|
4
4
|
lderror = require('lderror');
|
|
5
5
|
provider = require('../provider');
|
|
6
6
|
unbox = require('../unbox');
|
|
7
|
+
semver = require('@plotdb/semver');
|
|
7
8
|
pvd = new provider({
|
|
8
|
-
name: '
|
|
9
|
+
name: 'npm',
|
|
10
|
+
fetchVersionList: function(arg$){
|
|
11
|
+
var name, jsonurl;
|
|
12
|
+
name = arg$.name;
|
|
13
|
+
jsonurl = "https://registry.npmjs.org/" + name;
|
|
14
|
+
return nodeFetch(jsonurl, {
|
|
15
|
+
method: 'GET'
|
|
16
|
+
}).then(function(r){
|
|
17
|
+
if (r.status !== 200) {
|
|
18
|
+
return lderror.reject(404);
|
|
19
|
+
} else {
|
|
20
|
+
return r.json();
|
|
21
|
+
}
|
|
22
|
+
}).then(function(r){
|
|
23
|
+
return Object.keys(r.versions || {}).filter(function(it){
|
|
24
|
+
return semver.valid(it);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
},
|
|
9
28
|
fetchRealVersion: function(arg$){
|
|
10
29
|
var root, path, name, cachetime, version, versionType, force, opt, jsonurl;
|
|
11
30
|
root = arg$.root, path = arg$.path, name = arg$.name, cachetime = arg$.cachetime, version = arg$.version, versionType = arg$.versionType, force = arg$.force, opt = arg$.opt;
|
package/route.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
(function(){
|
|
2
|
-
var pthk, lderror, fs, handle, route;
|
|
2
|
+
var pthk, lderror, fs, versionType, handle, route;
|
|
3
3
|
pthk = require('pthk');
|
|
4
4
|
lderror = require('lderror');
|
|
5
5
|
fs = require("fs-extra");
|
|
6
|
+
versionType = require('./provider').versionType;
|
|
6
7
|
handle = function(arg$){
|
|
7
8
|
var provider, id, root, opt, ref$, paths, obj;
|
|
8
9
|
provider = arg$.provider, id = arg$.id, root = arg$.root, opt = arg$.opt;
|
|
@@ -11,8 +12,8 @@
|
|
|
11
12
|
}
|
|
12
13
|
ref$ = [{}, {}, pthk.rectify(id)], paths = ref$[0], obj = ref$[1], id = ref$[2];
|
|
13
14
|
return Promise.resolve().then(function(){
|
|
14
|
-
var ids;
|
|
15
|
-
if (!/^[-_a-zA-Z0-9
|
|
15
|
+
var ids, e;
|
|
16
|
+
if (!/^[-_a-zA-Z0-9@./~^%]+$/.exec(id)) {
|
|
16
17
|
return lderror.reject(404);
|
|
17
18
|
}
|
|
18
19
|
ids = id.split('/');
|
|
@@ -30,6 +31,25 @@
|
|
|
30
31
|
if (!(obj.name && obj.version && obj.path)) {
|
|
31
32
|
return lderror.reject(404);
|
|
32
33
|
}
|
|
34
|
+
try {
|
|
35
|
+
obj.version = decodeURIComponent(obj.version);
|
|
36
|
+
} catch (e$) {
|
|
37
|
+
e = e$;
|
|
38
|
+
return lderror.reject(404);
|
|
39
|
+
}
|
|
40
|
+
if (versionType(obj.version) === 'range') {
|
|
41
|
+
return provider.resolve(import$({
|
|
42
|
+
root: root.fs,
|
|
43
|
+
name: obj.name,
|
|
44
|
+
version: obj.version,
|
|
45
|
+
force: false,
|
|
46
|
+
cachetime: 60 * 60
|
|
47
|
+
}, opt)).then(function(v){
|
|
48
|
+
return {
|
|
49
|
+
redirect: pthk.join(root.pub, obj.name, v, obj.path)
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
33
53
|
return provider.fetch(import$({
|
|
34
54
|
root: root.fs,
|
|
35
55
|
name: obj.name,
|
|
@@ -65,18 +85,22 @@
|
|
|
65
85
|
id: id,
|
|
66
86
|
root: root,
|
|
67
87
|
opt: _o
|
|
68
|
-
}).then(function(){
|
|
88
|
+
}).then(function(r){
|
|
89
|
+
if (r && r.redirect) {
|
|
90
|
+
return res.redirect(302, r.redirect);
|
|
91
|
+
}
|
|
69
92
|
res.set({
|
|
70
93
|
"X-Accel-Redirect": pthk.join(root.internal, id)
|
|
71
94
|
});
|
|
72
95
|
return res.send();
|
|
73
96
|
})['catch'](function(e){
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
res.status(
|
|
97
|
+
var code;
|
|
98
|
+
code = lderror.id(e);
|
|
99
|
+
if (code === 400 || code === 404) {
|
|
100
|
+
return res.status(code).send();
|
|
78
101
|
}
|
|
79
|
-
|
|
102
|
+
console.log(e);
|
|
103
|
+
return res.status(500).send();
|
|
80
104
|
});
|
|
81
105
|
};
|
|
82
106
|
};
|