Skip to content

Commit

Permalink
feat: dont check db data on tgz download request (#1477)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jun 9, 2019
1 parent 9636903 commit 8e2367e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/index.js
Expand Up @@ -155,6 +155,8 @@ var config = {
}),
// if set true, will 302 redirect to `nfs.url(dist.key)`
downloadRedirectToNFS: false,
// don't check database and just download tgz from nfs
downloadTgzDontCheckModule: false,

// registry url name
registryHost: 'r.cnpmjs.org',
Expand Down
10 changes: 9 additions & 1 deletion controllers/registry/package/download.js
Expand Up @@ -19,7 +19,6 @@ module.exports = function* download(next) {
var name = this.params.name || this.params[0];
var filename = this.params.filename || this.params[1];
var version = filename.slice(name.length + 1, -4);
var row = yield packageService.getModule(name, version);
// can not get dist
var url = null;

Expand All @@ -36,7 +35,16 @@ module.exports = function* download(next) {
}

debug('download %s %s %s %s', name, filename, version, url);
// don't check database and just download tgz from nfs
if (config.downloadTgzDontCheckModule && url) {
this.status = 302;
this.set('Location', url);
const count = (globalDownloads.get(name) || 0) + 1;
globalDownloads.set(name, count);
return;
}

var row = yield packageService.getModule(name, version);
if (!row || !row.package || !row.package.dist) {
if (!url) {
return yield next;
Expand Down

0 comments on commit 8e2367e

Please sign in to comment.