Compare commits
69 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
152f6800da | ||
|
|
2f7e52f86f | ||
|
|
bb4b51c54f | ||
|
|
4c2303e4fa | ||
|
|
b70201db79 | ||
|
|
dd095147b0 | ||
|
|
08c4445e78 | ||
|
|
b892ad8185 | ||
|
|
a8ee1e43bf | ||
|
|
dd84674b98 | ||
|
|
ccec2cb45b | ||
|
|
f3a4500191 | ||
|
|
161a860f74 | ||
|
|
f58e8a24b0 | ||
|
|
9bc6a6dd74 | ||
|
|
c50364807d | ||
|
|
b3e3ecfc3a | ||
|
|
637b5fe785 | ||
|
|
6eed7b9002 | ||
|
|
899becb448 | ||
|
|
7e982ca877 | ||
|
|
26156253c7 | ||
|
|
9445d46bbf | ||
|
|
55bfcc853e | ||
|
|
4eeb1b25de | ||
|
|
42959196c6 | ||
|
|
d264b47b09 | ||
|
|
4e412d1808 | ||
|
|
73527da1f1 | ||
|
|
7986f198af | ||
|
|
adb1411313 | ||
|
|
2f24e9828e | ||
|
|
d7e5921e24 | ||
|
|
e3e6a1aaa5 | ||
|
|
0d1969fadd | ||
|
|
028e599d51 | ||
|
|
fa0dd5c23f | ||
|
|
7be5df8e70 | ||
|
|
adddf0e4c5 | ||
|
|
28cc13d583 | ||
|
|
c85b27b9b2 | ||
|
|
46795adf54 | ||
|
|
c8ab1735a5 | ||
|
|
4c759b40c8 | ||
|
|
1bab099f38 | ||
|
|
f95f814a8c | ||
|
|
ffcb0d669a | ||
|
|
81ca81d578 | ||
|
|
803f6d42f8 | ||
|
|
5366f16bcb | ||
|
|
ab18e49131 | ||
|
|
3c874244a7 | ||
|
|
d463b09c81 | ||
|
|
40301f260b | ||
|
|
72dbde1906 | ||
|
|
d68157faa8 | ||
|
|
c88991c028 | ||
|
|
262abe8520 | ||
|
|
9dd942df1a | ||
|
|
9ec552e08d | ||
|
|
2420164a9d | ||
|
|
822f2f6a4e | ||
|
|
d423a987ae | ||
|
|
70cefd817e | ||
|
|
2606af24a1 | ||
|
|
5b781cbda1 | ||
|
|
1519b52a74 | ||
|
|
4b73f6e0a7 | ||
|
|
88bcb14a4f |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -19,3 +19,4 @@ config/config.js
|
||||
backup/*.json
|
||||
backup/*.gz
|
||||
docs/web/history.md
|
||||
view/web/_layout.html
|
||||
|
||||
@@ -8,3 +8,4 @@ logo.png
|
||||
public/dist/
|
||||
backup/*.json
|
||||
backup/*.gz
|
||||
view/web/_layout.html
|
||||
|
||||
102
History.md
102
History.md
@@ -1,4 +1,106 @@
|
||||
|
||||
0.2.20 / 2014-01-23
|
||||
==================
|
||||
|
||||
* hotfix sync missing dependencies and readmes
|
||||
* fix sync readme error, fixed #174
|
||||
* add updateReadme in module
|
||||
|
||||
0.2.19 / 2014-01-22
|
||||
==================
|
||||
|
||||
* npm install no need to check authorization header. fixed #171
|
||||
|
||||
0.2.18 / 2014-01-20
|
||||
==================
|
||||
|
||||
* Support gitlab git url to display and click. fixed #160
|
||||
* fix redis crash
|
||||
|
||||
0.2.17 / 2014-01-17
|
||||
==================
|
||||
|
||||
* custom logo url
|
||||
* hotfix layout bug
|
||||
|
||||
0.2.16 / 2014-01-16
|
||||
==================
|
||||
|
||||
* fix publish-time bug
|
||||
|
||||
0.2.15 / 2014-01-16
|
||||
==================
|
||||
|
||||
* add publish_time to debug
|
||||
|
||||
0.2.14 / 2014-01-16
|
||||
==================
|
||||
|
||||
* add make autod
|
||||
* update publish_time, fixed #163
|
||||
|
||||
0.2.13 / 2014-01-15
|
||||
==================
|
||||
|
||||
* markdown tmpl not support footer, need to wrap on app start
|
||||
|
||||
0.2.12 / 2014-01-15
|
||||
==================
|
||||
|
||||
* add footer and npm client name customable
|
||||
|
||||
0.2.11 / 2014-01-15
|
||||
==================
|
||||
|
||||
* package page contributor link to search, default is true
|
||||
|
||||
0.2.10 / 2014-01-14
|
||||
==================
|
||||
|
||||
* fix #155 Content-Disposition wrong.
|
||||
|
||||
0.2.9 / 2014-01-14
|
||||
==================
|
||||
|
||||
* support startkey=c and startkey="c"
|
||||
* support couch db search api. fixed #153
|
||||
* fix fork me image link
|
||||
* support sync by query.name
|
||||
|
||||
0.2.8 / 2014-01-14
|
||||
==================
|
||||
|
||||
* dont show err stack on test env
|
||||
* add download link for package page
|
||||
|
||||
0.2.7 / 2014-01-13
|
||||
==================
|
||||
|
||||
* add shasum when nfs.upload and hfs.uploadBuffer, fixed #148
|
||||
|
||||
0.2.6 / 2014-01-13
|
||||
==================
|
||||
|
||||
* support custom session store, fixed #146
|
||||
|
||||
0.2.5 / 2014-01-13
|
||||
==================
|
||||
|
||||
* add download timeout and unit test
|
||||
* use downloadStream() first
|
||||
* nfs download to a writeable stream.
|
||||
|
||||
0.2.4 / 2014-01-10
|
||||
==================
|
||||
|
||||
* set main script to index.js, fixed #142
|
||||
|
||||
0.2.3 / 2014-01-10
|
||||
==================
|
||||
|
||||
* Dont show sync button on private package
|
||||
* Sync package as publish with no deps. fixed #138
|
||||
|
||||
0.2.2 / 2014-01-10
|
||||
==================
|
||||
|
||||
|
||||
4
Makefile
4
Makefile
@@ -31,4 +31,8 @@ test-all: test test-cov
|
||||
contributors: install
|
||||
@./node_modules/contributors/bin/contributors -f plain -o AUTHORS
|
||||
|
||||
autod: install
|
||||
@./node_modules/.bin/autod -w -e public,view,docs,backup
|
||||
@$(MAKE) install
|
||||
|
||||
.PHONY: test
|
||||
|
||||
@@ -9,12 +9,13 @@ cnpmjs.org
|
||||
|
||||
## What is this?
|
||||
|
||||
Private npm registry and web for Enterprise, base on MySQL and Simple File Store.
|
||||
Private npm registry and web for Enterprise, base on MySQL and [Simple Store Service](https://github.com/cnpm/cnpmjs.org/wiki/NFS-Guide).
|
||||
|
||||
@[JacksonTian](https://github.com/JacksonTian/) had a talk about [private npm](https://speakerdeck.com/jacksontian/qi-ye-ji-node-dot-jskai-fa).
|
||||
|
||||

|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
|
||||
@@ -19,6 +19,8 @@ var config = require('../config');
|
||||
|
||||
var client = qn.create(config.qn);
|
||||
|
||||
exports._client = client;
|
||||
|
||||
/**
|
||||
* Upload file
|
||||
*
|
||||
|
||||
@@ -33,7 +33,7 @@ if (config.debug) {
|
||||
session = connect.session({
|
||||
key: key,
|
||||
secret: config.sessionSecret,
|
||||
store: new RedisStore(config.redis),
|
||||
store: config.sessionStore || new RedisStore(config.redis),
|
||||
cookie: cookie,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -71,6 +71,11 @@ var config = {
|
||||
debug: false
|
||||
},
|
||||
|
||||
logoURL: 'http://ww4.sinaimg.cn/large/69c1d4acgw1ebfly5kjlij208202oglr.jpg',
|
||||
registryHost: 'r.cnpmjs.org',
|
||||
customFooter: '', // you can add copyright and site total script html here
|
||||
npmClientName: 'cnpm', // use `${name} install package`
|
||||
packagePageContributorSearch: true, // package page contributor link to search, default is true
|
||||
sourceNpmRegistry: 'http://registry.npmjs.org',
|
||||
enablePrivate: true, // enable private mode, only admin can publish, other use just can sync package from source npm
|
||||
admins: {
|
||||
|
||||
@@ -23,6 +23,9 @@ var utility = require('utility');
|
||||
var eventproxy = require('eventproxy');
|
||||
var Bagpipe = require('bagpipe');
|
||||
var urlparse = require('url').parse;
|
||||
var mime = require('mime');
|
||||
var semver = require('semver');
|
||||
var ms = require('ms');
|
||||
var config = require('../../config');
|
||||
var Module = require('../../proxy/module');
|
||||
var Total = require('../../proxy/total');
|
||||
@@ -32,7 +35,6 @@ var Log = require('../../proxy/module_log');
|
||||
var DownloadTotal = require('../../proxy/download');
|
||||
var SyncModuleWorker = require('../../proxy/sync_module_worker');
|
||||
var logger = require('../../common/logger');
|
||||
var semver = require('semver');
|
||||
|
||||
exports.show = function (req, res, next) {
|
||||
var name = req.params.name;
|
||||
@@ -84,6 +86,7 @@ exports.show = function (req, res, next) {
|
||||
}
|
||||
var pkg = row.package;
|
||||
common.setDownloadURL(pkg, req);
|
||||
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;
|
||||
if ((!distTags.latest && !latestMod) || distTags.latest === row.version) {
|
||||
@@ -138,6 +141,7 @@ exports.get = function (req, res, next) {
|
||||
Module[method](name, queryLabel, ep.done(function (mod) {
|
||||
if (mod) {
|
||||
common.setDownloadURL(mod.package, req);
|
||||
mod.package._cnpm_publish_time = mod.publish_time;
|
||||
return res.json(mod.package);
|
||||
}
|
||||
ep.emit('notFound');
|
||||
@@ -167,6 +171,8 @@ exports.get = function (req, res, next) {
|
||||
|
||||
var _downloads = {};
|
||||
|
||||
var DOWNLOAD_TIMEOUT = ms('10m');
|
||||
|
||||
exports.download = function (req, res, next) {
|
||||
var name = req.params.name;
|
||||
var filename = req.params.filename;
|
||||
@@ -181,9 +187,9 @@ exports.download = function (req, res, next) {
|
||||
}
|
||||
var dist = row.package.dist;
|
||||
if (dist.key) {
|
||||
return ep.emit('key', dist.key);
|
||||
return ep.emit('key', dist);
|
||||
} else {
|
||||
return ep.emit('url', dist.tarball);
|
||||
return ep.emit('url', dist);
|
||||
}
|
||||
ep.emit('nodist');
|
||||
});
|
||||
@@ -195,23 +201,46 @@ exports.download = function (req, res, next) {
|
||||
ep.emit('url', nfs.url(common.getCDNKey(name, filename)));
|
||||
});
|
||||
|
||||
ep.once('url', function (url) {
|
||||
ep.once('url', function (dist) {
|
||||
res.statusCode = 302;
|
||||
res.setHeader('Location', url);
|
||||
res.setHeader('Location', dist.tarball);
|
||||
res.end();
|
||||
_downloads[name] = (_downloads[name] || 0) + 1;
|
||||
});
|
||||
|
||||
ep.once('key', function (key) {
|
||||
if (!nfs.download) {
|
||||
ep.once('key', function (dist) {
|
||||
if (!nfs.downloadStream && !nfs.download) {
|
||||
return next();
|
||||
}
|
||||
var tmpPath = path.join(config.uploadDir, utility.randomString() + key);
|
||||
|
||||
_downloads[name] = (_downloads[name] || 0) + 1;
|
||||
|
||||
if (typeof dist.size === 'number') {
|
||||
res.setHeader('Content-Length', dist.size);
|
||||
}
|
||||
res.setHeader('Content-Type', mime.lookup(dist.key));
|
||||
res.setHeader('Content-Disposition', 'attachment; filename="' + filename + '"');
|
||||
res.setHeader('ETag', dist.shasum);
|
||||
|
||||
if (nfs.downloadStream) {
|
||||
nfs.downloadStream(dist.key, res, {timeout: DOWNLOAD_TIMEOUT},
|
||||
function (err) {
|
||||
if (err) {
|
||||
// TODO: just end or send error response?
|
||||
return next(err);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// use download file api
|
||||
var tmpPath = path.join(config.uploadDir, utility.randomString() + dist.key);
|
||||
function cleanup() {
|
||||
fs.unlink(tmpPath, utility.noop);
|
||||
}
|
||||
|
||||
nfs.download(key, tmpPath, function (err) {
|
||||
nfs.download(dist.key, tmpPath, {timeout: DOWNLOAD_TIMEOUT},
|
||||
function (err) {
|
||||
if (err) {
|
||||
cleanup();
|
||||
return next(err);
|
||||
@@ -220,7 +249,6 @@ exports.download = function (req, res, next) {
|
||||
tarball.on('error', cleanup);
|
||||
tarball.on('end', cleanup);
|
||||
tarball.pipe(res);
|
||||
_downloads[name] = (_downloads[name] || 0) + 1;
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -323,8 +351,13 @@ exports.upload = function (req, res, next) {
|
||||
});
|
||||
}
|
||||
shasum = shasum.digest('hex');
|
||||
var key = common.getCDNKey(name, filename);
|
||||
nfs.upload(filepath, {key: key, size: length}, function (err, result) {
|
||||
|
||||
var options = {
|
||||
key: common.getCDNKey(name, filename),
|
||||
size: length,
|
||||
shasum: shasum
|
||||
};
|
||||
nfs.upload(filepath, options, function (err, result) {
|
||||
// remove tmp file whatever
|
||||
fs.unlink(filepath, utility.noop);
|
||||
if (err) {
|
||||
@@ -406,6 +439,8 @@ exports.updateLatest = function (req, res, next) {
|
||||
}
|
||||
body._publish_on_cnpm = true;
|
||||
nextMod.package = body;
|
||||
// reset publish time
|
||||
nextMod.publish_time = Date.now();
|
||||
debug('update %s:%s %j', nextMod.package.name, nextMod.package.version, nextMod.package.dist);
|
||||
// change latest to version
|
||||
Module.update(nextMod, function (err) {
|
||||
@@ -492,9 +527,12 @@ exports.addPackageAndDist = function (req, res, next) {
|
||||
shasum = crypto.createHash('sha1');
|
||||
shasum.update(tarballBuffer);
|
||||
shasum = shasum.digest('hex');
|
||||
var key = common.getCDNKey(name, filename);
|
||||
|
||||
nfs.uploadBuffer(tarballBuffer, {key: key}, ep.done('upload'));
|
||||
var options = {
|
||||
key: common.getCDNKey(name, filename),
|
||||
shasum: shasum
|
||||
};
|
||||
nfs.uploadBuffer(tarballBuffer, options, ep.done('upload'));
|
||||
});
|
||||
|
||||
ep.on('upload', function (result) {
|
||||
|
||||
@@ -13,13 +13,27 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Log = require('../proxy/module_log');
|
||||
var SyncModuleWorker = require('../proxy/sync_module_worker');
|
||||
|
||||
exports.sync = function (req, res, next) {
|
||||
var username = req.session.name || 'anonymous';
|
||||
var name = req.params.name;
|
||||
SyncModuleWorker.sync(name, username, function (err, result) {
|
||||
var publish = req.query.publish === 'true';
|
||||
var noDep = req.query.nodeps === 'true';
|
||||
if (publish && !req.session.isAdmin) {
|
||||
return res.json(403, {
|
||||
error: 'no_perms',
|
||||
reason: 'Only admin can publish'
|
||||
});
|
||||
}
|
||||
|
||||
var options = {
|
||||
publish: publish,
|
||||
noDep: noDep,
|
||||
};
|
||||
SyncModuleWorker.sync(name, username, options, function (err, result) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
@@ -14,16 +14,19 @@
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var giturl = require('giturl');
|
||||
var moment = require('moment');
|
||||
var eventproxy = require('eventproxy');
|
||||
var semver = require('semver');
|
||||
var marked = require('marked');
|
||||
var gravatar = require('gravatar');
|
||||
var humanize = require('humanize-number');
|
||||
var config = require('../../config');
|
||||
var Module = require('../../proxy/module');
|
||||
var down = require('../download');
|
||||
var sync = require('../sync');
|
||||
var Log = require('../../proxy/module_log');
|
||||
var setDownloadURL = require('../../lib/common').setDownloadURL;
|
||||
|
||||
exports.display = function (req, res, next) {
|
||||
var params = req.params;
|
||||
@@ -72,15 +75,24 @@ exports.display = function (req, res, next) {
|
||||
if (contributor.email) {
|
||||
contributor.gravatar = gravatar.url(contributor.email, {s: '50', d: 'retro'}, false);
|
||||
}
|
||||
if (config.packagePageContributorSearch || !contributor.url) {
|
||||
contributor.url = '/~' + encodeURIComponent(contributor.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pkg.repository && pkg.repository.url) {
|
||||
pkg.repository.weburl = giturl.parse(pkg.repository.url);
|
||||
}
|
||||
|
||||
setLicense(pkg);
|
||||
|
||||
for (var k in download) {
|
||||
download[k] = humanize(download[k]);
|
||||
}
|
||||
|
||||
setDownloadURL(pkg, req, config.registryHost);
|
||||
|
||||
res.render('package', {
|
||||
title: 'Package - ' + pkg.name,
|
||||
package: pkg,
|
||||
@@ -105,8 +117,41 @@ exports.search = function (req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
exports.rangeSearch = function (req, res, next) {
|
||||
var startKey = req.query.startkey || '';
|
||||
if (startKey[0] === '"') {
|
||||
startKey = startKey.substring(1);
|
||||
}
|
||||
if (startKey[startKey.length - 1] === '"') {
|
||||
startKey = startKey.substring(0, startKey.length - 1);
|
||||
}
|
||||
var limit = Number(req.query.limit) || 20;
|
||||
Module.search(startKey, {limit: limit}, function (err, packages) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var rows = [];
|
||||
for (var i = 0; i < packages.length; i++) {
|
||||
var p = packages[i];
|
||||
var row = {
|
||||
key: p.name,
|
||||
count: 1,
|
||||
value: {
|
||||
name: p.name,
|
||||
description: p.description,
|
||||
}
|
||||
};
|
||||
rows.push(row);
|
||||
}
|
||||
res.json({
|
||||
rows: rows
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.displaySync = function (req, res, next) {
|
||||
var name = req.params.name;
|
||||
var name = req.params.name || req.query.name;
|
||||
res.render('sync', {
|
||||
name: name,
|
||||
title: 'Sync - ' + name
|
||||
|
||||
60
dispatch.js
60
dispatch.js
@@ -24,46 +24,36 @@ var workerPath = path.join(__dirname, 'worker.js');
|
||||
var childProcess = require('child_process');
|
||||
var syncPath = path.join(__dirname, 'sync');
|
||||
|
||||
function start(customConfig) {
|
||||
config.loadConfig(customConfig);
|
||||
if (config.enableCluster) {
|
||||
cluster.setupMaster({
|
||||
exec: workerPath
|
||||
});
|
||||
|
||||
if (config.enableCluster) {
|
||||
cluster.setupMaster({
|
||||
exec: workerPath
|
||||
});
|
||||
cluster.on('fork', function (worker) {
|
||||
console.log('[%s] [worker:%d] new worker start', new Date(), worker.process.pid);
|
||||
});
|
||||
|
||||
cluster.on('fork', function (worker) {
|
||||
console.log('[%s] [worker:%d] new worker start', new Date(), worker.process.pid);
|
||||
});
|
||||
cluster.on('disconnect', function (worker) {
|
||||
var w = cluster.fork();
|
||||
console.error('[%s] [master:%s] wroker:%s disconnect! new worker:%s fork',
|
||||
new Date(), process.pid, worker.process.pid, w.process.pid);
|
||||
});
|
||||
|
||||
cluster.on('disconnect', function (worker) {
|
||||
var w = cluster.fork();
|
||||
console.error('[%s] [master:%s] wroker:%s disconnect! new worker:%s fork',
|
||||
new Date(), process.pid, worker.process.pid, w.process.pid);
|
||||
});
|
||||
cluster.on('exit', function (worker, code, signal) {
|
||||
var exitCode = worker.process.exitCode;
|
||||
var err = new Error(util.format('worker %s died (code: %s, signal: %s)', worker.process.pid, exitCode, signal));
|
||||
err.name = 'WorkerDiedError';
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
cluster.on('exit', function (worker, code, signal) {
|
||||
var exitCode = worker.process.exitCode;
|
||||
var err = new Error(util.format('worker %s died (code: %s, signal: %s)', worker.process.pid, exitCode, signal));
|
||||
err.name = 'WorkerDiedError';
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
var numCPUs = require('os').cpus().length;
|
||||
// Fork workers.
|
||||
for (var i = 0; i < numCPUs; i++) {
|
||||
cluster.fork();
|
||||
}
|
||||
|
||||
childProcess.fork(syncPath);
|
||||
} else {
|
||||
require(workerPath);
|
||||
require(syncPath);
|
||||
var numCPUs = require('os').cpus().length;
|
||||
// Fork workers.
|
||||
for (var i = 0; i < numCPUs; i++) {
|
||||
cluster.fork();
|
||||
}
|
||||
}
|
||||
|
||||
if (!module.parent) {
|
||||
start();
|
||||
childProcess.fork(syncPath);
|
||||
} else {
|
||||
module.exports = start;
|
||||
require(workerPath);
|
||||
require(syncPath);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
## What is this?
|
||||
|
||||
> Private npm registry and web for Enterprise, base on MySQL and Simple File Store.
|
||||
> Private npm registry and web for Enterprise, base on MySQL and [Simple Store Service](https://github.com/cnpm/cnpmjs.org/wiki/NFS-Guide).
|
||||
|
||||
@[JacksonTian](https://github.com/JacksonTian/) had a talk about [private npm](https://speakerdeck.com/jacksontian/qi-ye-ji-node-dot-jskai-fa).
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
## Registry
|
||||
|
||||
* Our public registry: [registry.cnpmjs.org](http://registry.cnpmjs.org)
|
||||
* Our public registry: [r.cnpmjs.org](http://r.cnpmjs.org), syncing from [registry.npmjs.org](http://registry.npmjs.org)
|
||||
* Current [cnpmjs.org](/) version: <span id="app-version"></span>
|
||||
|
||||
<table class="downloads">
|
||||
@@ -119,13 +119,13 @@ $(function () {
|
||||
alias it:
|
||||
|
||||
```bash
|
||||
alias cnpm="npm --registry=http://registry.cnpmjs.org \
|
||||
alias cnpm="npm --registry=http://r.cnpmjs.org \
|
||||
--cache=$HOME/.npm/.cache/cnpm \
|
||||
--disturl=http://dist.u.qiniudn.com \
|
||||
--userconfig=$HOME/.cnpmrc"
|
||||
|
||||
#Or alias it in .bashrc or .zshrc
|
||||
$ echo '\n#alias for cnpm\nalias cnpm="npm --registry=http://registry.cnpmjs.org \
|
||||
$ echo '\n#alias for cnpm\nalias cnpm="npm --registry=http://r.cnpmjs.org \
|
||||
--cache=$HOME/.npm/.cache/cnpm \
|
||||
--disturl=http://dist.u.qiniudn.com \
|
||||
--userconfig=$HOME/.cnpmrc"' >> ~/.zshrc && source ~/.zshrc
|
||||
@@ -139,7 +139,7 @@ $ npm install cnpm -g
|
||||
|
||||
### install
|
||||
|
||||
Install package from [registry.cnpmjs.org](http://registry.cnpmjs.org). When isntall a package or version not exist, it will try to install from official registry([registry.npmjs.org](http://registry.npmjs.org)), and sync this package to cnpm in the backend.
|
||||
Install package from [r.cnpmjs.org](http://r.cnpmjs.org). When isntall a package or version not exist, it will try to install from official registry([registry.npmjs.org](http://registry.npmjs.org)), and sync this package to cnpm in the backend.
|
||||
|
||||
```
|
||||
$ cnpm install [name]
|
||||
|
||||
30
index.js
Normal file
30
index.js
Normal file
@@ -0,0 +1,30 @@
|
||||
/*!
|
||||
* cnpmjs.org - index.js
|
||||
*
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
* MIT Licensed
|
||||
*
|
||||
* Authors:
|
||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var config = require('./config');
|
||||
|
||||
exports.loadConfig = config.loadConfig;
|
||||
exports.config = config;
|
||||
|
||||
exports.startWorker = function (customConfig) {
|
||||
config.loadConfig(customConfig);
|
||||
require('./worker');
|
||||
};
|
||||
|
||||
exports.startSync = function (customConfig) {
|
||||
config.loadConfig(customConfig);
|
||||
require('./sync');
|
||||
};
|
||||
@@ -29,11 +29,12 @@ exports.getCDNKey = function (name, filename) {
|
||||
return '/' + name + '/-/' + filename;
|
||||
};
|
||||
|
||||
exports.setDownloadURL = function (pkg, req) {
|
||||
exports.setDownloadURL = function (pkg, req, host) {
|
||||
if (pkg.dist) {
|
||||
host = host || req.headers.host;
|
||||
pkg.dist.tarball = util.format('%s://%s/%s/download/%s-%s.tgz',
|
||||
req.connection.encrypted ? 'https' : 'http',
|
||||
req.headers.host, pkg.name, pkg.name, pkg.version);
|
||||
host, pkg.name, pkg.name, pkg.version);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*!
|
||||
/**!
|
||||
* cnpmjs.org - middleware/auth.js
|
||||
*
|
||||
* Copyright(c) cnpmjs.org and other contributors.
|
||||
@@ -21,6 +21,11 @@ var common = require('../lib/common');
|
||||
|
||||
module.exports = function (options) {
|
||||
return function auth(req, res, next) {
|
||||
if (!req.session) {
|
||||
// redis crash
|
||||
req.session = {};
|
||||
return next();
|
||||
}
|
||||
req.session.onlySync = config.enablePrivate ? true : false;
|
||||
if (req.session.name) {
|
||||
req.session.isAdmin = common.isAdmin(req.session.name);
|
||||
@@ -33,7 +38,12 @@ module.exports = function (options) {
|
||||
if (!authorization) {
|
||||
return next();
|
||||
}
|
||||
|
||||
authorization = new Buffer(authorization, 'base64').toString().split(':');
|
||||
if (authorization.length !== 2) {
|
||||
return next();
|
||||
}
|
||||
|
||||
var username = authorization[0];
|
||||
var password = authorization[1];
|
||||
|
||||
@@ -44,10 +54,9 @@ module.exports = function (options) {
|
||||
|
||||
if (!row) {
|
||||
debug('auth fail user: %j, headers: %j', row, req.headers);
|
||||
return res.json(401, {
|
||||
error: 'unauthorized',
|
||||
reason: 'Name or password is incorrect.'
|
||||
});
|
||||
req.session.name = null;
|
||||
req.session.isAdmin = false;
|
||||
return next();
|
||||
}
|
||||
|
||||
req.session.name = row.name;
|
||||
|
||||
17
package.json
17
package.json
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "cnpmjs.org",
|
||||
"version": "0.2.2",
|
||||
"description": "Private npm registry and web",
|
||||
"main": "dispatch.js",
|
||||
"version": "0.2.20",
|
||||
"description": "Private npm registry and web for Enterprise, base on MySQL and Simple Store Service",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "make test-all",
|
||||
"start": "./bin/nodejsctl start && cp History.md docs/web/history.md",
|
||||
@@ -30,16 +30,18 @@
|
||||
"debug": "0.7.4",
|
||||
"eventproxy": "0.2.6",
|
||||
"forward": "0.0.4",
|
||||
"giturl": "0.0.1",
|
||||
"graceful": "0.0.5",
|
||||
"gravatar": "1.0.6",
|
||||
"humanize-number": "0.0.2",
|
||||
"logfilestream": "0.1.0",
|
||||
"marked": "0.3.0",
|
||||
"microtime": "0.5.1",
|
||||
"mime": "1.2.11",
|
||||
"mkdirp": "0.3.5",
|
||||
"moment": "2.5.0",
|
||||
"moment": "2.5.1",
|
||||
"ms": "0.6.2",
|
||||
"mysql": "2.0.0",
|
||||
"mysql": "2.0.1",
|
||||
"nodemailer": "0.6.0",
|
||||
"qn": "0.2.0",
|
||||
"ready": "0.1.1",
|
||||
@@ -51,6 +53,7 @@
|
||||
"utility": "0.1.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"autod": ">=0.0.13",
|
||||
"blanket": "*",
|
||||
"contributors": "*",
|
||||
"coveralls": "*",
|
||||
@@ -58,8 +61,8 @@
|
||||
"mocha": "*",
|
||||
"mocha-lcov-reporter": "*",
|
||||
"pedding": "0.0.3",
|
||||
"should": "2.1.1",
|
||||
"supertest": "0.8.3",
|
||||
"should": "3.0.1",
|
||||
"supertest": "0.9.0",
|
||||
"travis-cov": "*"
|
||||
},
|
||||
"homepage": "https://github.com/cnpm/cnpmjs.org",
|
||||
|
||||
@@ -59,7 +59,21 @@ exports.updateDescription = function (id, description, callback) {
|
||||
mysql.query(UPDATE_DESC_SQL, [description, id], callback);
|
||||
};
|
||||
|
||||
var UPDATE_DIST_SQL = 'UPDATE module SET version=?, package=?, dist_tarball=?, dist_shasum=?, dist_size=? WHERE id=?;';
|
||||
var UPDATE_PACKAGE_SQL = 'UPDATE module SET package=? WHERE id=?;';
|
||||
exports.updateReadme = function (id, readme, callback) {
|
||||
exports.getById(id, function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
data.package = data.package || {};
|
||||
data.package.readme = readme;
|
||||
var pkg = stringifyPackage(data.package);
|
||||
mysql.query(UPDATE_PACKAGE_SQL, [pkg, id], callback);
|
||||
});
|
||||
};
|
||||
|
||||
var UPDATE_DIST_SQL = 'UPDATE module SET publish_time=?, version=?, package=?, \
|
||||
dist_tarball=?, dist_shasum=?, dist_size=? WHERE id=?;';
|
||||
|
||||
exports.update = function (mod, callback) {
|
||||
var pkg;
|
||||
@@ -69,7 +83,8 @@ exports.update = function (mod, callback) {
|
||||
return callback(e);
|
||||
}
|
||||
var dist = mod.package.dist;
|
||||
mysql.query(UPDATE_DIST_SQL, [mod.version, pkg, dist.tarball, dist.shasum, dist.size, mod.id],
|
||||
mysql.query(UPDATE_DIST_SQL,
|
||||
[mod.publish_time, mod.version, pkg, dist.tarball, dist.shasum, dist.size, mod.id],
|
||||
function (err, result) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -296,14 +311,20 @@ exports.listByAuthor = function (author, callback) {
|
||||
};
|
||||
|
||||
var SEARCH_SQLS = [
|
||||
'SELECT module_id FROM tag WHERE name LIKE ? AND tag="latest" ORDER BY name LIMIT 100;',
|
||||
'SELECT module_id FROM tag WHERE name LIKE ? AND tag="latest" ORDER BY name LIMIT ?;',
|
||||
'SELECT name, description FROM module WHERE id IN (?) ORDER BY name;'
|
||||
];
|
||||
exports.search = function (word, callback) {
|
||||
exports.search = function (word, options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = null;
|
||||
}
|
||||
options = options || {};
|
||||
var limit = options.limit || 100;
|
||||
word = word.replace(/^%/, '') + '%'; //ignore prefix %
|
||||
var ep = eventproxy.create();
|
||||
ep.fail(callback);
|
||||
mysql.query(SEARCH_SQLS[0], [word], ep.done(function (rows) {
|
||||
mysql.query(SEARCH_SQLS[0], [word, limit], ep.done(function (rows) {
|
||||
if (!rows || rows.length === 0) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
@@ -20,11 +20,9 @@ var config = require('../config');
|
||||
function request(url, options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = {
|
||||
dataType: 'json',
|
||||
timeout: 10000
|
||||
};
|
||||
options = null;
|
||||
}
|
||||
options = options || {};
|
||||
options.dataType = options.dataType || 'json';
|
||||
options.timeout = options.timeout || 120000;
|
||||
url = config.sourceNpmRegistry + url;
|
||||
|
||||
@@ -47,6 +47,8 @@ function SyncModuleWorker(options) {
|
||||
|
||||
this.username = options.username;
|
||||
this.concurrency = options.concurrency || 1;
|
||||
this._publish = options.publish; // _publish_on_cnpm
|
||||
|
||||
this.syncingNames = {};
|
||||
this.nameMap = {};
|
||||
this.names.forEach(function (name) {
|
||||
@@ -82,7 +84,8 @@ SyncModuleWorker.prototype.log = function (format, arg1, arg2) {
|
||||
};
|
||||
|
||||
SyncModuleWorker.prototype.start = function () {
|
||||
this.log('user: %s, sync %s worker start, %d concurrency.', this.username, this.names[0], this.concurrency);
|
||||
this.log('user: %s, sync %s worker start, %d concurrency, nodeps: %s, publish: %s',
|
||||
this.username, this.names[0], this.concurrency, this.noDep, this._publish);
|
||||
for (var i = 0; i < this.concurrency; i++) {
|
||||
this.next(i);
|
||||
}
|
||||
@@ -122,11 +125,11 @@ SyncModuleWorker.prototype.next = function (concurrencyId) {
|
||||
return that.next(concurrencyId);
|
||||
}
|
||||
|
||||
that.log('[c#%d] [%s] start...', concurrencyId, pkg.name);
|
||||
that._sync(pkg, function (err, versions) {
|
||||
that.log('[c#%d] [%s] start...', concurrencyId, name);
|
||||
that._sync(name, pkg, function (err, versions) {
|
||||
delete that.syncingNames[name];
|
||||
if (err) {
|
||||
that.fails.push(pkg.name);
|
||||
that.fails.push(name);
|
||||
that.log('[error] [%s] sync error: %s', name, err.stack);
|
||||
return that.next(concurrencyId);
|
||||
}
|
||||
@@ -139,9 +142,8 @@ SyncModuleWorker.prototype.next = function (concurrencyId) {
|
||||
});
|
||||
};
|
||||
|
||||
SyncModuleWorker.prototype._sync = function (pkg, callback) {
|
||||
var username = this.name;
|
||||
var name = pkg.name;
|
||||
SyncModuleWorker.prototype._sync = function (name, pkg, callback) {
|
||||
var username = this.username;
|
||||
var that = this;
|
||||
var ep = eventproxy.create();
|
||||
ep.fail(callback);
|
||||
@@ -159,7 +161,7 @@ SyncModuleWorker.prototype._sync = function (pkg, callback) {
|
||||
|
||||
if (r.package && r.package._publish_on_cnpm) {
|
||||
// publish on cnpm, dont sync this version package
|
||||
that.log(' [%s] publish on local cnpm, don\'t sync.', pkg.name);
|
||||
that.log(' [%s] publish on local cnpm, don\'t sync', name);
|
||||
ep.unbind();
|
||||
callback(null, []);
|
||||
return;
|
||||
@@ -192,6 +194,8 @@ SyncModuleWorker.prototype._sync = function (pkg, callback) {
|
||||
var missingVersions = [];
|
||||
var missingTags = [];
|
||||
var missingDescriptions = [];
|
||||
var missingReadmes = [];
|
||||
|
||||
ep.all('existsMap', 'existsTags', function (map, tags) {
|
||||
var times = pkg.time || {};
|
||||
pkg.versions = pkg.versions || {};
|
||||
@@ -200,7 +204,7 @@ SyncModuleWorker.prototype._sync = function (pkg, callback) {
|
||||
versionNames = Object.keys(pkg.versions);
|
||||
}
|
||||
if (versionNames.length === 0) {
|
||||
that.log(' [%s] no times and no versions, hasModules: %s', pkg.name, hasModules);
|
||||
that.log(' [%s] no times and no versions, hasModules: %s', name, hasModules);
|
||||
if (!hasModules) {
|
||||
// save a next module
|
||||
var maintainer = pkg.maintainers && pkg.maintainers[0];
|
||||
@@ -211,11 +215,11 @@ SyncModuleWorker.prototype._sync = function (pkg, callback) {
|
||||
maintainer = '-';
|
||||
}
|
||||
var nextMod = {
|
||||
name: pkg.name,
|
||||
name: name,
|
||||
version: 'next',
|
||||
author: maintainer,
|
||||
package: {
|
||||
name: pkg.name,
|
||||
name: name,
|
||||
version: 'next',
|
||||
description: pkg.description || '',
|
||||
readme: pkg.readme || '',
|
||||
@@ -225,7 +229,7 @@ SyncModuleWorker.prototype._sync = function (pkg, callback) {
|
||||
},
|
||||
};
|
||||
Module.add(nextMod, function (err, result) {
|
||||
that.log(' [%s] save next module, %j, error: %s', pkg.name, result, err);
|
||||
that.log(' [%s] save next module, %j, error: %s', name, result, err);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -237,7 +241,10 @@ SyncModuleWorker.prototype._sync = function (pkg, callback) {
|
||||
if (!version || !version.dist) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//patch for readme
|
||||
if (!version.readme) {
|
||||
version.readme = pkg.readme;
|
||||
}
|
||||
var publish_time = times[v];
|
||||
version.publish_time = publish_time ? Date.parse(publish_time) : null;
|
||||
if (!version.maintainers || !version.maintainers[0]) {
|
||||
@@ -250,7 +257,7 @@ SyncModuleWorker.prototype._sync = function (pkg, callback) {
|
||||
// * shasum make sure equal
|
||||
if ((version.publish_time === exists.publish_time) || (!version.publish_time && exists.publish_time)) {
|
||||
debug(' [%s] %s publish_time equal: %s, %s',
|
||||
pkg.name, version.version, version.publish_time, exists.publish_time);
|
||||
name, version.version, version.publish_time, exists.publish_time);
|
||||
// * publish_time make sure equal
|
||||
if (exists.description === null && version.description) {
|
||||
// * make sure description exists
|
||||
@@ -259,6 +266,14 @@ SyncModuleWorker.prototype._sync = function (pkg, callback) {
|
||||
description: version.description
|
||||
});
|
||||
}
|
||||
|
||||
if (!exists.package.readme && version.readme) {
|
||||
// * make sure readme exists
|
||||
missingReadmes.push({
|
||||
id: exists.id,
|
||||
readme: version.readme
|
||||
});
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -274,7 +289,7 @@ SyncModuleWorker.prototype._sync = function (pkg, callback) {
|
||||
}
|
||||
|
||||
if (versions.length === 0) {
|
||||
that.log(' [%s] all versions are exists', pkg.name);
|
||||
that.log(' [%s] all versions are exists', name);
|
||||
return ep.emit('syncDone');
|
||||
}
|
||||
|
||||
@@ -282,7 +297,7 @@ SyncModuleWorker.prototype._sync = function (pkg, callback) {
|
||||
return a.publish_time - b.publish_time;
|
||||
});
|
||||
missingVersions = versions;
|
||||
that.log(' [%s] %d versions', pkg.name, versions.length);
|
||||
that.log(' [%s] %d versions', name, versions.length);
|
||||
ep.emit('syncModule', missingVersions.shift());
|
||||
});
|
||||
|
||||
@@ -311,14 +326,15 @@ SyncModuleWorker.prototype._sync = function (pkg, callback) {
|
||||
return ep.emit('descriptionDone');
|
||||
}
|
||||
|
||||
that.log(' [%s] saving %d descriptions', pkg.name, missingDescriptions.length);
|
||||
that.log(' [%s] saving %d descriptions', name, missingDescriptions.length);
|
||||
missingDescriptions.forEach(function (item) {
|
||||
Module.updateDescription(item.id, item.description, function (err, result) {
|
||||
if (err) {
|
||||
return that.log(' save error, %s: description %j, error: %s', item.id, item.description, err);
|
||||
that.log(' save error, id: %s, description: %s, error: %s', item.id, item.description, err);
|
||||
} else {
|
||||
that.log(' saved, id: %s, description length: %d', item.id, item.description.length);
|
||||
}
|
||||
that.log(' saved, id: %s, description length: %d', item.id, item.description.length);
|
||||
ep.emit('saveDescription');
|
||||
ep.emitLater('saveDescription');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -332,12 +348,12 @@ SyncModuleWorker.prototype._sync = function (pkg, callback) {
|
||||
return ep.emit('tagDone');
|
||||
}
|
||||
|
||||
that.log(' [%s] adding %d tags', pkg.name, missingTags.length);
|
||||
that.log(' [%s] adding %d tags', name, missingTags.length);
|
||||
// sync tags
|
||||
missingTags.forEach(function (item) {
|
||||
Module.addTag(pkg.name, item[0], item[1], ep.done(function (result) {
|
||||
Module.addTag(name, item[0], item[1], ep.done(function (result) {
|
||||
that.log(' added tag %s:%s, module_id: %s', item[0], item[1], result && result.module_id);
|
||||
ep.emit('addTag');
|
||||
ep.emitLater('addTag');
|
||||
}));
|
||||
});
|
||||
|
||||
@@ -346,7 +362,29 @@ SyncModuleWorker.prototype._sync = function (pkg, callback) {
|
||||
});
|
||||
});
|
||||
|
||||
ep.all('tagDone', 'descriptionDone', function () {
|
||||
ep.once('syncDone', function () {
|
||||
if (missingReadmes.length === 0) {
|
||||
return ep.emit('readmeDone');
|
||||
}
|
||||
|
||||
that.log(' [%s] saving %d readmes', name, missingReadmes.length);
|
||||
missingReadmes.forEach(function (item) {
|
||||
Module.updateReadme(item.id, item.readme, function (err, result) {
|
||||
if (err) {
|
||||
that.log(' save error, id: %s, error: %s', item.id, err);
|
||||
} else {
|
||||
that.log(' saved, id: %s', item.id);
|
||||
}
|
||||
ep.emitLater('saveReadme');
|
||||
});
|
||||
});
|
||||
|
||||
ep.after('saveReadme', missingReadmes.length, function () {
|
||||
ep.emit('readmeDone');
|
||||
});
|
||||
});
|
||||
|
||||
ep.all('tagDone', 'descriptionDone', 'readmeDone', function () {
|
||||
// TODO: set latest version
|
||||
callback(null, versionNames);
|
||||
});
|
||||
@@ -371,8 +409,9 @@ SyncModuleWorker.prototype._syncOneVersion = function (versionIndex, sourcePacka
|
||||
callback(err);
|
||||
});
|
||||
|
||||
that.log(' [%s:%d] syncing, version: %s, dist: %j',
|
||||
sourcePackage.name, versionIndex, sourcePackage.version, sourcePackage.dist);
|
||||
that.log(' [%s:%d] syncing, version: %s, dist: %j, no deps: %s, publish on cnpm: %s',
|
||||
sourcePackage.name, versionIndex, sourcePackage.version,
|
||||
sourcePackage.dist, that.noDep, that._publish);
|
||||
if (!that.noDep) {
|
||||
for (var k in sourcePackage.dependencies) {
|
||||
that.add(k);
|
||||
@@ -419,8 +458,12 @@ SyncModuleWorker.prototype._syncOneVersion = function (versionIndex, sourcePacka
|
||||
return ep.emit('error', err);
|
||||
}
|
||||
|
||||
var key = common.getCDNKey(sourcePackage.name, filename);
|
||||
nfs.upload(filepath, {key: key, size: dataSize}, ep.done('uploadResult'));
|
||||
var options = {
|
||||
key: common.getCDNKey(sourcePackage.name, filename),
|
||||
size: dataSize,
|
||||
shasum: shasum
|
||||
};
|
||||
nfs.upload(filepath, options, ep.done('uploadResult'));
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -442,6 +485,12 @@ SyncModuleWorker.prototype._syncOneVersion = function (versionIndex, sourcePacka
|
||||
author: author,
|
||||
publish_time: sourcePackage.publish_time,
|
||||
};
|
||||
|
||||
if (that._publish) {
|
||||
// sync as publish
|
||||
mod.package._publish_on_cnpm = true;
|
||||
}
|
||||
|
||||
var dist = {
|
||||
shasum: shasum,
|
||||
size: dataSize,
|
||||
@@ -457,16 +506,23 @@ SyncModuleWorker.prototype._syncOneVersion = function (versionIndex, sourcePacka
|
||||
|
||||
mod.package.dist = dist;
|
||||
Module.add(mod, ep.done(function (result) {
|
||||
that.log(' [%s:%s] done, insertId: %s, author: %s, version: %s, size: %d, publish_time: %j',
|
||||
that.log(' [%s:%s] done, insertId: %s, author: %s, version: %s, size: %d, publish_time: %j, publish on cnpm: %s',
|
||||
sourcePackage.name, versionIndex,
|
||||
result.id,
|
||||
author, mod.version, dataSize, new Date(mod.publish_time));
|
||||
author, mod.version, dataSize,
|
||||
new Date(mod.publish_time),
|
||||
that._publish);
|
||||
callback(null, result);
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
SyncModuleWorker.sync = function (name, username, callback) {
|
||||
SyncModuleWorker.sync = function (name, username, options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
options = null;
|
||||
}
|
||||
options = options || {};
|
||||
npm.get(name, function (err, pkg, response) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -486,6 +542,8 @@ SyncModuleWorker.sync = function (name, username, callback) {
|
||||
logId: result.id,
|
||||
name: name,
|
||||
username: username,
|
||||
noDep: options.noDep,
|
||||
publish: options.publish,
|
||||
});
|
||||
worker.start();
|
||||
callback(null, {
|
||||
|
||||
@@ -62,7 +62,7 @@ function routes(app) {
|
||||
// https://registry.npmjs.org/-/user/org.couchdb.user:fengmk2
|
||||
app.put('/-/user/org.couchdb.user::name', user.add);
|
||||
app.get('/-/user/org.couchdb.user::name', user.show);
|
||||
app.put('/-/user/org.couchdb.user::name/-rev/:rev', login, user.update);
|
||||
app.put('/-/user/org.couchdb.user::name/-rev/:rev', [login], user.update);
|
||||
|
||||
// _session
|
||||
app.post('/_session', user.authSession);
|
||||
|
||||
@@ -31,6 +31,9 @@ function routes(app) {
|
||||
app.get('/sync/:name', pkg.displaySync);
|
||||
app.put('/sync/:name', sync.sync);
|
||||
app.get('/sync/:name/log/:id', sync.getSyncLog);
|
||||
app.get('/sync', pkg.displaySync);
|
||||
|
||||
app.get('/_list/search/search', pkg.rangeSearch);
|
||||
}
|
||||
|
||||
module.exports = routes;
|
||||
|
||||
@@ -65,9 +65,9 @@ app.use(function (req, res, next) {
|
||||
|
||||
app.use(function (err, req, res, next) {
|
||||
err.url = err.url || req.url;
|
||||
logger.error(err);
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
console.error(err.stack);
|
||||
logger.error(err);
|
||||
}
|
||||
if (config.debug) {
|
||||
return next(err);
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
require('response-patch');
|
||||
var path = require('path');
|
||||
var http = require('http');
|
||||
var fs = require('fs');
|
||||
var connect = require('connect');
|
||||
var rt = require('connect-rt');
|
||||
var urlrouter = require('urlrouter');
|
||||
@@ -49,9 +50,16 @@ app.use(connect.json());
|
||||
var viewDir = path.join(rootdir, 'view', 'web');
|
||||
var docDir = path.join(rootdir, 'docs', 'web');
|
||||
|
||||
var layoutFile = path.join(viewDir, '_layout.html');
|
||||
var footer = config.customFooter || fs.readFileSync(path.join(viewDir, 'footer.html'), 'utf8');
|
||||
var layout = fs.readFileSync(path.join(viewDir, 'layout.html'), 'utf8')
|
||||
.replace('{{footer}}', footer)
|
||||
.replace('{{logoURL}}', config.logoURL);
|
||||
fs.writeFileSync(layoutFile, layout);
|
||||
|
||||
app.use('/', connectMarkdown({
|
||||
root: docDir,
|
||||
layout: path.join(viewDir, 'layout.html'),
|
||||
layout: layoutFile,
|
||||
titleHolder: '<%- locals.title %>',
|
||||
bodyHolder: '<%- locals.body %>',
|
||||
indexName: 'readme'
|
||||
@@ -64,7 +72,7 @@ var helpers = {
|
||||
app.use(render({
|
||||
root: viewDir,
|
||||
viewExt: '.html',
|
||||
layout: 'layout',
|
||||
layout: '_layout',
|
||||
cache: config.viewCache,
|
||||
helpers: helpers
|
||||
}));
|
||||
@@ -81,8 +89,10 @@ app.use(urlrouter(routes));
|
||||
|
||||
app.use(function (err, req, res, next) {
|
||||
err.url = err.url || req.url;
|
||||
console.error(err.stack);
|
||||
logger.error(err);
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
console.error(err.stack);
|
||||
}
|
||||
if (config.debug) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
@@ -96,6 +96,9 @@ describe('controllers/registry/module.test.js', function () {
|
||||
body.version.should.equal('0.2.1');
|
||||
body._id.should.equal('cnpmjs.org@0.2.1');
|
||||
body.dist.tarball.should.include('cnpmjs.org-0.2.1.tgz');
|
||||
body.should.have.property('_cnpm_publish_time');
|
||||
body._cnpm_publish_time.should.be.a.Number;
|
||||
body.should.have.property('_publish_on_cnpm', true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -446,6 +449,43 @@ describe('controllers/registry/module.test.js', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /:name/download/:filename', function () {
|
||||
it('should download a file with 302 redirect', function (done) {
|
||||
request(app)
|
||||
.get('/cutter/download/cutter-0.0.2.tgz')
|
||||
.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', 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', 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 () {
|
||||
var lastRev;
|
||||
before(function (done) {
|
||||
|
||||
@@ -40,6 +40,54 @@ describe('controllers/sync.test.js', function () {
|
||||
describe('sync source npm package', function () {
|
||||
var logIdRegistry;
|
||||
var logIdWeb;
|
||||
|
||||
it('should sync as publish success', function (done) {
|
||||
request(registryApp)
|
||||
.del('/utility/-rev/123')
|
||||
.set('authorization', baseauth)
|
||||
// .expect(200)
|
||||
// .expect({ok: true})
|
||||
.end(function (err, res) {
|
||||
should.not.exist(err);
|
||||
|
||||
mm.data(Npm, 'get', require(path.join(fixtures, 'utility.json')));
|
||||
request(registryApp)
|
||||
.put('/utility/sync?publish=true&nodeps=true')
|
||||
.set('authorization', baseauth)
|
||||
.end(function (err, res) {
|
||||
should.not.exist(err);
|
||||
res.body.should.have.keys('ok', 'logId');
|
||||
logIdRegistry = res.body.logId;
|
||||
done();
|
||||
// setTimeout(function () {
|
||||
// request(registryApp)
|
||||
// .get('/utility')
|
||||
// .expect(200)
|
||||
// .end(function (err, res) {
|
||||
// should.not.exist(err);
|
||||
// Object.keys(res.body.versions).length.should.above(0);
|
||||
// for (var v in res.body.versions) {
|
||||
// var pkg = res.body.versions[v];
|
||||
// pkg.should.have.property('_publish_on_cnpm', true);
|
||||
// }
|
||||
// done();
|
||||
// });
|
||||
// }, 5000);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should sync as publish 403 when user not admin', function (done) {
|
||||
mm.data(Npm, 'get', require(path.join(fixtures, 'utility.json')));
|
||||
request(registryApp)
|
||||
.put('/utility_unit_test/sync?publish=true&nodeps=true')
|
||||
.expect(403)
|
||||
.expect({
|
||||
error: 'no_perms',
|
||||
reason: 'Only admin can publish'
|
||||
}, done);
|
||||
});
|
||||
|
||||
it('should sync success', function (done) {
|
||||
mm.data(Npm, 'get', require(path.join(fixtures, 'utility.json')));
|
||||
done = pedding(2, done);
|
||||
|
||||
@@ -31,6 +31,48 @@ describe('controllers/web/package.test.js', function () {
|
||||
|
||||
afterEach(mm.restore);
|
||||
|
||||
describe('GET /_list/search/search', function () {
|
||||
it('should search with "c"', function (done) {
|
||||
request(app)
|
||||
.get('/_list/search/search?startkey="c"&limit=2')
|
||||
.expect(200, function (err, res) {
|
||||
should.not.exist(err);
|
||||
res.body.should.have.keys('rows');
|
||||
res.body.rows.should.eql([
|
||||
{ key: 'c', count: 1, value: { name: 'c', description: 'Give folders or directories comments and view them easy.' } },
|
||||
{ key: 'charset', count: 1,
|
||||
value: { name: 'charset', description: 'Get the content charset from header and html content-type.' } }
|
||||
]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should search with c', function (done) {
|
||||
request(app)
|
||||
.get('/_list/search/search?startkey=c&limit=2')
|
||||
.expect(200, function (err, res) {
|
||||
should.not.exist(err);
|
||||
res.body.should.have.keys('rows');
|
||||
res.body.rows.should.eql([
|
||||
{ key: 'c', count: 1, value: { name: 'c', description: 'Give folders or directories comments and view them easy.' } },
|
||||
{ key: 'charset', count: 1,
|
||||
value: { name: 'charset', description: 'Get the content charset from header and html content-type.' } }
|
||||
]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should search return empty', function (done) {
|
||||
request(app)
|
||||
.get('/_list/search/search?startkey="cddddsdasdaasds"&limit=2')
|
||||
.expect(200, function (err, res) {
|
||||
should.not.exist(err);
|
||||
res.body.should.eql({rows: []});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /package/:name', function (done) {
|
||||
it('should get 200', function (done) {
|
||||
request(app)
|
||||
|
||||
@@ -45,11 +45,12 @@ describe('middleware/auth.test.js', function () {
|
||||
.expect(200, done);
|
||||
});
|
||||
|
||||
it('should 401 with authorization and check fail', function (done) {
|
||||
it('should pass with authorization and check fail', function (done) {
|
||||
// npm install no need to check auth
|
||||
request(app)
|
||||
.get('/-/user/org.couchdb.user:cnpmjstest10')
|
||||
.set('authorization', 'basic ' + new Buffer('cnpmjstest10:cnpmjstest').toString('base64'))
|
||||
.expect(401, done);
|
||||
.expect(200, done);
|
||||
});
|
||||
|
||||
it('should 500 with authorization and mysql error', function (done) {
|
||||
|
||||
@@ -23,6 +23,7 @@ var Module = require('../../proxy/module');
|
||||
|
||||
var fixtures = path.join(path.dirname(__dirname), 'fixtures');
|
||||
|
||||
var id;
|
||||
describe('proxy/module.test.js', function () {
|
||||
afterEach(mm.restore);
|
||||
|
||||
@@ -53,6 +54,7 @@ describe('proxy/module.test.js', function () {
|
||||
};
|
||||
mod.package.dist = dist;
|
||||
Module.add(mod, function (err, result) {
|
||||
id = result.id;
|
||||
should.not.exist(err);
|
||||
Module.getById(result.id, function (err, row) {
|
||||
should.not.exist(err);
|
||||
@@ -74,4 +76,17 @@ describe('proxy/module.test.js', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateReadme()', function () {
|
||||
it('should update ok', function (done) {
|
||||
Module.updateReadme(id, 'test', function (err, data) {
|
||||
should.not.exist(err);
|
||||
Module.getById(id, function (err, data) {
|
||||
should.not.exist(err);
|
||||
data.package.readme.should.equal('test');
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -30,6 +30,8 @@ Log.create({
|
||||
name: names,
|
||||
username: 'fengmk2',
|
||||
concurrency: names.length,
|
||||
noDep: true,
|
||||
publish: true,
|
||||
});
|
||||
|
||||
worker.start();
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('sync/sync_exist.js', function () {
|
||||
should.not.exist(err);
|
||||
data.successes.should.eql(['cnpmjs.org', 'cutter']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
5
view/web/footer.html
Normal file
5
view/web/footer.html
Normal file
@@ -0,0 +1,5 @@
|
||||
Copyright 2013 - 2014 © cnpmjs.org
|
||||
|
|
||||
<a href="/">Home</a>
|
||||
|
|
||||
<script>var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_5757157'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s17.cnzz.com/stat.php%3Fid%3D5757157%26online%3D1%26show%3Dline' type='text/javascript'%3E%3C/script%3E"));</script>
|
||||
@@ -47,20 +47,16 @@
|
||||
<body>
|
||||
<div class="container">
|
||||
<div id="content-header">
|
||||
<a href="/"><img src="http://ww4.sinaimg.cn/large/69c1d4acgw1ebfly5kjlij208202oglr.jpg"></a>
|
||||
<a href="/"><img src="{{logoURL}}"></a>
|
||||
<input type="text" id="search-input" class="form-control" placeholder="Search Packages">
|
||||
</div>
|
||||
<div id="content-body"><%- locals.body %></div>
|
||||
<div class="bottom">
|
||||
<hr/>
|
||||
<p>
|
||||
Copyright 2013 - 2014 © cnpmjs.org
|
||||
|
|
||||
<a href="/">Home</a>
|
||||
|
|
||||
<script>var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_5757157'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s17.cnzz.com/stat.php%3Fid%3D5757157%26online%3D1%26show%3Dline' type='text/javascript'%3E%3C/script%3E"));</script>
|
||||
{{footer}}
|
||||
</p>
|
||||
<a href="https://github.com/fengmk2/cnpmjs.org" id="fork" target="_blank">
|
||||
<a href="https://github.com/cnpm/cnpmjs.org" id="fork" target="_blank">
|
||||
<img alt="Fork me on GitHub" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
<div id="package">
|
||||
<h1>
|
||||
<%= package.name %>
|
||||
<small>(<a href="/sync/<%= package.name %>" target="_blank">SYNC</a> missed versions from official npm registry)</small>
|
||||
<small>
|
||||
<% if (package._publish_on_cnpm) { %>
|
||||
(Private package)
|
||||
<% } else { %>
|
||||
(<a href="/sync/<%= package.name %>" target="_blank">SYNC</a> missed versions from official npm registry)
|
||||
<% } %>
|
||||
</small>
|
||||
</h1>
|
||||
|
||||
<% if (package.deprecated) { %>
|
||||
@@ -12,7 +18,7 @@
|
||||
<p class="description"><%= package.description %></p>
|
||||
<% } %>
|
||||
|
||||
<pre class="sh"><code>$ cnpm install <%= package.name %></code></pre>
|
||||
<pre class="sh"><code>$ <%- config.npmClientName %> install <%= package.name %></code></pre>
|
||||
|
||||
<table class="downloads">
|
||||
<tbody>
|
||||
@@ -83,19 +89,13 @@
|
||||
%></td>
|
||||
</tr>
|
||||
<% } %>
|
||||
<% if (package.repository && package.repository !== 'undefined') {
|
||||
var gh = package.repository.url &&
|
||||
package.repository.url.match(
|
||||
/^(?:https?:\/\/|git(?::\/\/|@))(gist.github.com|github.com)[:\/](.*?)(?:.git)?$/)
|
||||
if (gh) {
|
||||
gh = 'https://' + gh[1] + '/' + gh[2]
|
||||
}
|
||||
%>
|
||||
<% if (package.repository && package.repository !== 'undefined') { %>
|
||||
<tr>
|
||||
<th>Repository</td>
|
||||
<td>
|
||||
<% if (gh) { %><a href="<%= gh %>" target="_blank"><% } %>
|
||||
<%= package.repository.url %><% if (gh) { %></a><% } %>
|
||||
<a href="<%= package.repository.weburl || package.repository.url %>" target="_blank">
|
||||
<%= package.repository.url %>
|
||||
</a>
|
||||
(<%= package.repository.type %>)
|
||||
</td>
|
||||
</tr>
|
||||
@@ -175,7 +175,7 @@
|
||||
<td>
|
||||
<% package.contributors.forEach(function (m) { %>
|
||||
<span class="user">
|
||||
<a class="username" href="/~<%= m.name %>">
|
||||
<a class="username" target="_blank" href="<%= m.url %>">
|
||||
<% if (m.gravatar) { %>
|
||||
<img src="<%- m.gravatar %>" class="avatar">
|
||||
<% } %>
|
||||
@@ -186,6 +186,17 @@
|
||||
</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
|
||||
<% if (package.dist && package.dist.tarball) { %>
|
||||
<tr>
|
||||
<th>Download</th>
|
||||
<td>
|
||||
<a class="downloadlink" target="_blank" href="<%= package.dist.tarball %>">
|
||||
<%= package.dist.tarball %>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<% } %>
|
||||
</table>
|
||||
|
||||
<div class="details">
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
var $notify = $('#sync-notify');
|
||||
var timer;
|
||||
var name = '<%= name %>';
|
||||
var resourceURL = '/sync/' + name;
|
||||
$(function() {
|
||||
var checkLogId = location.hash.match(/logid=(\d+)/);
|
||||
var logid = checkLogId ? checkLogId[1] : '';
|
||||
@@ -18,7 +19,7 @@
|
||||
return getSyncLog(logid);
|
||||
}
|
||||
$.ajax({
|
||||
url: location.pathname,
|
||||
url: resourceURL,
|
||||
type: 'PUT',
|
||||
dataType: 'json',
|
||||
success: handleSyncSucess,
|
||||
@@ -53,7 +54,7 @@
|
||||
var hasFail = false;
|
||||
function getSyncLog(id) {
|
||||
$.ajax({
|
||||
url: location.pathname + '/log/' + id + '?offset=' + offset,
|
||||
url: resourceURL + '/log/' + id + '?offset=' + offset,
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
|
||||
Reference in New Issue
Block a user