Compare commits

...

14 Commits
master ... 1.x

Author SHA1 Message Date
fengmk2
6bc7d9216d Release 1.7.6 2014-12-09 16:11:10 +08:00
fengmk2
bf2f1a2bf3 fix title xss 2014-12-09 16:10:42 +08:00
dead_horse
278f70c391 Release 1.7.5 2014-11-26 10:19:01 +08:00
Yiyu He
cbfb2debe0 Merge pull request #518 from CatTail/1.x
Fix `Module.add` don't add keyword into `module_keyword` table
2014-11-26 10:17:08 +08:00
zhongchiyu
f366def30c Fix Module.add don't add keyword into module_keyword table 2014-11-26 10:15:37 +08:00
dead_horse
d03b9e159f Release 1.7.4 2014-11-25 12:56:48 +08:00
Yiyu He
63d148c1a5 Merge pull request #516 from CatTail/1.x
Add search package by keyword
2014-11-25 12:54:21 +08:00
zhongchiyu
dbd38ee6e7 Add unit test for searchbykeyword 2014-11-25 12:14:03 +08:00
zhongchiyu
df3a20df26 Add search package by keyword 2014-11-25 11:18:24 +08:00
fengmk2
5bb836381f Release 1.7.3 2014-11-12 16:59:14 +08:00
fengmk2
db73b9a675 fix(sync): should not sync package when maintainers sort change
Closes #500
2014-11-12 16:57:37 +08:00
fengmk2
6ca71e1d8b Release 1.7.2 2014-10-31 14:28:30 +08:00
Yiyu He
ff811ab15e Merge pull request #487 from cnpm/min-sync-interval
feat(sync): add min sync interval time detect
2014-10-31 14:21:39 +08:00
fengmk2
ae1ca1bc32 feat(sync): add min sync interval time detect
Forbidden some guy write `config.syncInterval = 1` to let sync too fast.

Closes #486
2014-10-31 14:18:58 +08:00
9 changed files with 98 additions and 12 deletions

View File

@@ -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
==================

View File

@@ -1059,3 +1059,10 @@ exports.updateTag = function* () {
ok: true
};
};
exports.searchByKeyword = function* () {
var packages = yield Module.searchByKeyword(this.params.keyword, {});
this.body = {
packages: packages
};
};

View File

@@ -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"
}

View File

@@ -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 () {;/*

View File

@@ -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)) {

View File

@@ -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;

View File

@@ -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);
}
/**

View File

@@ -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,7 +184,15 @@ describe('proxy/module.test.js', function () {
Module.getById(result.id, function (err, row) {
should.not.exist(err);
row.package.readme.should.equal(sourcePackage.readme);
done();
// 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();
});
});
});
});

View File

@@ -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 -->