Compare commits

...

13 Commits
0.3.1 ... 0.3.3

Author SHA1 Message Date
fengmk2
685af2a367 Release 0.3.3 2014-02-28 17:41:09 +08:00
dead_horse
818f216fb4 Merge pull request #232 from cnpm/host-hotfix
get request host from request.headers
2014-02-28 16:36:44 +08:00
fengmk2
1b47495565 get request host from request.headers 2014-02-28 16:35:51 +08:00
dead_horse
0ab314f27c Merge pull request #231 from cnpm/bug-fix
fix deps display bug#230 and nsf.url TypeError#229
2014-02-28 15:40:04 +08:00
fengmk2
95076c8787 fix deps display bug#230 and nsf.url TypeError#229 2014-02-28 15:35:37 +08:00
fengmk2
4e6eb0a9cc Release 0.3.2 2014-02-28 14:46:17 +08:00
fengmk2
29f17dd5d1 Merge pull request #228 from cnpm/update-sess
update koa-sess and koa-redis
2014-02-28 14:42:03 +08:00
dead_horse
3a48637ef1 update koa-sess and koa-redis 2014-02-28 14:40:47 +08:00
fengmk2
e1029b005f Merge pull request #227 from cnpm/fix-nfs
Fix nfs
2014-02-28 12:20:43 +08:00
dead_horse
66771dfc3b fix sync all test 2014-02-28 12:15:30 +08:00
dead_horse
66f05a2f07 remove nfs.downloadStream first, fix tmppath error 2014-02-28 12:04:28 +08:00
fengmk2
6660cabbb6 Merge pull request #226 from cnpm/giturl-bug-fix
fix fengmk2/giturl#1 bug
2014-02-27 20:53:33 +08:00
fengmk2
fbe1971957 fix fengmk2/giturl#1 bug 2014-02-27 20:52:19 +08:00
7 changed files with 38 additions and 47 deletions

View File

@@ -1,4 +1,20 @@
0.3.3 / 2014-02-28
==================
* Merge pull request #232 from cnpm/host-hotfix
* get request host from request.headers
* Merge pull request #231 from cnpm/bug-fix
* fix deps display bug#230 and nsf.url TypeError#229
0.3.2 / 2014-02-28
==================
* update koa-sess and koa-redis
* fix sync all test
* remove nfs.downloadStream first, fix tmppath error
* fix fengmk2/giturl#1 bug
0.3.1 / 2014-02-27
==================

View File

