Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bc7d9216d | ||
|
|
bf2f1a2bf3 | ||
|
|
278f70c391 | ||
|
|
cbfb2debe0 | ||
|
|
f366def30c | ||
|
|
d03b9e159f | ||
|
|
63d148c1a5 | ||
|
|
dbd38ee6e7 | ||
|
|
df3a20df26 | ||
|
|
5bb836381f | ||
|
|
db73b9a675 | ||
|
|
6ca71e1d8b | ||
|
|
ff811ab15e | ||
|
|
ae1ca1bc32 |
28
History.md
28
History.md
@@ -1,4 +1,32 @@
|
||||
|
||||
1.7.6 / 2014-12-09
|
||||
==================
|
||||
|
||||
* fix title xss
|
||||
|
||||
1.7.5 / 2014-11-26
|
||||
==================
|
||||
|
||||
* Merge pull request [#518](https://github.com/cnpm/cnpmjs.org/issues/518) from CatTail/1.x
|
||||
* Fix `Module.add` don't add keyword into `module_keyword` table
|
||||
|
||||
1.7.4 / 2014-11-25
|
||||
==================
|
||||
|
||||
* Merge pull request [#516](https://github.com/cnpm/cnpmjs.org/issues/516) from CatTail/1.x
|
||||
* Add unit test for searchbykeyword
|
||||
* Add search package by keyword
|
||||
|
||||
1.7.3 / 2014-11-12
|
||||
==================
|
||||
|
||||
* fix(sync): should not sync package when maintainers sort change
|
||||
|
||||
1.7.2 / 2014-10-31
|
||||
==================
|
||||
|
||||
* feat(sync): add min sync interval time detect
|
||||
|
||||
1.7.1 / 2014-10-15
|
||||
==================
|
||||
|
||||
|
||||
@@ -1059,3 +1059,10 @@ exports.updateTag = function* () {
|
||||
ok: true
|
||||
};
|
||||
};
|
||||
|
||||
exports.searchByKeyword = function* () {
|
||||
var packages = yield Module.searchByKeyword(this.params.keyword, {});
|
||||
this.body = {
|
||||
packages: packages
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cnpmjs.org",
|
||||
"version": "1.7.1",
|
||||
"version": "1.7.6",
|
||||
"description": "Private npm registry and web for Enterprise, base on MySQL and Simple Store Service",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@@ -90,5 +90,8 @@
|
||||
"fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)",
|
||||
"dead_horse <dead_horse@qq.com> (http://deadhorse.me)"
|
||||
],
|
||||
"publishConfig": {
|
||||
"tag": "v1"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ exports.add = function (mod, callback) {
|
||||
}
|
||||
|
||||
// add keywords
|
||||
exports.addKeywords(mod, description, words, utility.noop);
|
||||
exports.addKeywords(mod.name, description, words, utility.noop);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -572,6 +572,13 @@ exports.search = function (word, options, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
exports.searchByKeyword = function (keyword, options, callback) {
|
||||
var limit = options.limit || 100;
|
||||
mysql.query(SEARCH_MODULES_BY_KEYWORD_SQL, [ keyword, limit ], function(err, rows) {
|
||||
callback(null, rows);
|
||||
});
|
||||
};
|
||||
|
||||
thunkify(exports);
|
||||
|
||||
var GET_LAST_MODIFIED_MODULE_SQL = multiline(function () {;/*
|
||||
|
||||
@@ -549,13 +549,8 @@ SyncModuleWorker.prototype._sync = function* (name, pkg) {
|
||||
if (!version.maintainers || !version.maintainers[0]) {
|
||||
version.maintainers = pkg.maintainers;
|
||||
}
|
||||
var sourceAuthor = version.maintainers && version.maintainers[0] &&
|
||||
version.maintainers[0].name || exists.author;
|
||||
|
||||
if (exists.package &&
|
||||
exists.package.dist.shasum === version.dist.shasum &&
|
||||
exists.author === sourceAuthor) {
|
||||
// * author make sure equal
|
||||
exists.package.dist.shasum === version.dist.shasum) {
|
||||
// * shasum make sure equal
|
||||
if ((version.publish_time === exists.publish_time) ||
|
||||
(!version.publish_time && exists.publish_time)) {
|
||||
|
||||
@@ -87,6 +87,9 @@ function routes(app) {
|
||||
|
||||
// list all packages of user
|
||||
app.get('/-/by-user/:user', userPackage.list);
|
||||
|
||||
// search package by keyword
|
||||
app.get('/-/by-keyword/:keyword', mod.searchByKeyword);
|
||||
}
|
||||
|
||||
module.exports = routes;
|
||||
|
||||
@@ -58,7 +58,7 @@ var handleSync = co(function *() {
|
||||
var data;
|
||||
var error;
|
||||
try {
|
||||
data = yield *sync();
|
||||
data = yield* sync();
|
||||
} catch (err) {
|
||||
error = err;
|
||||
error.message += ' (sync package error)';
|
||||
@@ -74,7 +74,12 @@ var handleSync = co(function *() {
|
||||
|
||||
if (sync) {
|
||||
handleSync();
|
||||
setInterval(handleSync, ms(config.syncInterval));
|
||||
var syncInterval = ms(config.syncInterval);
|
||||
var minSyncInterval = ms('5m');
|
||||
if (!syncInterval || syncInterval < minSyncInterval) {
|
||||
syncInterval = minSyncInterval;
|
||||
}
|
||||
setInterval(handleSync, syncInterval);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -100,6 +100,36 @@ describe('proxy/module.test.js', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('searchByKeyword()', function () {
|
||||
before(function (done) {
|
||||
Module.addKeywords('bbbb', 'mock bbbbbb', ['aa', 'bb', 'cc'], function (err, results) {
|
||||
should.not.exist(err);
|
||||
results.should.be.an.Array;
|
||||
results.should.length(3);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should search match keywords modules', function(done) {
|
||||
Module.searchByKeyword('aa', {}, function (err, data) {
|
||||
should.not.exist(err);
|
||||
data.length.should.above(0);
|
||||
data.forEach(function (row) {
|
||||
row.should.have.keys('name', 'description');
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return empty array if not match found', function (done) {
|
||||
Module.searchByKeyword('notexistkeyword', {}, function (err, data) {
|
||||
should.not.exist(err);
|
||||
data.should.eql([]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var mockName = 'aa' + Date.now();
|
||||
describe('addKeywords()', function () {
|
||||
it('should add diff keywords to module', function (done) {
|
||||
@@ -154,11 +184,19 @@ describe('proxy/module.test.js', function () {
|
||||
Module.getById(result.id, function (err, row) {
|
||||
should.not.exist(err);
|
||||
row.package.readme.should.equal(sourcePackage.readme);
|
||||
// check if keyword added into module_keyword
|
||||
var keyword = sourcePackage.keywords[0];
|
||||
Module.searchByKeyword(keyword, {}, function(err, pkgs) {
|
||||
var isFound = pkgs.some(function(pkg) {
|
||||
return pkg.name == sourcePackage.name;
|
||||
});
|
||||
isFound.should.be.ok;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('listByAuthor()', function () {
|
||||
it('should return author recent modules', function* () {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title><%- locals.title %></title>
|
||||
<title><%= locals.title %></title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="shortcut icon" href="/favicon.png">
|
||||
<!-- Bootstrap -->
|
||||
|
||||
Reference in New Issue
Block a user