Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
add readmeFilename and missing created, modified time. #235
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Mar 4, 2014
1 parent ff50946 commit 0b7997e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
35 changes: 30 additions & 5 deletions controllers/registry/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ exports.show = function *(next) {
var versions = {};
var times = {};
var attachments = {};
var createdTime = null;
var modifiedTime = null;
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
if (row.version === 'next') {
Expand All @@ -91,13 +93,29 @@ exports.show = function *(next) {
common.setDownloadURL(pkg, this);
pkg._cnpm_publish_time = row.publish_time;
versions[pkg.version] = pkg;
times[pkg.version] = row.publish_time ? new Date(row.publish_time) : row.gmt_modified;
var t = times[pkg.version] = row.publish_time ? new Date(row.publish_time) : row.gmt_modified;
if ((!distTags.latest && !latestMod) || distTags.latest === row.version) {
latestMod = row;
readme = pkg.readme;
}
delete pkg.readme;

if (!createdTime || t < createdTime) {
createdTime = t;
}
if (!modifiedTime || t > modifiedTime) {
modifiedTime = t;
}
}

var ts = {
modified: modifiedTime,
created: createdTime,
};
for (var t in times) {
ts[t] = times[t];
}
times = ts;

if (!latestMod) {
latestMod = nextMod || rows[0];
Expand All @@ -112,21 +130,28 @@ exports.show = function *(next) {
rev = String(nextMod.id);
}

var pkg = latestMod.package;

var info = {
_id: name,
_rev: rev,
name: name,
description: latestMod.package.description,
description: pkg.description,
"dist-tags": distTags,
maintainers: latestMod.package.maintainers,
maintainers: pkg.maintainers,
time: times,
author: latestMod.package.author,
repository: latestMod.package.repository,
author: pkg.author,
repository: pkg.repository,
versions: versions,
readme: readme,
_attachments: attachments,
};

info.readmeFilename = pkg.readmeFilename;
info.homepage = pkg.homepage;
info.bugs = pkg.bugs;
info.license = pkg.license;

debug('show module %s: %s, latest: %s', name, rev, latestMod.version);

this.body = info;
Expand Down
10 changes: 8 additions & 2 deletions test/controllers/registry/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,15 @@ describe('controllers/registry/module.test.js', function () {
etag = res.headers.etag;
res.body.should.have.keys('_id', '_rev', 'name', 'description',
'versions', 'dist-tags', 'readme', 'maintainers',
'time', 'author', 'repository', '_attachments');
'time', 'author', 'repository', '_attachments',
'readmeFilename', 'homepage', 'bugs', 'license');
res.body.name.should.equal('cnpmjs.org');
res.body.versions[Object.keys(res.body.versions)[0]].dist.tarball.should.include('/cnpmjs.org/download');
res.body.versions[Object.keys(res.body.versions)[0]]
.dist.tarball.should.include('/cnpmjs.org/download');
res.body.time.should.have.property('modified');
res.body.time.modified.should.be.a.String;
res.body.time.should.have.property('created');
res.body.time.created.should.be.a.String;
done();
});
});
Expand Down

0 comments on commit 0b7997e

Please sign in to comment.