@@ -182,10 +182,14 @@ exports.download = function *(next) {
var version = filename.slice(name.length + 1, -4);
var row = yield Module.get(name, version);
// can not get dist
var url = nfs.url(common.getCDNKey(name, filename));
var url = null;
if (typeof nfs.url === 'function') {
url = nfs.url(common.getCDNKey(name, filename));
}
if (!row || !row.package || !row.package.dist) {
if (!nfs.url) {
if (!url) {
return yield next;
}
this.status = 302;
@@ -193,6 +197,7 @@ exports.download = function *(next) {
_downloads[name] = (_downloads[name] || 0) + 1;
return;
}
var dist = row.package.dist;
if (!dist.key) {
debug('get tarball by 302');
@@ -203,7 +208,7 @@ exports.download = function *(next) {
}
// else use `dist.key` to get tarball from nfs
if (!nfs.downloadStream && !nfs.download) {
if (!nfs.download) {
return yield next;
}
@@ -216,13 +221,9 @@ exports.download = function *(next) {
this.set('Content-Disposition', 'attachment; filename="' + filename + '"');
this.set('ETag', dist.shasum);
if (nfs.downloadStream) {
yield nfs.downloadStream(dist.key, this.res, {timeout: DOWNLOAD_TIMEOUT});
return;
}
// use download file api
var tmpPath = path.join(config.uploadDir, utility.randomString() + dist.key);
var tmpPath = path.join(config.uploadDir,
utility.randomString() + dist.key.replace(/\//g, '-'));
function cleanup() {
fs.unlink(tmpPath, utility.noop);
}
@@ -233,8 +234,8 @@ exports.download = function *(next) {
this.throw(err);
}
var tarball = fs.createReadStream(tmpPath);
tarball.on('error', cleanup);
tarball.on('end', cleanup);
tarball.once('error', cleanup);
tarball.once('end', cleanup);
this.body = tarball;
};

View File

@@ -51,7 +51,9 @@ exports.display = function *(next) {
];
var pkg = r[0];
var download = r[1];
var dependents = r[2];
var dependents = (r[2] || []).map(function (item) {
return item.deps;
});
if (!pkg || !pkg.package) {
return yield next;
@@ -90,7 +92,7 @@ exports.display = function *(next) {
}
if (pkg.repository && pkg.repository.url) {
pkg.repository.weburl = giturl.parse(pkg.repository.url);
pkg.repository.weburl = giturl.parse(pkg.repository.url) || pkg.repository.url;
}
setLicense(pkg);

View File

@@ -31,7 +31,7 @@ exports.getCDNKey = function (name, filename) {
exports.setDownloadURL = function (pkg, ctx, host) {
if (pkg.dist) {
host = host || ctx.host;
host = host || ctx.get('host') || ctx.host;
pkg.dist.tarball = util.format('%s://%s/%s/download/%s-%s.tgz',
ctx.protocol,
host, pkg.name, pkg.name, pkg.version);

View File

@@ -1,6 +1,6 @@
{
"name": "cnpmjs.org",
"version": "0.3.1",
"version": "0.3.3",
"description": "Private npm registry and web for Enterprise, base on MySQL and Simple Store Service",
"main": "index.js",
"scripts": {
@@ -21,15 +21,15 @@
"co-read": "0.0.1",
"co-write": "0.3.0",
"debug": "0.7.4",
"eventproxy": "0.2.6",
"eventproxy": "0.2.7",
"forward": "0.0.4",
"giturl": "0.0.1",
"giturl": "0.0.2",
"graceful": "0.0.6",
"gravatar": "1.0.6",
"humanize-number": "0.0.2",
"koa": "0.5.0",
"koa-markdown": "0.0.2",
"koa-middlewares": "0.0.5",
"koa-middlewares": "0.0.6",
"logfilestream": "0.1.0",
"marked": "0.3.1",
"microtime": "0.5.1",

View File

@@ -537,34 +537,6 @@ describe('controllers/registry/module.test.js', function () {
.expect('Location', 'http://qtestbucket.qiniudn.com/cutter/-/cutter-0.0.2.tgz')
.expect(302, done)
});
it('should download a file direct from nfs stream', function (done) {
var nfs = require('../../../common/nfs');
mm(nfs, 'downloadStream', thunkify(function (key, writeStream, options, callback) {
options.timeout.should.equal(600000);
nfs._client.download(key, {writeStream: writeStream, timeout: options.timeout}, callback);
}));
Module.__get__ = Module.get;
mm(Module, 'get', thunkify(function (name, version, callback) {
Module.__get__(name, version, function (err, info) {
info.package.dist.key = 'cutter/-/cutter-0.0.2.tgz';
callback(err, info);
});
}));
request(app)
.get('/cutter/download/cutter-0.0.2.tgz')
.expect('ETag', 'c61fde5e8c26d053574d0c722097029fd1bc963a')
.expect('Content-Type', 'application/octet-stream')
.expect('Content-Length', '3139')
.expect('Content-Disposition', 'attachment; filename="cutter-0.0.2.tgz"')
.expect(200)
.end(function (err, res) {
should.not.exist(err);
// TODO: why supertest change buffer to text?
// res.text.length.should.equal(3139);
done();
});
});
});
describe('DELETE /:name/download/:filename/-rev/:rev', function () {

View File

@@ -50,7 +50,7 @@ describe('sync/sync_all.js', function () {
mm.data(Module, 'listAllModuleNames', [{name: 'cnpmjs.org'}, {name: 'cutter'}]);
sync(function (err, data) {
should.not.exist(err);
data.successes.should.eql(['cnpm', 'cnpmjs.org', 'cutter']);
data.successes.should.eql(['cnpmjs.org', 'cutter']);
done();
});
});