Compare commits

...

119 Commits
1.0.0 ... 1.6.1

Author SHA1 Message Date
fengmk2
abaac6089a Release 1.6.1 2014-10-09 01:15:09 +08:00
fengmk2
e8ba8eadb3 Merge pull request #466 from cnpm/sync-npm-package-maintainers
save npm original package maintainers to npm_module_maintainer table.
2014-10-09 00:46:29 +08:00
fengmk2
20093741eb make test on travis faster 2014-10-09 00:33:50 +08:00
fengmk2
51ddf2cf02 ensure not sync user also has his own package names 2014-10-09 00:24:14 +08:00
fengmk2
26efecd2fc add v1.6.x-upgrade sql 2014-10-09 00:01:50 +08:00
fengmk2
678c85102e save npm original package maintainers to npm_module_maintainer table. fixed #464 2014-10-09 00:01:14 +08:00
fengmk2
439b6663f3 use simple 404 2014-10-08 18:40:23 +08:00
fengmk2
3069179718 fix possible xss on 404 page 2014-10-08 18:29:13 +08:00
fengmk2
f2613edcd5 Release 1.6.0 2014-10-08 11:15:44 +08:00
dead_horse
6e9ceaf844 Merge pull request #463 from cnpm/by-user-api
list user all packages api. fixed #462
2014-10-08 01:06:14 +08:00
fengmk2
188dab4ed8 list user all packages api. fixed #462 2014-10-08 00:53:20 +08:00
dead_horse
5d0d742e85 Merge pull request #461 from cnpm/node-dev
add node-dev: $ make dev
2014-10-04 01:56:15 +08:00
fengmk2
92a828c04d update readme 2014-10-04 00:33:27 +08:00
fengmk2
3c804758e7 add node-dev: $ make dev 2014-10-04 00:26:08 +08:00
fengmk2
683b2e3640 Merge pull request #459 from cnpm/sync
always start sync worker
2014-10-03 21:11:39 +08:00
dead_horse
35d445cd11 always start sync worker 2014-10-03 02:06:44 +08:00
fengmk2
45a9e0ff97 Merge pull request #458 from cnpm/nodemailer
update node mailer
2014-10-02 09:14:51 +08:00
dead_horse
dda2f0785c update node mailer 2014-10-02 01:58:43 +08:00
dead_horse
ce02d2f48e update autod 2014-10-02 01:10:03 +08:00
fengmk2
c36523da17 Release 1.5.5 2014-09-25 00:00:46 +08:00
fengmk2
93f33a98cf fix sync in web 2014-09-24 23:44:03 +08:00
dead_horse
c8372f06a8 Merge pull request #454 from cnpm/sync-upstream-on-frist-package
sync upstream only the first package. ...
2014-09-24 23:38:25 +08:00
fengmk2
234e8bf27b sync upstream only the first package. make sync devDependencies optionsal, default is false 2014-09-24 23:34:35 +08:00
fengmk2
dfe56b6222 Merge pull request #453 from cnpm/config
add some comment, default sourceNpmRegistryIsCNpm to true
2014-09-24 23:14:13 +08:00
dead_horse
8548104ee6 add some comment, default sourceNpmRegistryIsCNpm to true 2014-09-24 23:10:13 +08:00
fengmk2
ceeb617f0d Release 1.5.4 2014-09-24 23:04:31 +08:00
fengmk2
91ee61c997 format sync log 2014-09-24 23:04:15 +08:00
fengmk2
1d94ba4e11 Release 1.5.3 2014-09-24 22:23:32 +08:00
dead_horse
5b09d974fb Merge pull request #452 from cnpm/sync-upstream-package
support sync upstream first. fixed #451
2014-09-24 19:54:36 +08:00
fengmk2
763224bbbb support sync upstream first. fixed #451 2014-09-24 19:43:51 +08:00
fengmk2
7b6c757b83 Release 1.5.2 2014-09-24 18:22:36 +08:00
fengmk2
fd915e0c5d support im url on user profile page 2014-09-24 18:21:31 +08:00
dead_horse
fb39eb8c2a Release 1.5.1 2014-09-23 17:15:17 +08:00
dead_horse
f139cccad0 search support case insensitive, close #450 2014-09-23 17:14:03 +08:00
fengmk2
4bb2e6a5d8 Merge pull request #449 from cnpm/sync-in-web
add config._syncInWeb, close #448
2014-09-23 09:20:06 +08:00
dead_horse
4d3c257474 add config._syncInWeb, close #448 2014-09-23 02:02:56 +08:00
dead_horse
b990bd9cf1 Merge pull request #445 from cnpm/show-maintainers-when-publish-fail
show maintainers when publish 403. fixed #430
2014-09-16 01:13:21 +08:00
fengmk2
917b407d1e show maintainers when publish 403. fixed #430 2014-09-16 01:05:40 +08:00
dead_horse
774fd44b12 Merge pull request #444 from cnpm/no-attachment-for-html
no attachment for html
2014-09-15 17:12:45 +08:00
fengmk2
a6b67f5453 no attachment for html 2014-09-15 17:10:49 +08:00
fengmk2
1e56c77deb Release 1.5.0 2014-09-15 16:50:20 +08:00
dead_horse
e1e6b6b674 Merge pull request #441 from cnpm/dist-sync-document
dist sync document too. fixed #420
2014-09-14 18:30:27 +08:00
fengmk2
615d16165c dist sync document too. fixed #420 2014-09-13 00:33:20 +08:00
fengmk2
8986503005 Release 1.4.4 2014-09-12 15:37:57 +08:00
fengmk2
4b5a49b626 badge version support 1.0.0-beta1. fixed #440 2014-09-12 11:54:58 +08:00
fengmk2
fce0876295 Release 1.4.3 2014-09-09 12:06:53 +08:00
fengmk2
9df81764a9 alias /:name/-/:file to /:name/download/:file. fixed #439 2014-09-09 12:06:05 +08:00
dead_horse
4801f15768 Release 1.4.2 2014-09-03 13:12:53 +08:00
dead_horse
d24422fdba change default source registry to taobao's registry 2014-09-03 13:11:55 +08:00
dead_horse
835f898eb3 Merge pull request #435 from cnpm/bluebird
add bluebird
2014-09-03 10:17:02 +08:00
fengmk2
2a3a0436e7 add bluebird 2014-09-03 10:12:05 +08:00
dead_horse
0a782ea014 bump fs-cnpm 2014-09-03 09:38:54 +08:00
dead_horse
3813827d77 Merge pull request #434 from cnpm/agent-stat
show agent sockets stat. fixed #433
2014-09-03 09:35:51 +08:00
fengmk2
264544c780 show agent sockets stat. fixed #433 2014-09-03 00:41:04 +08:00
dead_horse
416afb2e9a update readme 2014-09-02 20:51:25 +08:00
dead_horse
fe15eb78e9 remove pic in readme 2014-09-02 20:50:47 +08:00
dead_horse
64d2facef3 Release 1.4.1 2014-08-20 23:19:52 +08:00
dead_horse
d677e804b5 Merge branch 'master' of github.com:cnpm/cnpmjs.org 2014-08-20 23:18:35 +08:00
dead_horse
f4dae42589 fix login error status 2014-08-20 23:18:24 +08:00
fengmk2
71452f692e Release 1.4.0 2014-08-20 10:01:48 +08:00
dead_horse
c24526d7ff Merge pull request #429 from cnpm/badge
Badge version image
2014-08-20 09:56:48 +08:00
fengmk2
43dcd4b4f1 update readme for badge url desc 2014-08-20 09:53:37 +08:00
fengmk2
ff90c0f238 different version, different color badge 2014-08-20 09:47:06 +08:00
fengmk2
f85752e4bc add badge on package page 2014-08-20 00:25:26 +08:00
fengmk2
4b20c13a4f add version badge. fixed #427 2014-08-20 00:07:53 +08:00
dead_horse
ef61605e0c add download and node version badge 2014-08-18 21:32:52 +08:00
dead_horse
a5291d95dd Release 1.3.2 2014-08-18 11:45:25 +08:00
dead_horse
9de10e791c remove unused eventproxy 2014-08-18 11:27:25 +08:00
dead_horse
1162ed95b0 add custom config in tools/sync_not_exist.js 2014-08-18 11:25:09 +08:00
dead_horse
6cdbc0b058 Release 1.3.1 2014-08-18 10:15:49 +08:00
dead_horse
dc7239637d add sync not exist tools, close #424 2014-08-18 10:14:38 +08:00
dead_horse
b735c9c15c use gittip instand of alipay. close #425 2014-08-17 22:21:59 +08:00
dead_horse
417e19a330 update registry api doc 2014-08-16 16:01:06 +08:00
dead_horse
40ab0929e1 Release 1.3.0 2014-08-11 11:46:58 +08:00
dead_horse
6dabe60839 ignore config/config.js 2014-08-11 11:46:29 +08:00
fengmk2
2680512c71 Merge pull request #421 from cnpm/qn-cnpm
use simple fs storage in develop env
2014-08-10 08:59:40 +08:00
dead_horse
f444566a23 fix test case 2014-08-10 01:57:58 +08:00
dead_horse
99cb110ee2 use fs-cnpm 2014-08-10 01:27:08 +08:00
dead_horse
536704705c fix test 2014-08-09 21:32:36 +08:00
dead_horse
d919a81dae use qn-cnpm 2014-08-09 21:17:59 +08:00
dead_horse
fe8100ea30 bump cfork 2014-08-09 20:16:56 +08:00
dead_horse
764c32646e Release 1.2.2 2014-08-08 10:47:50 +08:00
dead_horse
dea16e72de bump koa 2014-08-08 10:45:50 +08:00
fengmk2
7f951a6c5d Release 1.2.1 2014-08-07 18:19:08 +08:00
fengmk2
a1f2bc87b7 Merge pull request #418 from cnpm/undeprecate
deprecated bug fix and support undeprecate
2014-08-07 18:18:31 +08:00
fengmk2
706a5e053b deprecated bug fix and support undeprecate 2014-08-07 18:06:32 +08:00
fengmk2
eddc1a1bb9 Release 1.2.0 2014-08-07 17:27:39 +08:00
dead_horse
6e5abe44b9 Merge pull request #417 from cnpm/deprecate-api
Deprecate API
2014-08-07 17:20:30 +08:00
fengmk2
e6484e7e7b show deprecated message 2014-08-07 17:18:44 +08:00
fengmk2
7a88fa49d2 Sync deprecated field if it missing 2014-08-07 16:48:41 +08:00
fengmk2
82189bd393 Support $ cnpm deprecate [pkgname]@[version] "message". fixed #415 2014-08-07 16:24:35 +08:00
fengmk2
7834f44901 Release 1.1.0 2014-08-07 10:18:39 +08:00
dead_horse
463cf44133 Merge pull request #414 from cnpm/add-maintainers-bugfix
Add user to maintainers when publish. fixed #395
2014-08-07 09:21:17 +08:00
fengmk2
e6bb4b76c2 Add user to maintainers when publish. fixed #395
Also remove the maintainers when package unpublish.
2014-08-07 00:32:10 +08:00
fengmk2
b86d8eb110 List all npm registry api. close #413 2014-08-06 00:49:28 +08:00
dead_horse
070e72b571 Merge pull request #412 from cnpm/limit-list-since
limit list since
2014-08-05 09:24:16 +08:00
fengmk2
6e6f87c147 limit list since 2014-08-05 01:51:19 +08:00
dead_horse
bc9306eda7 Merge pull request #411 from cnpm/deps-change
change deps by "~"
2014-08-04 23:30:02 +08:00
fengmk2
66ea71756c change deps by "~" 2014-08-04 23:25:12 +08:00
dead_horse
0a1fff70cc Merge pull request #409 from cnpm/cfork
use cfork to make sure worker fork and restart
2014-08-04 21:08:05 +08:00
fengmk2
71da60c16f use cfork to make sure worker fork and restart 2014-08-04 18:53:55 +08:00
dead_horse
b5d585988f Merge pull request #405 from cnpm/master-uncaughtException
handle master uncaughtException. fixed #403
2014-08-04 12:27:41 +08:00
fengmk2
758d1d4320 handle master uncaughtException. fixed #403 2014-08-04 12:26:26 +08:00
fengmk2
7b77f09264 Release 1.0.6 2014-08-02 02:13:44 +08:00
fengmk2
7731b44ab4 WTF moment@2.8.0 missing 2014-08-02 02:13:24 +08:00
fengmk2
4bc6998040 Release 1.0.5 2014-08-02 02:04:36 +08:00
fengmk2
0d28fbde54 fix remove tar test cases 2014-08-02 02:03:59 +08:00
fengmk2
660035c1d5 Merge pull request #401 from cnpm/hotfix-unpublish-version
unpublish pkg@version bug hotfix. fixed #400
2014-08-02 01:57:19 +08:00
fengmk2
f21e5a1c07 unpublish pkg@version bug hotfix. fixed #400 2014-08-02 01:56:32 +08:00
fengmk2
4d20d91965 Release 1.0.4 2014-08-01 18:40:45 +08:00
fengmk2
a3e33850fc hotfix #399 use not exists 2014-08-01 18:39:53 +08:00
fengmk2
d888ef3297 Release 1.0.3 2014-08-01 13:31:54 +08:00
fengmk2
ce4ec7e6e9 Merge pull request #397 from cnpm/list-users-packages
add maintaining packages in user page
2014-08-01 13:19:30 +08:00
dead_horse
fe319b06ba Release 1.0.2 2014-08-01 12:05:54 +08:00
dead_horse
d829600ed0 ~_~ fix response message 2014-08-01 12:05:25 +08:00
dead_horse
4dd59cb300 Release 1.0.1 2014-08-01 12:00:33 +08:00
dead_horse
5ff25474c0 Merge pull request #398 from cnpm/fix-auth
hot fix auth error
2014-08-01 11:58:54 +08:00
dead_horse
6d49a859c6 hot fix auth error 2014-08-01 11:58:23 +08:00
dead_horse
094178c3ca add maintaining packages in user page 2014-08-01 10:47:47 +08:00
67 changed files with 3244 additions and 607 deletions

View File

@@ -19,3 +19,4 @@ coverage/
.DS_Store
config/web_readme.md
.dist/
config/config.js

View File

@@ -1,4 +1,172 @@
1.6.1 / 2014-10-09
==================
* make test on travis faster
* ensure not sync user also has his own package names
* add [v1.6.x-upgrade.sql](https://github.com/cnpm/cnpmjs.org/blob/master/docs/update_sqls/v1.6.x-upgrade.sql)
* save npm original package maintainers to npm_module_maintainer table. fixed #464
* use simple 404
1.6.0 / 2014-10-08
==================
* list user all packages api. fixed #462
* add node-dev: $ make dev
* always start sync worker
* update node mailer
* update autod
1.5.5 / 2014-09-25
==================
* fix sync in web
* sync upstream only the first package. make sync devDependencies optionsal, default is false
* add some comment, default sourceNpmRegistryIsCNpm to true
1.5.4 / 2014-09-24
==================
* format sync log
1.5.3 / 2014-09-24
==================
* support sync upstream first. fixed #451
1.5.2 / 2014-09-24
==================
* support im url on user profile page; update bootstrap to 3.2.0
1.5.1 / 2014-09-23
==================
* search support case insensitive, close [#450](https://github.com/cnpm/cnpmjs.org/issues/450)
* add config._syncInWeb, close [#448](https://github.com/cnpm/cnpmjs.org/issues/448)
* show maintainers when publish 403. fixed [#430](https://github.com/cnpm/cnpmjs.org/issues/430)
* no attachment for html
1.5.0 / 2014-09-15
==================
* dist sync document too. fixed [#420](https://github.com/cnpm/cnpmjs.org/issues/420)
1.4.4 / 2014-09-12
==================
* badge version support 1.0.0-beta1. fixed [#440](https://github.com/cnpm/cnpmjs.org/issues/440)
1.4.3 / 2014-09-09
==================
* alias /:name/-/:file to /:name/download/:file. fixed [#439](https://github.com/cnpm/cnpmjs.org/issues/439)
1.4.2 / 2014-09-03
==================
* change default source registry to taobao's registry
* Merge pull request [#435](https://github.com/cnpm/cnpmjs.org/issues/435) from cnpm/bluebird
* add bluebird
* bump fs-cnpm
* Merge pull request [#434](https://github.com/cnpm/cnpmjs.org/issues/434) from cnpm/agent-stat
* show agent sockets stat. fixed [#433](https://github.com/cnpm/cnpmjs.org/issues/433)
* update readme
* remove pic in readme
1.4.1 / 2014-08-20
==================
* fix login error status
1.4.0 / 2014-08-20
==================
* different version, different color badge, add version badge. fixed [#427](https://github.com/cnpm/cnpmjs.org/issues/427)
* add download and node version badge
1.3.2 / 2014-08-18
==================
* remove unused eventproxy
* add custom config in tools/sync_not_exist.js
1.3.1 / 2014-08-18
==================
* add sync not exist tools, close [#424](https://github.com/cnpm/cnpmjs.org/issues/424)
* use gittip instand of alipay. close [#425](https://github.com/cnpm/cnpmjs.org/issues/425)
* update registry api doc
1.3.0 / 2014-08-11
==================
* ignore config/config.js
* Merge pull request [#421](https://github.com/cnpm/cnpmjs.org/issues/421) from cnpm/qn-cnpm
* fix test case
* use fs-cnpm
* fix test
* use qn-cnpm
* bump cfork
1.2.2 / 2014-08-08
==================
* bump koa
1.2.1 / 2014-08-07
==================
* deprecated bug fix and support undeprecate
1.2.0 / 2014-08-07
==================
* show deprecated message
* Sync deprecated field if it missing
* Support $ cnpm deprecate [pkgname]@[version] "message". fixed [#415](https://github.com/cnpm/cnpmjs.org/issues/415)
1.1.0 / 2014-08-07
==================
* Add user to maintainers when publish. fixed [#395](https://github.com/cnpm/cnpmjs.org/issues/395)
* List all npm registry api. close [#413](https://github.com/cnpm/cnpmjs.org/issues/413)
* limit list since
* change deps by "~"
* use cfork to make sure worker fork and restart
* handle master uncaughtException. fixed [#403](https://github.com/cnpm/cnpmjs.org/issues/403)
1.0.6 / 2014-08-02
==================
* WTF moment@2.8.0 missing
1.0.5 / 2014-08-02
==================
* unpublish pkg@version bug hotfix. fixed [#400](https://github.com/cnpm/cnpmjs.org/issues/400)
1.0.4 / 2014-08-01
==================
* hotfix [#399](https://github.com/cnpm/cnpmjs.org/issues/399) use not exists
1.0.3 / 2014-08-01
==================
* add maintaining packages in user page
1.0.2 / 2014-08-01
==================
* ~_~ fix auth error response message
1.0.1 / 2014-08-01
==================
* Merge pull request [#398](https://github.com/cnpm/cnpmjs.org/issues/398) from cnpm/fix-auth
* hot fix auth error
1.0.0 / 2014-08-01
==================
@@ -27,7 +195,7 @@
* remove session middleware
* add DefaultUserService
* check scopes in module.getAdapt
* test public mode, fix some logic, close #382
* test public mode, fix some logic, close [#382](https://github.com/cnpm/cnpmjs.org/issues/382)
* move scope.js into publishable.js, add forcePublishWithScope
* config.scopes not exist, means do not support scope
* add assert scope middleware
@@ -40,12 +208,12 @@
0.8.6 / 2014-07-23
==================
* show unpublished info on web package page. fixes #381
* show unpublished info on web package page. fixes [#381](https://github.com/cnpm/cnpmjs.org/issues/381)
0.8.5 / 2014-07-22
==================
* Only private package support default scoped. fixed #378
* Only private package support default scoped. fixed [#378](https://github.com/cnpm/cnpmjs.org/issues/378)
0.8.4 / 2014-07-22
==================
@@ -66,20 +234,20 @@
==================
* add more test cases
* support default @org. close #376
* support default @org. close [#376](https://github.com/cnpm/cnpmjs.org/issues/376)
* hotfix redis init error
0.8.0 / 2014-07-21
==================
* support "scoped" packages. close #352
* support "scoped" packages. close [#352](https://github.com/cnpm/cnpmjs.org/issues/352)
* use safe jsonp
* Stop support old publish flow. fix #368
* Stop support old publish flow. fix [#368](https://github.com/cnpm/cnpmjs.org/issues/368)
* update SQLs
* use sync_info and sync_error categories
* add categories to loggers. fix #370
* add categories to loggers. fix [#370](https://github.com/cnpm/cnpmjs.org/issues/370)
* fix get latest tag always not exists bug
* support `npm publish --tag beta`. fix #366
* support `npm publish --tag beta`. fix [#366](https://github.com/cnpm/cnpmjs.org/issues/366)
* use mini-logger and error-formater
0.7.0 / 2014-07-07
@@ -87,7 +255,7 @@
* use module_maintainers on GET /pakcage/:name page
* use new module_maintainers on GET /:name
* admin user should never publish to other user's packages. fix #363
* admin user should never publish to other user's packages. fix [#363](https://github.com/cnpm/cnpmjs.org/issues/363)
* Add a new table for module-maintainers.
* gravatar use https
* support https
@@ -102,8 +270,8 @@
0.6.0 / 2014-06-16
==================
* sync unpublished info. close #353
* Delete not exists versions on sync worker. #353
* sync unpublished info. close [#353](https://github.com/cnpm/cnpmjs.org/issues/353)
* Delete not exists versions on sync worker. [#353](https://github.com/cnpm/cnpmjs.org/issues/353)
0.5.3 / 2014-06-13
==================

View File

@@ -16,6 +16,7 @@ pretest:
@mysql -uroot -e 'CREATE DATABASE cnpmjs_test;'
@mysql -uroot 'cnpmjs_test' < ./docs/db.sql
@mysql -uroot 'cnpmjs_test' -e 'show tables;'
@rm -rf .tmp/dist
test: install pretest
@NODE_ENV=test ./node_modules/.bin/mocha \
@@ -42,10 +43,10 @@ test-cov cov: install pretest
--require ./test/init.js \
$(MOCHA_OPTS) \
$(TESTS)
@./node_modules/.bin/cov coverage
test-travis: install pretest
@NODE_ENV=test node --harmony \
@NODE_ENV=test CNPM_SOURCE_NPM=https://registry.npmjs.org CNPM_SOURCE_NPM_ISCNPM=false \
node --harmony \
node_modules/.bin/istanbul cover --preserve-comments \
./node_modules/.bin/_mocha \
--report lcovonly \
@@ -59,11 +60,18 @@ test-travis: install pretest
$(MOCHA_OPTS) \
$(TESTS)
dev:
@node_modules/.bin/node-dev --harmony dispatch.js
contributors: install
@./node_modules/.bin/contributors -f plain -o AUTHORS
autod: install
@./node_modules/.bin/autod -w -e public,view,docs,backup,coverage -k nodemailer
@./node_modules/.bin/autod -w \
--prefix "~"\
--exclude public,view,docs,backup,coverage \
--dep bluebird \
--devdep mocha,should,istanbul-harmony,jshint
@$(MAKE) install
.PHONY: test

View File

@@ -6,17 +6,23 @@ cnpmjs.org
[![Test coverage][coveralls-image]][coveralls-url]
[![Gittip][gittip-image]][gittip-url]
[![David deps][david-image]][david-url]
[![node version][node-image]][node-url]
[![npm download][download-image]][download-url]
[npm-image]: https://img.shields.io/npm/v/cnpmjs.org.svg?style=flat
[npm-url]: https://npmjs.org/package/cnpmjs.org
[travis-image]: https://img.shields.io/travis/cnpm/cnpmjs.org.svg?style=flat
[npm-image]: http://cnpmjs.org/badge/v/cnpmjs.org.svg?style=flat-square
[npm-url]: http://cnpmjs.org/package/cnpmjs.org
[travis-image]: https://img.shields.io/travis/cnpm/cnpmjs.org.svg?style=flat-square
[travis-url]: https://travis-ci.org/cnpm/cnpmjs.org
[coveralls-image]: https://img.shields.io/coveralls/cnpm/cnpmjs.org.svg?style=flat
[coveralls-image]: https://img.shields.io/coveralls/cnpm/cnpmjs.org.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/cnpm/cnpmjs.org?branch=master
[gittip-image]: https://img.shields.io/gittip/fengmk2.svg?style=flat
[gittip-image]: https://img.shields.io/gittip/fengmk2.svg?style=flat-square
[gittip-url]: https://www.gittip.com/fengmk2/
[david-image]: https://img.shields.io/david/cnpm/cnpmjs.org.svg?style=flat
[david-image]: https://img.shields.io/david/cnpm/cnpmjs.org.svg?style=flat-square
[david-url]: https://david-dm.org/cnpm/cnpmjs.org
[node-image]: https://img.shields.io/badge/node.js-%3E=_0.11-red.svg?style=flat-square
[node-url]: http://nodejs.org/download/
[download-image]: https://img.shields.io/npm/dm/cnpmjs.org.svg?style=flat-square
[download-url]: https://npmjs.org/package/cnpmjs.org
![logo](https://raw.github.com/cnpm/cnpmjs.org/master/logo.png)
@@ -48,6 +54,7 @@ to extend `npm` with more features(`sync` command, [gzip](https://github.com/npm
And it easy to wrap for your own registry which build with `cnpmjs.org`.
* **Compatible with NPM client**: you can use the origin NPM client with `cnpmjs.org`,
only need to change the registry in config. Even include manual synchronization (through `install` command).
* **Version badge**: base on [shields.io](http://shields.io/) ![cnpm-badge](http://cnpmjs.org/badge/v/cnpmjs.org.svg?style=flat-square)
## Getting Start
@@ -56,15 +63,13 @@ only need to change the registry in config. Even include manual synchronization
* Mirror NPM in China: [cnpmjs.org](http://cnpmjs.org)
* cnpm client: [cnpm](https://github.com/cnpm/cnpm), `npm install -g cnpm`
* [How to deploy cnpmjs.org](https://github.com/cnpm/cnpmjs.org/wiki/Deploy)
* [NFS guide](https://github.com/cnpm/cnpmjs.org/wiki/NFS-Guide)
![cnpm](https://docs.google.com/drawings/d/12QeQfGalqjsB77mRnf5Iq5oSXHCIUTvZTwECMonqCmw/pub?w=480&h=360)
* [wiki](https://github.com/cnpm/cnpmjs.org/wiki)
## Develop on your local machine
### Dependencies
* [node](http://nodejs.org) =0.11.12
* [node](http://nodejs.org) >=0.11.12, use `--harmony`
* [mysql](http://dev.mysql.com/downloads/) >= 0.5.0, include `mysqld` and `mysql cli`. I test on `mysql@5.6.16`.
### Start MySQL
@@ -91,8 +96,8 @@ $ make test-cov
# udpate dependencies
$ make autod
# start server
$ node --harmony_generators dispatch.js
# start server with development mode
$ make dev
```
## How to contribute
@@ -104,24 +109,6 @@ $ node --harmony_generators dispatch.js
Tips: make sure your code is following the [node-style-guide](https://github.com/felixge/node-style-guide).
## Authors
```bash
$ git summary
project : cnpmjs.org
repo age : 4 months ago
commits : 472
active : 167 days
files : 104
authors :
272 fengmk2 57.6%
195 dead_horse 41.3%
2 4simple 0.4%
2 Stanley Zheng 0.4%
1 Alsotang 0.2%
```
## License
(The MIT License)

View File

@@ -14,10 +14,30 @@
* Module dependencies.
*/
var utility = require('utility');
var nodemailer = require('nodemailer');
var os = require('os');
var mailConfig = require('../config').mail;
var nodemailer = require('nodemailer');
var utility = require('utility');
var os = require('os');
var smtpConfig;
if (mailConfig.auth) {
// new style
smtpConfig = mailConfig;
} else {
smtpConfig = {
// backward compat
host: mailConfig.host,
port: mailConfig.port,
secure: mailConfig.secure || mailConfig.ssl,
debug: mailConfig.debug,
auth: {
user: mailConfig.user,
pass: mailConfig.pass
}
};
}
var transport = nodemailer.createTransport(smtpConfig);
/**
* Send notice email with mail level and appname.
@@ -51,26 +71,14 @@ LEVELS.forEach(function (level) {
exports.send = function (to, subject, html, callback) {
callback = callback || utility.noop;
var transport = nodemailer.createTransport("SMTP", {
host: mailConfig.host,
port: mailConfig.port,
secureConnection: mailConfig.ssl,
debug: mailConfig.debug,
auth: {
user: mailConfig.user,
pass: mailConfig.pass,
}
});
var message = {
sender: mailConfig.sender,
from: mailConfig.from || mailConfig.sender,
to: to,
subject: subject,
html: html,
};
transport.sendMail(message, function (err, result) {
transport.close();
callback(err, result);
});
};

View File

@@ -15,11 +15,5 @@
*/
var config = require('../config');
var nfs = config.nfs;
if (!nfs) {
// use qnfs by default
nfs = require('./qnfs');
}
module.exports = nfs;
module.exports = config.nfs;

View File

@@ -1,83 +0,0 @@
/*!
* cnpmjs.org - common/qnfs.js
*
* Copyright(c) cnpmjs.org and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
*/
'use strict';
/**
* Module dependencies.
*/
var thunkify = require('thunkify-wrap');
var qn = require('qn');
var fs = require('fs');
var config = require('../config');
var client = qn.create(config.qn);
thunkify(client, ['delete', 'uploadFile', 'upload', 'download']);
exports._client = client;
/**
* Upload file
*
* @param {String} filepath
* @param {Object} options
* - {String} key
* - {Number} size
*/
exports.upload = function *(filepath, options) {
try {
yield client.delete(options.key);
} catch (err) {
// ignore error here
}
var res = yield client.uploadFile(filepath, {
key: options.key,
size: options.size
});
var url = res && res[0] ? res[0].url : '';
return { url: url };
};
exports.uploadBuffer = function *(buf, options) {
try {
yield client.delete(options.key);
} catch (err) {
// ignore error here
}
var res = yield client.upload(buf, {key: options.key});
var url = res && res[0] ? res[0].url : '';
return { url: url };
};
exports.url = function (key) {
return client.resourceURL(key);
};
exports.download = function* (key, filepath, options) {
var writeStream = fs.createWriteStream(filepath);
yield client.download(key, {
timeout: options.timeout,
writeStream: writeStream
});
};
exports.remove = function *(key) {
try {
return yield client.delete(key);
} catch (err) {
if (err.name === 'QiniuFileNotExistsError') {
return;
}
throw err;
}
};

85
common/urllib.js Normal file
View File

@@ -0,0 +1,85 @@
/**!
* cnpmjs.org - common/urllib.js
*
* Copyright(c) fengmk2 and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
*/
'use strict';
/**
* Module dependencies.
*/
var urllib = require('urllib');
var HttpAgent = require('agentkeepalive');
var HttpsAgent = require('agentkeepalive').HttpsAgent;
var httpAgent = new HttpAgent({
timeout: 0,
keepAliveTimeout: 15000
});
var httpsAgent = new HttpsAgent({
timeout: 0,
keepAliveTimeout: 15000
});
var client = urllib.create({
agent: httpAgent,
httpsAgent: httpsAgent
});
module.exports = client;
module.exports.USER_AGENT = urllib.USER_AGENT;
function startMonitor() {
var statInterval = 60000;
var agents = [
['httpAgent', httpAgent],
['httpsAgent', httpsAgent]
];
function agentStat() {
for (var i = 0; i < agents.length; i++) {
var type = agents[i][0];
var agent = agents[i][1];
var rate = '0';
if (agent.createSocketCount > 0) {
rate = (agent.requestCount / agent.createSocketCount).toFixed(0);
}
console.info('[%s] socket: %d created, %d close, %d timeout, request: %d requests, %s req/socket',
type,
agent.createSocketCount,
agent.closeSocketCount,
agent.timeoutSocketCount,
agent.requestCount,
rate
);
var name;
for (name in agent.sockets) {
console.info('working sockets %s: %d', name, agent.sockets[name].length);
}
for (name in agent.freeSockets) {
console.info('free sockets %s: %d', name, agent.freeSockets[name].length);
}
for (name in agent.requests) {
console.info('pedding requests %s: %d', name, agent.requests[name].length);
}
if (agent.requestCount >= 100000000) {
agent.requestCount = 0;
agent.createSocketCount = 0;
agent.closeSocketCount = 0;
agent.timeoutSocketCount = 0;
}
}
}
agentStat();
return setInterval(agentStat, statInterval);
}
startMonitor();

View File

@@ -27,7 +27,6 @@ var version = require('../package.json').version;
var root = path.dirname(__dirname);
var config = {
version: version,
/**
@@ -78,20 +77,30 @@ var config = {
fengmk2: 'fengmk2@gmail.com',
admin: 'admin@cnpmjs.org',
dead_horse: 'dead_horse@qq.com',
cnpmjstest10: 'cnpmjstest10@cnpmjs.org',
},
// email notification for errors
// check https://github.com/andris9/Nodemailer for more informations
mail: {
appname: 'cnpmjs.org',
sender: 'cnpmjs.org mail sender <adderss@gmail.com>',
host: 'smtp.gmail.com',
port: 465,
user: 'address@gmail.com',
pass: 'your password',
ssl: true,
debug: false
from: 'cnpmjs.org mail sender <adderss@gmail.com>',
service: 'gmail',
auth: {
user: 'address@gmail.com',
pass: 'your password'
}
},
// forward Compat with old style
// mail: {
// appname: 'cnpmjs.org',
// sender: 'cnpmjs.org mail sender <adderss@gmail.com>',
// host: 'smtp.gmail.com',
// port: 465,
// user: 'address@gmail.com',
// pass: 'your password',
// ssl: true,
// debug: false
// },
logoURL: '//ww4.sinaimg.cn/large/69c1d4acgw1ebfly5kjlij208202oglr.jpg', // cnpm logo image url
@@ -126,19 +135,14 @@ var config = {
// use for koa-limit module as storage
redis: null,
// package tarball store in qn by default
// qiniu cdn: http://www.qiniu.com/, it free for dev.
qn: {
accessKey: "5UyUq-l6jsWqZMU6tuQ85Msehrs3Dr58G-mCZ9rE",
secretKey: "YaRsPKiYm4nGUt8mdz2QxeV5Q_yaUzVxagRuWTfM",
bucket: "qiniu-sdk-test",
domain: "http://qiniu-sdk-test.qiniudn.com",
},
// package tarball store in local filesystem by default
nfs: require('fs-cnpm')({
dir: path.join(root, '.tmp', 'dist')
}),
// registry url name
registryHost: 'r.cnpmjs.org',
/**
* registry mode config
*/
@@ -175,8 +179,20 @@ var config = {
disturl: 'http://nodejs.org/dist',
syncDist: false,
// sync source
sourceNpmRegistry: 'http://registry.npmjs.org',
// the official npm registry
// cnpm wont directly sync from this one
// but sometimes will request it for some package infomations
// please don't change it if not necessary
officialNpmRegistry: 'https://registry.npmjs.org',
// sync source, upstream registry
// If you want to directly sync from official npm's registry
// please drop them an email first
sourceNpmRegistry: 'http://registry.npm.taobao.org',
// upstream registry is base on cnpm/cnpmjs.org or not
// if your upstream is official npm registry, please turn it off
sourceNpmRegistryIsCNpm: true,
// if install return 404, try to sync from source registry
syncByInstall: true,
@@ -190,6 +206,12 @@ var config = {
syncConcurrency: 1,
// sync interval, default is 10 minutes
syncInterval: '10m',
// sync devDependencies or not, default is false
syncDevDependencies: false,
// badge subject on http://shields.io/
badgeSubject: 'cnpm',
};
// load config/config.js, everything in config.js will cover the same key in index.js

View File

@@ -24,9 +24,9 @@ exports.total = function (name, callback) {
name = null;
}
var end = moment();
var start = end.clone().subtract('months', 1).startOf('month');
var lastday = end.clone().subtract('days', 1).format('YYYY-MM-DD');
var lastweekStart = end.clone().subtract('weeks', 1).startOf('week');
var start = end.clone().subtract(1, 'months').startOf('month');
var lastday = end.clone().subtract(1, 'days').format('YYYY-MM-DD');
var lastweekStart = end.clone().subtract(1, 'weeks').startOf('week');
var lastweekEnd = lastweekStart.clone().endOf('week').format('YYYY-MM-DD');
var lastmonthEnd = start.clone().endOf('month').format('YYYY-MM-DD');
var thismonthStart = end.clone().startOf('month').format('YYYY-MM-DD');

View File

@@ -0,0 +1,60 @@
/**!
* cnpmjs.org - controllers/registry/deprecate.js
*
* Copyright(c) fengmk2 and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
*/
'use strict';
/**
* Module dependencies.
*/
var Module = require('../../proxy/module');
module.exports = deprecateVersions;
/**
* @see https://github.com/cnpm/cnpmjs.org/issues/415
*/
function* deprecateVersions(next) {
var body = this.request.body;
var name = this.params.name || this.params[0];
var tasks = [];
for (var version in body.versions) {
tasks.push(Module.get(name, version));
}
var rs = yield tasks;
var updateTasks = [];
for (var i = 0; i < rs.length; i++) {
var row = rs[i];
if (!row) {
// some version not exists
this.status = 400;
this.body = {
error: 'version_error',
reason: 'Some versions: ' + JSON.stringify(Object.keys(body.versions)) + ' not found'
};
return;
}
var data = body.versions[row.package.version];
if (typeof data.deprecated === 'string') {
row.package.deprecated = data.deprecated;
updateTasks.push(Module.updatePackage(row.id, row.package));
}
}
yield updateTasks;
// update last modified
yield* Module.updateLastModified(name);
this.status = 201;
this.body = {
ok: true
};
}

View File

@@ -41,6 +41,8 @@ var ModuleUnpublished = require('../../proxy/module_unpublished');
var packageService = require('../../services/package');
var UserService = require('../../services/user');
var downloadAsReadStream = require('../utils').downloadAsReadStream;
var deprecateVersions = require('./deprecate');
var npm = require('../../proxy/npm');
/**
* show all version of a module
@@ -143,13 +145,29 @@ exports.show = function* (next) {
};
return;
}
var result = yield SyncModuleWorker.sync(name, 'sync-by-install');
this.body = result.pkg;
this.status = result.ok ? 200 : (result.statusCode || 500);
// start sync
var logId = yield* SyncModuleWorker.sync(name, 'sync-by-install');
debug('start sync %s, get log id %s', name, logId);
// rty to get package from official registry
var r = yield npm.request('/' + name, {
registry: config.officialNpmRegistry
});
if (r.statusCode !== 200) {
debug('requet from officialNpmRegistry response %s', r.statusCode);
this.status = 404;
this.body = {
error: 'not_found',
reason: 'document not found'
}
return;
}
this.body = r.data;
return;
}
var nextMod = null;
var latestMod = null;
var readme = null;
// set tags
@@ -166,22 +184,19 @@ exports.show = function* (next) {
var createdTime = null;
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
if (row.version === 'next') {
nextMod = row;
continue;
}
var pkg = row.package;
common.setDownloadURL(pkg, this);
pkg._cnpm_publish_time = row.publish_time;
versions[pkg.version] = pkg;
var t = times[pkg.version] = row.publish_time ? new Date(row.publish_time) : row.gmt_modified;
if ((!distTags.latest && !latestMod) || distTags.latest === row.version) {
if ((!distTags.latest && !latestMod) || distTags.latest === pkg.version) {
latestMod = row;
readme = pkg.readme;
}
delete pkg.readme;
if (maintainers.length > 0) {
// TODO: need to use newer maintainers
pkg.maintainers = maintainers;
}
@@ -208,21 +223,13 @@ exports.show = function* (next) {
}
if (!latestMod) {
latestMod = nextMod || rows[0];
}
if (!nextMod) {
nextMod = latestMod;
}
var rev = '';
if (nextMod) {
rev = String(nextMod.id);
latestMod = rows[0];
}
var rev = String(latestMod.id);
var pkg = latestMod.package;
if (tags.length === 0 && pkg.version !== 'next') {
if (tags.length === 0) {
// some sync error reason, will cause tags missing
// set latest tag at least
distTags.latest = pkg.version;
@@ -303,17 +310,26 @@ exports.get = function* (next) {
return;
}
var result = yield SyncModuleWorker.sync(name, 'sync-by-install');
var pkg = result.pkg && result.pkg.versions[version];
if (!pkg) {
// start sync
var logId = yield* SyncModuleWorker.sync(name, 'sync-by-install');
debug('start sync %s, get log id %s', name, logId);
// rty to get package from official registry
var r = yield npm.request('/' + name + '/' + version, {
registry: config.officialNpmRegistry
});
if (r.statusCode !== 200) {
debug('requet from officialNpmRegistry response %s', r.statusCode);
this.status = 404;
this.body = {
error: 'not exist',
reason: 'version not found: ' + version
};
}
return;
}
this.body = pkg;
this.body = r.data;
};
var _downloads = {};
@@ -344,7 +360,7 @@ exports.download = function *(next) {
var dist = row.package.dist;
if (!dist.key) {
debug('get tarball by 302');
debug('get tarball by 302, url: %s', dist.tarball || url);
this.status = 302;
this.set('Location', dist.tarball || url);
_downloads[name] = (_downloads[name] || 0) + 1;
@@ -362,7 +378,7 @@ exports.download = function *(next) {
this.length = dist.size;
}
this.type = mime.lookup(dist.key);
this.attachment = filename;
this.attachment(filename);
this.etag = dist.shasum;
this.body = yield* downloadAsReadStream(dist.key);
@@ -438,26 +454,59 @@ exports.addPackageAndDist = function *(next) {
// { content_type: 'application/octet-stream',
// data: 'H4sIAAAAA
// length: 9883
var pkg = this.request.body;
var username = this.user.name;
var name = this.params.name || this.params[0];
var filename = Object.keys(pkg._attachments || {})[0];
var version = Object.keys(pkg.versions || {})[0];
if (!version || !filename) {
if (!version) {
this.status = 400;
this.body = {
error: 'version_error',
reason: 'filename or version not found, filename: ' + filename + ', version: ' + version
reason: 'version ' + version + ' not found'
};
return;
}
// check maintainers
var result = yield* packageService.authMaintainer(name, username);
if (!result.isMaintainer) {
this.status = 403;
this.body = {
error: 'forbidden user',
reason: username + ' not authorized to modify ' + name +
', please contact maintainers: ' + result.maintainers.join(', ')
};
return;
}
if (!filename) {
var hasDeprecated = false;
for (var v in pkg.versions) {
var row = pkg.versions[v];
if (typeof row.deprecated === 'string') {
hasDeprecated = true;
break;
}
}
if (hasDeprecated) {
return yield* deprecateVersions.call(this, next);
}
this.status = 400;
this.body = {
error: 'filename_error',
reason: 'filename ' + filename + ' not found'
};
return;
}
var attachment = pkg._attachments[filename];
var versionPackage = pkg.versions[version];
var maintainers = versionPackage.maintainers;
// should never happened in normal request
if (!versionPackage.maintainers) {
if (!maintainers) {
this.status = 400;
this.body = {
error: 'maintainers error',
@@ -471,7 +520,7 @@ exports.addPackageAndDist = function *(next) {
// make sure user in auth is in maintainers
// should never happened in normal request
var m = versionPackage.maintainers.filter(function (maintainer) {
var m = maintainers.filter(function (maintainer) {
return maintainer.name === username;
});
if (!m.length) {
@@ -513,17 +562,6 @@ exports.addPackageAndDist = function *(next) {
return;
}
// check maintainers
var isMaintainer = yield* packageService.isMaintainer(name, username);
if (!isMaintainer) {
this.status = 403;
this.body = {
error: 'forbidden user',
reason: username + ' not authorized to modify ' + name
};
return;
}
// upload attachment
var tarballBuffer;
tarballBuffer = new Buffer(attachment.data, 'base64');
@@ -592,6 +630,11 @@ exports.addPackageAndDist = function *(next) {
});
}
// ensure maintainers exists
yield* packageService.addMaintainers(name, maintainers.map(function (item) {
return item.name;
}));
this.status = 201;
this.body = {
ok: true,
@@ -747,7 +790,7 @@ exports.removeWithVersions = function* (next) {
debug('remove versions: %j, remain versions: %j', removeVersions, remainVersions);
// step 4: remove all the versions which need to remove
yield Module.removeByNameAndVersions(name, removeVersions);
// let removeTar do remove versions from module table
var tags = yield Module.listTags(name);
var removeTags = [];
@@ -785,20 +828,24 @@ exports.removeTar = function* (next) {
var name = this.params.name || this.params[0];
var filename = this.params.filename || this.params[1];
var id = Number(this.params.rev || this.params[2]);
debug('remove tarball with filename: %s, id: %s', filename, id);
// cnpmjs.org-2.0.0.tgz
var version = filename.split(name + '-')[1];
if (version) {
// 2.0.0.tgz
version = version.substring(0, version.lastIndexOf('.tgz'));
}
if (!version) {
return yield* next;
}
debug('remove tarball with filename: %s, version: %s, revert to => rev id: %s', filename, version, id);
var username = this.user.name;
if (isNaN(id)) {
return yield* next;
}
var mod = yield Module.getById(id);
if (!mod || mod.name !== name) {
return yield* next;
}
var isMaintainer = yield* packageService.isMaintainer(name, username);
if (!isMaintainer && !this.user.isAdmin) {
this.status = 403;
this.body = {
@@ -807,9 +854,33 @@ exports.removeTar = function* (next) {
};
return;
}
var key = mod.package.dist && mod.package.dist.key;
var rs = yield [
Module.getById(id),
Module.get(name, version),
];
var revertTo = rs[0];
var mod = rs[1]; // module need to delete
if (!mod || mod.name !== name) {
return yield* next;
}
var key = mod.package && mod.package.dist && mod.package.dist.key;
key = key || common.getCDNKey(mod.name, filename);
yield nfs.remove(key);
if (revertTo && revertTo.package) {
debug('removing key: %s from nfs, revert to %s@%s', key, revertTo.name, revertTo.package.version);
} else {
debug('removing key: %s from nfs, no revert mod', key);
}
try {
yield nfs.remove(key);
} catch (err) {
logger.error(err);
}
// remove version from table
yield Module.removeByNameAndVersions(name, [version]);
debug('removed %s@%s', name, version);
this.body = { ok: true };
};
@@ -858,6 +929,9 @@ exports.removeAll = function* (next) {
}
}
// remove the maintainers
yield* packageService.removeAllMaintainers(name);
this.body = { ok: true };
};
@@ -894,6 +968,8 @@ exports.listAllModules = function *() {
this.body = result;
};
var A_WEEK_MS = 3600000 * 24 * 7;
exports.listAllModulesSince = function *() {
var query = this.query || {};
if (query.stale !== 'update_after') {
@@ -908,6 +984,11 @@ exports.listAllModulesSince = function *() {
debug('list all modules from %s', query.startkey);
var startkey = Number(query.startkey) || 0;
var updated = Date.now();
if (updated - startkey > A_WEEK_MS) {
startkey = updated - A_WEEK_MS;
console.warn('[%s] list modules since time out of range: query: %j, ip: %s',
Date(), query, this.ip);
}
var mods = yield Module.listSince(startkey);
var result = { _updated: updated };
mods.forEach(function (mod) {

View File

@@ -214,6 +214,22 @@ exports.add = function* () {
};
// logined before update, no need to auth user again
// { name: 'admin',
// password: '123123',
// email: 'fengmk2@gmail.com',
// _id: 'org.couchdb.user:admin',
// type: 'user',
// roles: [],
// date: '2014-08-05T16:08:22.645Z',
// _rev: '1-1a18c3d73ba42e863523a399ff3304d8',
// _cnpm_meta:
// { id: 14,
// npm_user: false,
// custom_user: false,
// gmt_create: '2014-08-05T15:46:58.000Z',
// gmt_modified: '2014-08-05T15:46:58.000Z',
// admin: true,
// scopes: [ '@cnpm', '@cnpmtest' ] } }
exports.update = function *(next) {
var name = this.params.name;
var rev = this.params.rev;

View File

@@ -0,0 +1,70 @@
/**!
* cnpmjs.org - controllers/registry/user_package.js
*
* Copyright(c) fengmk2 and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
*/
'use strict';
/**
* Module dependencies.
*/
var Module = require('../../proxy/module');
var NpmModuleMaintainer = require('../../proxy/npm_module_maintainer');
exports.list = function* () {
var users = this.params.user.split('|');
if (users.length > 20) {
this.status = 400;
this.body = {
error: 'bad_request',
reason: 'reach max user names limit, must <= 20 user names'
};
return;
}
var firstUser = users[0];
if (!firstUser) {
// params.user = '|'
this.body = {};
return;
}
var data = {};
var r = yield [
NpmModuleMaintainer.listByUsers(users),
// get the first user module by author field
Module.listNamesByAuthor(firstUser),
];
var rows = r[0];
var firstUserModuleNames = r[1];
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
if (data[row.user]) {
data[row.user].push(row.name);
} else {
data[row.user] = [row.name];
}
}
if (firstUserModuleNames.length > 0) {
if (!data[firstUser]) {
data[firstUser] = firstUserModuleNames;
} else {
var items = data[firstUser];
for (var i = 0; i < firstUserModuleNames.length; i++) {
var name = firstUserModuleNames[i];
if (items.indexOf(name) === -1) {
items.push(name);
}
}
}
}
this.body = data;
};

View File

@@ -38,27 +38,13 @@ exports.sync = function* () {
noDep: noDep,
};
var result = yield SyncModuleWorker.sync(name, username, options);
debug('sync %s got %j', name, result);
var logId = yield SyncModuleWorker.sync(name, username, options);
debug('sync %s got log id %j', name, logId);
// friendly 404 reason info
if (result.statusCode === 404) {
this.status = 404;
this.body = {
ok: false,
reason: 'can not found ' + name + ' in the source registry'
};
return;
}
if (!result.ok) {
this.status = result.statusCode || 500;
this.body = result.pkg;
return;
}
this.status = 201;
this.body = {
ok: true,
logId: result.logId
logId: logId
};
};

View File

@@ -32,7 +32,7 @@ exports.show = function *() {
total.instance_start_time = startTime;
total.node_version = process.version;
total.app_version = version;
total.donate = 'https://me.alipay.com/imk2';
total.donate = 'https://www.gittip.com/fengmk2';
total.sync_model = config.syncModel;
this.body = total;

49
controllers/web/badge.js Normal file
View File

@@ -0,0 +1,49 @@
/**!
* cnpmjs.org - controllers/web/badge.js
*
* Copyright(c) fengmk2 and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
*/
'use strict';
/**
* Module dependencies.
*/
var config = require('../../config');
var Module = require('../../proxy/module');
exports.version = function* (next) {
var color = 'lightgrey';
var version = 'invalid';
var name = this.params[0];
var latestTag = yield* Module.getTag(name, 'latest');
if (latestTag) {
version = latestTag.version;
if (/^0\.0\./.test(version)) {
// <0.1.0 & >=0.0.0
color = 'red';
} else if (/^0\./.test(version)) {
// <1.0.0 & >=0.1.0
color = 'green';
} else {
// >=1.0.0
color = 'blue';
}
}
var subject = config.badgeSubject.replace(/\-/g, '--');
version = version.replace(/\-/g, '--');
var url = 'https://img.shields.io/badge/' + subject + '-' + version + '-' + color + '.svg';
if (this.querystring) {
url += '?' + this.querystring;
} else {
url += '?style=flat-square';
}
this.redirect(url);
};

View File

@@ -16,6 +16,7 @@
var debug = require('debug')('cnpmjs.org:controllers:web:dist');
var mime = require('mime');
var urlparse = require('url').parse;
var Dist = require('../../proxy/dist');
var config = require('../../config');
var downloadAsReadStream = require('../utils').downloadAsReadStream;
@@ -61,7 +62,7 @@ exports.list = function* (next) {
});
};
function* download(next) {
function* download(next) {
var fullname = this.params[0];
var info = yield* Dist.getfile(fullname);
debug('download %s got %j', fullname, info);
@@ -69,17 +70,31 @@ exports.list = function* (next) {
return yield* next;
}
if (/\.(html|js|css|json|txt)$/.test(fullname)) {
if (info.url.indexOf('http') === 0) {
info.url = urlparse(info.url).path;
}
return yield* pipe.call(this, info, false);
}
if (info.url.indexOf('http') === 0) {
return this.redirect(info.url);
}
yield* pipe.call(this, info, true);
}
function* pipe(info, attachment) {
debug('pipe %j, attachment: %s', info, attachment);
// download it from nfs
if (typeof info.size === 'number') {
if (typeof info.size === 'number' && info.size > 0) {
this.length = info.size;
}
this.type = mime.lookup(info.url);
this.attachment = info.name;
this.etag = info.sha1;
if (attachment) {
this.attachment(info.name);
}
if (info.sha1) {
this.etag = info.sha1;
}
this.body = yield* downloadAsReadStream(info.url);
}

View File

@@ -161,6 +161,41 @@ exports.display = function* (next) {
pkg.name = orginalName;
}
// pkg.engines = {
// "python": ">= 0.11.9",
// "node": ">= 0.11.9",
// "node1": ">= 0.8.9",
// "node2": ">= 0.10.9",
// "node3": ">= 0.6.9",
// };
if (pkg.engines) {
for (var k in pkg.engines) {
var engine = String(pkg.engines[k] || '').trim();
var color = 'blue';
if (k.indexOf('node') === 0) {
color = 'yellowgreen';
var version = /(\d+\.\d+\.\d+)/.exec(engine);
if (version) {
version = version[0];
if (/^0\.11\.\d+/.test(version)) {
color = 'red';
} else if (/^0\.10\./.test(version) ||
/^0\.12\./.test(version) ||
/^0\.14\./.test(version) ||
/^[^0]+\./.test(version)) {
color = 'brightgreen';
}
}
}
pkg.engines[k] = {
version: engine,
title: k + ': ' + engine,
badgeURL: 'https://img.shields.io/badge/' + encodeURIComponent(k) +
'-' + encodeURIComponent(engine) + '-' + color + '.svg?style=flat-square',
};
}
}
yield this.render('package', {
title: 'Package - ' + pkg.name,
package: pkg,
@@ -238,7 +273,7 @@ exports.displaySync = function* (next) {
var name = this.params.name || this.params[0] || this.query.name;
yield this.render('sync', {
name: name,
title: 'Sync - ' + name
title: 'Sync - ' + name,
});
};

View File

@@ -44,10 +44,12 @@ exports.display = function* (next) {
return yield* next;
}
user = user || {};
var data = {
name: name,
email: user && user.email,
json: user && user.json || {}
email: user.email,
json: user.json || {}
};
if (data.json.login) {
@@ -65,6 +67,7 @@ exports.display = function* (next) {
avatar: json.avatar_url,
fullname: json.name || json.login,
homepage: json.html_url,
im: json.im_url
};
}
@@ -72,7 +75,7 @@ exports.display = function* (next) {
title: 'User - ' + name,
packages: packages,
user: data,
lastModified: user.gmt_modified,
lastModified: user && user.gmt_modified,
isAdmin: isAdmin,
scopes: scopes
});

View File

@@ -18,6 +18,7 @@
var path = require('path');
var util = require('util');
var cluster = require('cluster');
var cfork = require('cfork');
var config = require('./config');
var workerPath = path.join(__dirname, 'worker.js');
var childProcess = require('child_process');
@@ -36,32 +37,21 @@ if (config.enableCluster) {
}
function forkWorker() {
cluster.setupMaster({
exec: workerPath
});
cluster.on('fork', function (worker) {
cfork({
exec: workerPath,
count: config.numCPUs,
}).on('fork', function (worker) {
console.log('[%s] [worker:%d] new worker start', Date(), worker.process.pid);
});
cluster.on('disconnect', function (worker) {
var w = cluster.fork();
console.error('[%s] [master:%s] wroker:%s disconnect, suicide: %s, state: %s. New worker:%s fork',
Date(), process.pid, worker.process.pid, worker.suicide, worker.state, w.process.pid);
});
cluster.on('exit', function (worker, code, signal) {
}).on('disconnect', function (worker) {
console.error('[%s] [master:%s] wroker:%s disconnect, suicide: %s, state: %s.',
Date(), process.pid, worker.process.pid, worker.suicide, worker.state);
}).on('exit', function (worker, code, signal) {
var exitCode = worker.process.exitCode;
var err = new Error(util.format('worker %s died (code: %s, signal: %s, suicide: %s, state: %s)',
worker.process.pid, exitCode, signal, worker.suicide, worker.state));
err.name = 'WorkerDiedError';
console.error('[%s] [master:%s] wroker exit: %s', Date(), process.pid, err.stack);
});
// Fork workers.
for (var i = 0; i < config.numCPUs; i++) {
cluster.fork();
}
}
function forkSyncer() {

View File

@@ -1,4 +1,4 @@
CREATE TABLE `user` (
CREATE TABLE IF NOT EXISTS `user` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`gmt_create` datetime NOT NULL COMMENT 'create time',
`gmt_modified` datetime NOT NULL COMMENT 'modified time',
@@ -19,7 +19,7 @@ CREATE TABLE `user` (
-- ADD `json` longtext CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT 'json details',
-- ADD `npm_user` tinyint(1) DEFAULT '0' COMMENT 'user sync from npm or not, 1: true, other: false';
CREATE TABLE `module_keyword` (
CREATE TABLE IF NOT EXISTS `module_keyword` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`gmt_create` datetime NOT NULL COMMENT 'create time',
`keyword` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'keyword',
@@ -30,7 +30,7 @@ CREATE TABLE `module_keyword` (
KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module keyword';
CREATE TABLE `module_star` (
CREATE TABLE IF NOT EXISTS `module_star` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`gmt_create` datetime NOT NULL COMMENT 'create time',
`user` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'user name',
@@ -40,7 +40,7 @@ CREATE TABLE `module_star` (
KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module star';
CREATE TABLE `module_maintainer` (
CREATE TABLE IF NOT EXISTS `module_maintainer` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`gmt_create` datetime NOT NULL COMMENT 'create time',
`user` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'user name',
@@ -48,9 +48,19 @@ CREATE TABLE `module_maintainer` (
PRIMARY KEY (`id`),
UNIQUE KEY `user_module_name` (`user`,`name`),
KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module maintainers';
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='private module maintainers';
CREATE TABLE `module` (
CREATE TABLE IF NOT EXISTS `npm_module_maintainer` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`gmt_create` datetime NOT NULL COMMENT 'create time',
`user` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'user name',
`name` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'module name',
PRIMARY KEY (`id`),
UNIQUE KEY `user_module_name` (`user`,`name`),
KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='npm original module maintainers';
CREATE TABLE IF NOT EXISTS `module` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`gmt_create` datetime NOT NULL COMMENT 'create time',
`gmt_modified` datetime NOT NULL COMMENT 'modified time',
@@ -76,7 +86,7 @@ CREATE TABLE `module` (
-- show create table module\G
-- ALTER TABLE `module` CHANGE `name` `name` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'module name';
CREATE TABLE `module_log` (
CREATE TABLE IF NOT EXISTS `module_log` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`gmt_create` datetime NOT NULL COMMENT 'create time',
`gmt_modified` datetime NOT NULL COMMENT 'modified time',
@@ -88,7 +98,7 @@ CREATE TABLE `module_log` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module sync log';
-- ALTER TABLE `module_log` CHANGE `name` `name` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'module name';
CREATE TABLE `tag` (
CREATE TABLE IF NOT EXISTS `tag` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`gmt_create` datetime NOT NULL COMMENT 'create time',
`gmt_modified` datetime NOT NULL COMMENT 'modified time',
@@ -104,7 +114,7 @@ CREATE TABLE `tag` (
-- ALTER TABLE `tag` CHANGE `name` `name` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'module name';
-- ALTER TABLE `tag` ADD KEY `gmt_modified` (`gmt_modified`);
CREATE TABLE `module_unpublished` (
CREATE TABLE IF NOT EXISTS `module_unpublished` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`gmt_create` datetime NOT NULL COMMENT 'create time',
`gmt_modified` datetime NOT NULL COMMENT 'modified time',
@@ -115,7 +125,7 @@ CREATE TABLE `module_unpublished` (
KEY `gmt_modified` (`gmt_modified`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module unpublished info';
CREATE TABLE `total` (
CREATE TABLE IF NOT EXISTS `total` (
`name` varchar(100) NOT NULL COMMENT 'total name',
`gmt_modified` datetime NOT NULL COMMENT 'modified time',
`module_delete` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT 'module delete count',
@@ -129,7 +139,9 @@ CREATE TABLE `total` (
`last_sync_module` varchar(100) COMMENT 'last sync success module name',
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='total info';
INSERT INTO total(name, gmt_modified) VALUES('total', now());
-- init `total` count
INSERT INTO total(name, gmt_modified) VALUES('total', now())
ON DUPLICATE KEY UPDATE gmt_modified=now();
-- ALTER TABLE `total` ADD `last_sync_time` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT 'last timestamp sync from official registry'
-- ALTER TABLE `total` ADD `last_exist_sync_time` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT 'last timestamp sync exist packages from official registry'
-- ALTER TABLE `total` ADD `sync_status` tinyint unsigned NOT NULL DEFAULT '0' COMMENT 'system sync from official registry status'
@@ -139,7 +151,7 @@ INSERT INTO total(name, gmt_modified) VALUES('total', now());
-- ALTER TABLE `total` ADD `left_sync_num` int unsigned NOT NULL DEFAULT '0' COMMENT 'how many packages left to be sync'
-- ALTER TABLE `total` ADD `last_sync_module` varchar(100) NOT NULL COMMENT 'last sync success module name';
CREATE TABLE `download_total` (
CREATE TABLE IF NOT EXISTS `download_total` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`gmt_create` datetime NOT NULL COMMENT 'create time',
`gmt_modified` datetime NOT NULL COMMENT 'modified time',
@@ -151,7 +163,7 @@ CREATE TABLE `download_total` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module download total info';
-- ALTER TABLE `download_total` CHANGE `name` `name` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'module name';
CREATE TABLE `module_deps` (
CREATE TABLE IF NOT EXISTS `module_deps` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`gmt_create` datetime NOT NULL COMMENT 'create time',
`name` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'module name',
@@ -161,7 +173,7 @@ CREATE TABLE `module_deps` (
KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module deps';
CREATE TABLE `dist_dir` (
CREATE TABLE IF NOT EXISTS `dist_dir` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`gmt_create` datetime NOT NULL COMMENT 'create time',
`gmt_modified` datetime NOT NULL COMMENT 'modified time',
@@ -173,7 +185,7 @@ CREATE TABLE `dist_dir` (
KEY `gmt_modified` (`gmt_modified`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='dist dir info';
CREATE TABLE `dist_file` (
CREATE TABLE IF NOT EXISTS `dist_file` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`gmt_create` datetime NOT NULL COMMENT 'create time',
`gmt_modified` datetime NOT NULL COMMENT 'modified time',

895
docs/registry-api.md Normal file
View File

@@ -0,0 +1,895 @@
# NPM Registry API
## Overview
* [Schema](/docs/registry-api.md#schema)
* [Client Errors](/docs/registry-api.md#client-errors)
* [Authentication](/docs/registry-api.md#authentication)
* [Package](/docs/registry-api.md#package)
* [User](/docs/registry-api.md#user)
* [Search](/docs/registry-api.md#search)
## Schema
All API access is over HTTPS or HTTP,
and accessed from the `registry.npmjs.org` domain.
All data is sent and received as JSON.
```bash
$ curl -i https://registry.npmjs.org
HTTP/1.1 200 OK
Date: Tue, 05 Aug 2014 10:53:24 GMT
Server: CouchDB/1.5.0 (Erlang OTP/R16B03)
Content-Type: text/plain; charset=utf-8
Cache-Control: max-age=60
Content-Length: 258
Accept-Ranges: bytes
Via: 1.1 varnish
Age: 11
X-Served-By: cache-ty67-TYO
X-Cache: HIT
X-Cache-Hits: 1
X-Timer: S1407236004.867906,VS0,VE0
{"db_name":"registry","doc_count":90789,"doc_del_count":381,"update_seq":137250,"purge_seq":0,
"compact_running":false,"disk_size":436228219,"data_size":332875061,
"instance_start_time":"1405721973718703","disk_format_version":6,"committed_update_seq":137250}
```
## Client Errors
```json
Status: 4xx
{
"error": "error_name",
"reason": "error reason string"
}
```
## Authentication
There is only one way to authenticate through the API.
## Basic Authentication
```bash
$ curl -u "username:password" https://registry.npmjs.org
```
## Failed login limit
```bash
$ curl -i -X PUT -u foo:pwd \
-d '{"name":"foo","email":"foo@bar.com","type":"user","roles":[]}' \
https://registry.npmjs.org/-/user/org.couchdb.user:foo/-rev/11-d226c6afa9286ab5b9eb858c429bdabf
HTTP/1.1 401 Unauthorized
Date: Tue, 05 Aug 2014 15:33:25 GMT
Server: CouchDB/1.5.0 (Erlang OTP/R14B04)
Content-Type: text/plain; charset=utf-8
Cache-Control: max-age=60
Content-Length: 67
Accept-Ranges: bytes
Via: 1.1 varnish
X-Served-By: cache-ty66-TYO
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1407252805.261390,VS0,VE434
{"error":"unauthorized","reason":"Name or password is incorrect."}
```
## Package
* Read
* [Get a single package](/docs/registry-api.md#get-a-single-package)
* [Get a special version or tag package](/docs/registry-api.md#get-a-special-version-or-tag-package)
* [List packages since from a update time](/docs/registry-api.md#list-packages-since-from-a-update-time)
* [List package names by users](/docs/registry-api.md#list-package-names-by-users)
* Write
* [Publish a new package](/docs/registry-api.md#publish-a-new-package)
* [Update a package's tag](/docs/registry-api.md#update-a-packages-tag)
* [Update a package's maintainers](/docs/registry-api.md#update-a-packages-maintainers)
* [Remove one version from package](/docs/registry-api.md#remove-one-version-from-package)
* [Remove a tgz file from package](/docs/registry-api.md#remove-a-tgz-file-from-package)
### Get a single package
```
GET /:package
```
#### Response
```json
HTTP/1.1 200 OK
Etag: "8UDCP753LFXOG42NMX88JAN40"
Content-Type: application/json
Cache-Control: max-age=60
Content-Length: 2243
{
"_id": "pedding",
"_rev": "11-e6d1e6e96eaf72433fef6aaabe843af8",
"name": "pedding",
"description": "Just pedding for callback.",
"dist-tags": {
"latest": "1.0.0"
},
"versions": {
"1.0.0": {
"name": "pedding",
"version": "1.0.0",
"description": "Just pedding for callback.",
"main": "index.js",
"scripts": {
"test": "make test-all"
},
"repository": {
"type": "git",
"url": "git://github.com/fengmk2/pedding.git"
},
"keywords": [
"pedding",
"callback"
],
"devDependencies": {
"contributors": "*",
"mocha": "*",
"mocha-phantomjs": "*",
"component": "*",
"chai": "*"
},
"author": {
"name": "fengmk2",
"email": "fengmk2@gmail.com"
},
"license": "MIT",
"contributors": [
{
"name": "fengmk2",
"email": "fengmk2@gmail.com",
"url": "https://github.com/fengmk2"
},
{
"name": "dead-horse",
"email": "dead_horse@qq.com",
"url": "https://github.com/dead-horse"
}
],
"gitHead": "b42a708414a704336e9dee570a963e2dbe43e529",
"bugs": {
"url": "https://github.com/fengmk2/pedding/issues"
},
"homepage": "https://github.com/fengmk2/pedding",
"_id": "pedding@1.0.0",
"_shasum": "7f5098d60307b4ef7240c3d693cb20a9473c6074",
"_from": ".",
"_npmVersion": "1.4.13",
"_npmUser": {
"name": "fengmk2",
"email": "fengmk2@gmail.com"
},
"maintainers": [
{
"name": "fengmk2",
"email": "fengmk2@gmail.com"
},
{
"name": "dead-horse",
"email": "dead_horse@qq.com"
}
],
"dist": {
"shasum": "7f5098d60307b4ef7240c3d693cb20a9473c6074",
"tarball": "http://registry.npmjs.org/pedding/-/pedding-1.0.0.tgz"
},
"directories": {}
}
},
"readme": "# pedding\n readme...",
"maintainers": [
{
"name": "fengmk2",
"email": "fengmk2@gmail.com"
},
{
"name": "dead-horse",
"email": "dead_horse@qq.com"
},
{
"name": "dead_horse",
"email": "dead_horse@qq.com"
}
],
"time": {
"modified": "2014-07-05T14:22:53.849Z",
"created": "2012-09-18T14:46:08.346Z",
"0.0.1": "2012-09-18T14:46:21.321Z",
"0.0.2": "2013-06-22T08:26:45.125Z",
"0.0.3": "2013-07-02T15:20:34.707Z",
"1.0.0": "2014-07-05T11:08:51.614Z"
},
"author": {
"name": "fengmk2",
"email": "fengmk2@gmail.com"
},
"repository": {
"type": "git",
"url": "git://github.com/fengmk2/pedding.git"
},
"keywords": [
"pedding",
"callback"
],
"bugs": {
"url": "https://github.com/fengmk2/pedding/issues"
},
"license": "MIT",
"readmeFilename": "README.md",
"homepage": "https://github.com/fengmk2/pedding",
"contributors": [
{
"name": "fengmk2",
"email": "fengmk2@gmail.com",
"url": "https://github.com/fengmk2"
},
{
"name": "dead-horse",
"email": "dead_horse@qq.com",
"url": "https://github.com/dead-horse"
}
],
"_attachments": {}
}
```
### ~~Get a special version or tag package~~
__deprecated__
```
GET /:package/:tag_or_version
```
#### Reponse
```json
HTTP/1.1 200 OK
Etag: "1WJ4JF535RO3BDZR2BARXSGLY"
Content-Type: application/json
Cache-Control: max-age=60
Content-Length: 1183
{
"name": "pedding",
"version": "1.0.0",
"description": "Just pedding for callback.",
"main": "index.js",
"scripts": {
"test": "make test-all"
},
"repository": {
"type": "git",
"url": "git://github.com/fengmk2/pedding.git"
},
"keywords": [
"pedding",
"callback"
],
"devDependencies": {
"contributors": "*",
"mocha": "*",
"mocha-phantomjs": "*",
"component": "*",
"chai": "*"
},
"author": {
"name": "fengmk2",
"email": "fengmk2@gmail.com"
},
"license": "MIT",
"contributors": [
{
"name": "fengmk2",
"email": "fengmk2@gmail.com",
"url": "https://github.com/fengmk2"
},
{
"name": "dead-horse",
"email": "dead_horse@qq.com",
"url": "https://github.com/dead-horse"
}
],
"gitHead": "b42a708414a704336e9dee570a963e2dbe43e529",
"bugs": {
"url": "https://github.com/fengmk2/pedding/issues"
},
"homepage": "https://github.com/fengmk2/pedding",
"_id": "pedding@1.0.0",
"_shasum": "7f5098d60307b4ef7240c3d693cb20a9473c6074",
"_from": ".",
"_npmVersion": "1.4.13",
"_npmUser": {
"name": "fengmk2",
"email": "fengmk2@gmail.com"
},
"maintainers": [
{
"name": "fengmk2",
"email": "fengmk2@gmail.com"
},
{
"name": "dead-horse",
"email": "dead_horse@qq.com"
}
],
"dist": {
"shasum": "7f5098d60307b4ef7240c3d693cb20a9473c6074",
"tarball": "http://registry.npmjs.org/pedding/-/pedding-1.0.0.tgz"
},
"directories": {}
}
```
### Publish a new package
* Authentication required.
```
PUT /:package
```
#### Input
```json
{
"_id": "pedding",
"name": "pedding",
"description": "Just pedding for callback.",
"dist-tags": {
"latest": "1.0.0"
},
"versions": {
"1.0.0": {
"name": "pedding",
"version": "1.0.0",
"description": "Just pedding for callback.",
"main": "index.js",
"scripts": {
"test": "make test-all"
},
"repository": {
"type": "git",
"url": "git://github.com/fengmk2/pedding.git"
},
"keywords": [ "pedding","callback" ],
"devDependencies": {
"contributors": "*",
"mocha": "*",
"mocha-phantomjs": "*",
"component": "*",
"chai": "*"
},
"dependencies": {},
"author": {
"name": "fengmk2",
"email": "fengmk2@gmail.com"
},
"license": "MIT",
"contributors": [
{
"name": "fengmk2",
"email": "fengmk2@gmail.com",
"url": "https://github.com/fengmk2"
},
{
"name": "dead-horse",
"email": "dead_horse@qq.com",
"url": "https://github.com/dead-horse"
}
],
"readme": "# pedding ...",
"readmeFilename": "README.md",
"gitHead": "b42a708414a704336e9dee570a963e2dbe43e529",
"bugs": {
"url": "https://github.com/fengmk2/pedding/issues"
},
"homepage": "https://github.com/fengmk2/pedding",
"_id": "pedding@1.0.0",
"_shasum": "7f5098d60307b4ef7240c3d693cb20a9473c6074",
"_from": ".",
"_npmVersion": "1.5.0-alpha-4",
"_npmUser": {
"name": "admin",
"email": "fengmk2@gmail.com"
},
"maintainers": [
{
"name": "admin",
"email": "fengmk2@gmail.com"
}
],
"dist": {
"shasum": "7f5098d60307b4ef7240c3d693cb20a9473c6074",
"tarball": "https://registry.npmjs.org/pedding/-/pedding-1.0.0.tgz"
}
}
},
"readme": "# pedding ...",
"maintainers": [
{
"name": "admin",
"email": "fengmk2@gmail.com"
}
],
"_attachments": {
"pedding-1.0.0.tgz":{
"content_type": "application/octet-stream",
"data": "H4sIAAAAAAAAA+0aa3PbNjKf8Su...",
"length": 2107
}
}
}
```
#### Response
```json
Status: 201 Created
{
"ok": true,
"rev": "11-e6d1e6e96eaf72433fef6aaabe843af8"
}
```
### Update a package's tag
* Authentication required.
```
PUT /:package/:tag
```
#### Input
The total input body is the `version` string which's setting to the tag.
```json
"1.0.0"
```
#### Response
```json
Status: 201 Created
{
"ok": true
}
```
### Update a package's maintainers
* Authentication required.
```
PUT /:package/-rev/:rev
```
#### Input
```json
{
"_id": "pedding",
"_rev": "11-e6d1e6e96eaf72433fef6aaabe843af8",
"maintainers":[
{ "name": "fengmk2", "email": "fengmk2@gmail.com" },
{ "name": "dead-horse", "email": "dead_horse@qq.com" }
]
}
```
#### Response
```json
Status: 201 Created
{
"ok": true,
"id": "pedding",
"rev": "12-bb300a90c9aeb779748b83ec1b744039"
}
```
### Remove one version from package
* Authentication required.
* In any delete, note that __the version number still cannot be reused__.
```
PUT /:package/-rev/:rev
```
#### Input
Remove that specific version from the versions hash in the `PUT` body.
Example for removing `0.0.1` version:
```json
{
"_id": "pedding",
"_rev": "12-bb300a90c9aeb779748b83ec1b744039",
"name": "pedding",
"description": "desc",
"dist-tags": { "latest": "1.0.0" },
"maintainers":
[ ... ],
"time":
{ ... },
"users": {},
"author": { ... },
"repository": { ... },
"versions":
{ "1.0.0":
{ ... },
"0.0.3":
{ ... },
"0.0.2":
{ ... } },
"readme": "...",
"homepage": "https://github.com/fengmk2/pedding",
"bugs": { ... },
"license": "MIT" }
```
#### Response
```json
Status: 201 Created
{
"ok": true
}
```
### Remove all versions of a package
* Authentication required.
* In any delete, note that __the version number still cannot be reused__.
```
DELETE /:package/-rev/:rev
```
#### Response
```json
Status: 201 Created
{
"ok": true
}
```
### Remove a tgz file from package
* Authentication required.
```
DELETE /:tgzfilepath/-rev/:rev
```
Exmaple for removing `https://registry.npmjs.org/pedding/-/pedding-0.0.1.tgz` file:
```
DELETE /pedding/-/pedding-0.0.1.tgz/-rev/12-bb300a90c9aeb779748b83ec1b744039
```
#### Response
```json
Status: 200 OK
{
"ok": true
}
```
### List packages since from a update time
```
GET /-/all/since?stale=update_after&startkey=:startkey
```
* `startkey` is a ms timestamp
#### Response
```bash
$ curl -i "https://registry.npmjs.org/-/all/since?stale=update_after&startkey=1407255748643"
```
```json
HTTP/1.1 200 OK
{
"_updated": 1407255883282,
"bacon-and-eggs": {
"name": "bacon-and-eggs",
"description": "A functional reactive Twitter API client in node",
"dist-tags": {
"latest": "0.0.4"
},
"maintainers": [
{
"name": "mikegroseclose",
"email": "mike.groseclose@gmail.com"
}
],
"homepage": "http://github.com/mikegroseclose/bacon-and-eggs",
"keywords": [
"twitter",
"api",
"frp",
"functional",
"reactive",
"bacon",
"eggs",
"oauth",
"stream",
"streams"
],
"repository": {
"type": "git",
"url": "git://github.com/mikegroseclose/gulp-regex-replace.git"
},
"author": {
"name": "Mike Groseclose",
"email": "mike.groseclose@gmail.com",
"url": "http://mikegroseclose.com"
},
"bugs": {
"url": "https://github.com/mikegroseclose/gulp-regex-replace/issues"
},
"readmeFilename": "README.md",
"time": {
"modified": "2014-08-05T16:21:17.041Z"
},
"versions": {
"0.0.4": "latest"
}
},
"git-perm-rm": {
"name": "git-perm-rm",
"description": "Permanently remove a file or directory from a git repo including all related commit records.",
"dist-tags": {
"latest": "1.0.1"
},
"maintainers": [
{
"name": "kael",
"email": "i@kael.me"
}
],
"homepage": "https://github.com/kaelzhang/git-perm-rm",
"keywords": [
"git",
"rm",
"git-perm-rm",
"remove",
"permanently"
],
"repository": {
"type": "git",
"url": "git://github.com/kaelzhang/git-perm-rm.git"
},
"author": {
"name": "Kael"
},
"bugs": {
"url": "https://github.com/kaelzhang/git-perm-rm/issues"
},
"license": "MIT",
"readmeFilename": "README.md",
"time": {
"modified": "2014-08-05T16:22:41.253Z"
},
"versions": {
"1.0.1": "latest"
}
}
}
```
### List package names by users
```bash
GET /-/by-user/$username[|$another1[|$another2...]]
```
* `username` user name like `fengmk2`
* also support multi users by `name1|name2|name3`
#### Response
```bash
$ curl -i "https://registry.npmjs.org/-/by-user/czy88840616"
$ curl -i "https://registry.npmjs.org/-/by-user/czy88840616|fengmk2|dead-horse"
```
```json
HTTP/1.1 200 OK
{
"czy88840616": [
"easyconf",
"egg",
"flag",
"gdp",
"generator-webx-vm",
"magic-cube",
"rim",
"tbuild",
"test-publish",
"velocity-parser",
"vmarket",
"wi"
]
}
```
## User
* [Get a single user](/docs/registry-api.md#get-a-single-user)
* [Add a new user](/docs/registry-api.md#add-a-new-user)
* [Update a exists user](/docs/registry-api.md#update-a-exists-user)
### Get a single user
```
GET /-/user/org.couchdb.user::username
```
#### Response
```json
HTTP/1.1 200 OK
ETag: "32-984ee97e01aea166dcab6d1517c730e3"
{
"_id": "org.couchdb.user:fengmk2",
"_rev": "32-984ee97e01aea166dcab6d1517c730e3",
"name": "fengmk2",
"email": "fengmk2@gmail.com",
"type": "user",
"roles": [],
"date": "2014-08-04T10:43:07.063Z",
"fullname": "fengmk2",
"avatar": "https://secure.gravatar.com/avatar/95b9d41231617a05ced5604d242c9670?s=50&d=retro",
"freenode": "",
"github": "fengmk2",
"homepage": "http://fengmk2.github.com",
"twitter": "fengmk2",
"avatarMedium": "https://secure.gravatar.com/avatar/95b9d41231617a05ced5604d242c9670?s=100&d=retro",
"avatarLarge": "https://secure.gravatar.com/avatar/95b9d41231617a05ced5604d242c9670?s=496&d=retro",
"fields": [
{
"name": "fullname",
"value": "fengmk2",
"title": "Full Name",
"show": "fengmk2"
},
{
"name": "email",
"value": "fengmk2@gmail.com",
"title": "Email",
"show": "<a href=\"mailto:fengmk2@gmail.com\">fengmk2@gmail.com</a>"
},
{
"name": "github",
"value": "fengmk2",
"title": "Github",
"show": "<a rel=\"me\" href=\"https://github.com/fengmk2\">fengmk2</a>"
},
{
"name": "twitter",
"value": "fengmk2",
"title": "Twitter",
"show": "<a rel=\"me\" href=\"https://twitter.com/fengmk2\">@fengmk2</a>"
},
{
"name": "appdotnet",
"value": "",
"title": "App.net",
"show": ""
},
{
"name": "homepage",
"value": "http://fengmk2.github.com",
"title": "Homepage",
"show": "<a rel=\"me\" href=\"http://fengmk2.github.com/\">http://fengmk2.github.com</a>"
},
{
"name": "freenode",
"value": "",
"title": "IRC Handle",
"show": ""
}
],
"appdotnet": "fengmk2"
}
```
### Add a new user
```
PUT /-/user/org.couchdb.user::username
```
#### Input
```json
{
"name": "admin",
"password": "123",
"email": "fengmk2@gmail.com",
"_id": "org.couchdb.user:admin",
"type": "user",
"roles": [],
"date": "2014-08-05T16:05:17.792Z"
}
```
#### Response
```json
Status: 201 Created
{
"ok": true,
"id": "org.couchdb.user:fengmk2",
"rev": "32-984ee97e01aea166dcab6d1517c730e3"
}
```
### Update a exists user
* Authentication required.
```
PUT /-/user/org.couchdb.user::username/-rev/:rev
```
#### Input
```json
{
"name": "admin",
"password": "123",
"email": "fengmk2@gmail.com",
"_id": "org.couchdb.user:admin",
"type": "user",
"roles": [],
"date": "2014-08-05T16:05:17.792Z",
"_rev": "2-1a18c3d73ba42e863523a399ff3304d8"
}
```
#### Response
```json
Status: 201 Created
{
"ok": true,
"id": "org.couchdb.user:fengmk2",
"rev": "3-bb300a90c9aeb779748b83ec1b744039"
}
```
## Search

View File

@@ -1,4 +1,4 @@
CREATE TABLE `module_maintainer` (
CREATE TABLE IF NOT EXISTS `npm_module_maintainer` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
`gmt_create` datetime NOT NULL COMMENT 'create time',
`user` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'user name',
@@ -6,4 +6,4 @@ CREATE TABLE `module_maintainer` (
PRIMARY KEY (`id`),
UNIQUE KEY `user_module_name` (`user`,`name`),
KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module maintainers';
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='npm original module maintainers';

View File

@@ -6,6 +6,7 @@ So `cnpm` is meaning: **Company npm**.
* 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>
* Mirror of [Node.js Manual & Documentation](/dist/latest/docs/api/index.html)
* Mirror of [nodejs.org/dist](http://nodejs.org/dist): [/dist mirror](/dist)
* Mirror of [phantomjs downloads](https://bitbucket.org/ariya/phantomjs/downloads): [phantomjs mirror](/dist/phantomjs/)
@@ -104,6 +105,16 @@ $(function () {
});
</script>
## Version Badge
Default style is `flat-square`.
Badge URL: `http://cnpmjs.org/badge/v/cnpmjs.org.svg` ![cnpmjs.org-badge](http://cnpmjs.org/badge/v/cnpmjs.org.svg)
* `<0.1.0 & >=0.0.0`: ![red-badge](https://img.shields.io/badge/cnpm-0.0.1-red.svg?style=flat-square)
* `<1.0.0 & >=0.1.0`: ![red-badge](https://img.shields.io/badge/cnpm-0.1.0-green.svg?style=flat-square)
* `>=1.0.0`: ![red-badge](https://img.shields.io/badge/cnpm-1.0.0-blue.svg?style=flat-square)
## Usage
use our npm client [cnpm](https://github.com/cnpm/cnpm)(More suitable with cnpmjs.org and gzip support), you can get our client through npm:

View File

@@ -17,6 +17,11 @@
var debug = require('debug')('cnpmjs.org:middleware:auth');
var UserService = require('../services/user');
/**
* Parse the request authorization
* get the real user
*/
module.exports = function (options) {
return function* auth(next) {
this.user = {};
@@ -40,12 +45,9 @@ module.exports = function (options) {
try {
row = yield* UserService.auth(username, password);
} catch (err) {
this.status = err.status || 500;
this.body = {
error: err.name,
reason: err.message
};
return;
// do not response error here
// many request do not need login
this.user.error = err;
}
if (!row) {

View File

@@ -14,8 +14,24 @@
* Module dependencies.
*/
var http = require('http');
module.exports = function *login(next) {
if (this.user.error) {
var status = this.user.error.status;
this.status = http.STATUS_CODES[status]
? status
: 500;
this.body = {
error: this.user.error.name,
reason: this.user.error.message
};
return;
}
if (!this.user.name) {
this.status = 401;
this.body = {
error: 'unauthorized',

View File

@@ -38,16 +38,16 @@ module.exports = function *notFound(next) {
// package not found
m = /\/package\/([\w\-\_\.]+)\/?$/.exec(this.url);
var name = null;
var title = '404: Page Not Found';
if (m) {
var name = m[1];
this.status = 404;
yield* this.render('404', {
title: 'Package - ' + name,
name: name
});
return;
name = m[1];
title = name + ' Not Found';
}
this.status = 404;
this.body = 'Cannot GET ' + this.path;
yield* this.render('404', {
title: title,
name: name
});
};

View File

@@ -1,6 +1,6 @@
{
"name": "cnpmjs.org",
"version": "1.0.0",
"version": "1.6.1",
"description": "Private npm registry and web for Enterprise, base on MySQL and Simple Store Service",
"main": "index.js",
"scripts": {
@@ -10,57 +10,61 @@
"stop": "./bin/nodejsctl stop"
},
"dependencies": {
"bytes": "1.0.0",
"cheerio": "0.17.0",
"co": "3.0.6",
"co-defer": "0.1.0",
"co-gather": "0.0.1",
"co-read": "0.1.0",
"co-redis": "1.1.0",
"co-urllib": "0.2.3",
"co-write": "0.3.0",
"copy-to": "1.0.1",
"debug": "1.0.4",
"error-formater": "1.0.3",
"eventproxy": "0.3.1",
"giturl": "0.0.3",
"graceful": "0.1.0",
"gravatar": "1.0.6",
"humanize-number": "0.0.2",
"koa": "0.8.1",
"koa-limit": "1.0.2",
"koa-markdown": "0.0.3",
"koa-middlewares": "1.2.0",
"marked": "0.3.2",
"mime": "1.2.11",
"mini-logger": "0.3.0",
"mkdirp": "0.5.0",
"moment": "2.7.0",
"ms": "0.6.2",
"multiline": "0.3.4",
"mysql": "2.4.1",
"nodemailer": "0.7.1",
"qn": "0.2.2",
"ready": "0.1.1",
"redis": "0.11.0",
"semver": "3.0.1",
"thunkify-wrap": "1.0.1",
"utility": "0.1.16"
"agentkeepalive": "~1.2.0",
"bluebird": "~2.3.5",
"bytes": "~1.0.0",
"cfork": "~1.2.0",
"cheerio": "~0.17.0",
"co": "~3.1.0",
"co-defer": "~0.1.1",
"co-gather": "~0.0.1",
"co-read": "~0.1.0",
"co-redis": "~1.1.0",
"co-sleep": "~0.0.1",
"co-write": "~0.3.0",
"copy-to": "~1.0.1",
"debug": "~2.0.0",
"error-formater": "~1.0.3",
"eventproxy": "~0.3.1",
"fs-cnpm": "~1.1.0",
"giturl": "~0.0.3",
"graceful": "~0.1.0",
"gravatar": "~1.1.0",
"humanize-number": "~0.0.2",
"koa": "~0.12.2",
"koa-limit": "~1.0.2",
"koa-markdown": "~0.0.3",
"koa-middlewares": "~1.4.1",
"marked": "~0.3.2",
"mime": "~1.2.11",
"mini-logger": "~1.0.0",
"mkdirp": "~0.5.0",
"moment": "~2.8.3",
"ms": "~0.6.2",
"multiline": "~1.0.1",
"mysql": "~2.5.1",
"nodemailer": "~1.3.0",
"ready": "~0.1.1",
"redis": "~0.12.1",
"semver": "~4.0.3",
"thunkify-wrap": "~1.0.2",
"urllib": "~1.5.2",
"utility": "~1.2.0"
},
"devDependencies": {
"autod": "~0.2.0",
"chunkstream": "0.0.1",
"autod": "^1.0.0",
"chunkstream": "~0.0.1",
"co-mocha": "0.0.2",
"contributors": "*",
"cov": "*",
"istanbul-harmony": "*",
"jshint": "*",
"mm": "0.2.1",
"mocha": "*",
"pedding": "1.0.0",
"should": "4.0.4",
"istanbul-harmony": "~0.3.0",
"jshint": "~2.5.6",
"mm": "~0.2.1",
"mocha": "~1.21.4",
"node-dev": "*",
"pedding": "~1.0.0",
"should": "~4.0.4",
"should-http": "0.0.1",
"supertest": "0.13.0"
"supertest": "~0.14.0"
},
"homepage": "https://github.com/cnpm/cnpmjs.org",
"repository": {
@@ -80,7 +84,7 @@
"registry"
],
"engines": {
"node": ">= 0.11.9"
"node": ">= 0.11.14"
},
"author": [
"fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)",

View File

@@ -57,7 +57,9 @@ exports.add = function (mod, callback) {
dist.size = 0;
var publish_time = mod.publish_time || Date.now();
var values = [
publish_time, mod.author, mod.name, mod.version, pkg,
publish_time,
mod.author, // meaning first maintainer, more maintainers please check module_maintainer table
mod.name, mod.version, pkg,
dist.tarball, dist.shasum, dist.size, description
];
mysql.query(INSERT_MODULE_SQL, values, function (err, result) {
@@ -162,26 +164,6 @@ exports.updateDescription = function (id, description, callback) {
mysql.query(UPDATE_DESC_SQL, [description, id], callback);
};
var UPDATE_PACKAGE_SQL = multiline(function () {;/*
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 ? WHERE id=?';
exports.update = function (mod, callback) {
var pkg;
@@ -495,70 +477,13 @@ exports.removeByNameAndVersions = function (name, versions, callback) {
mysql.query(DELETE_MODULE_BY_NAME_AND_VERSIONS_SQL, [name, versions], callback);
};
var LIST_BY_AUTH_SQLS = [];
LIST_BY_AUTH_SQLS.push(multiline(function () {;/*
SELECT
distinct(name) AS name
FROM
module
WHERE
author=?
ORDER BY
publish_time DESC
LIMIT
100;
*/}));
LIST_BY_AUTH_SQLS.push(multiline(function () {;/*
SELECT
module_id
FROM
tag
WHERE
tag="latest" AND name IN (?);
*/}));
LIST_BY_AUTH_SQLS.push(multiline(function () {;/*
SELECT
name, description
FROM
module
WHERE
id IN (?)
ORDER BY
publish_time DESC;
*/}));
exports.listByAuthor = function (author, callback) {
var ep = eventproxy.create();
ep.fail(callback);
mysql.query(LIST_BY_AUTH_SQLS[0], [author], ep.done(function (rows) {
if (!rows || rows.length === 0) {
return callback(null, []);
}
ep.emit('names', rows.map(function (r) {
return r.name;
}));
}));
ep.on('names', function (names) {
mysql.query(LIST_BY_AUTH_SQLS[1], [names], ep.done(function (rows) {
if (!rows || rows.length === 0) {
return callback(null, []);
}
ep.emit('ids', rows.map(function (r) {
return r.module_id;
}));
}));
});
ep.on('ids', function (ids) {
mysql.query(LIST_BY_AUTH_SQLS[2], [ids], callback);
});
};
var SEARCH_MODULES_SQL = multiline(function () {;/*
SELECT
module_id
FROM
tag
WHERE
name LIKE ? AND tag="latest"
LOWER(name) LIKE LOWER(?) AND tag="latest"
ORDER BY
name
LIMIT
@@ -739,3 +664,115 @@ exports.listPrivates = function* () {
return yield mysql.query(QUERY_MODULES_BY_ID_SQL, [ids]);
};
var LIST_BY_AUTH_SQLS = [];
LIST_BY_AUTH_SQLS.push(multiline(function () {;/*
SELECT
distinct(name) AS name
FROM
module
WHERE
author=?
ORDER BY
publish_time DESC
LIMIT
100;
*/}));
LIST_BY_AUTH_SQLS.push(multiline(function () {;/*
SELECT
name
FROM
module_maintainer
WHERE
user = ?
*/}));
LIST_BY_AUTH_SQLS.push(multiline(function () {;/*
SELECT
module_id
FROM
tag
WHERE
tag="latest" AND name IN (?);
*/}));
LIST_BY_AUTH_SQLS.push(multiline(function () {;/*
SELECT
name, description
FROM
module
WHERE
id IN (?)
ORDER BY
publish_time DESC;
*/}));
exports.listByAuthor = function* (author) {
var names = yield [
mysql.query(LIST_BY_AUTH_SQLS[0], [author]),
mysql.query(LIST_BY_AUTH_SQLS[1], [author])
];
names = names[0].concat(names[1]).map(function (n) {
return n.name;
}).sort();
if (!names.length) {
return [];
}
var ids = yield mysql.query(LIST_BY_AUTH_SQLS[2], [names]);
if (!ids.length) {
return [];
}
ids = ids.map(function (i) {
return i.module_id;
});
return yield mysql.query(LIST_BY_AUTH_SQLS[3], [ids]);
};
exports.listNamesByAuthor = function* (author) {
var sql = 'SELECT distinct(name) AS name FROM module WHERE author=?;';
var names = yield mysql.query(sql, [author]);
return names.map(function (item) {
return item.name;
});
};
var UPDATE_PACKAGE_SQL = multiline(function () {;/*
UPDATE
module
SET
package=?
WHERE
id=?;
*/});
exports.updatePackage = function* (id, pkg) {
pkg = stringifyPackage(pkg);
return yield mysql.query(UPDATE_PACKAGE_SQL, [pkg, id]);
};
exports.updatePackageFields = function* (id, fields) {
var data = yield exports.getById(id);
if (!data) {
throw new Error('module#' + id + ' not exists');
}
data.package = data.package || {};
for (var k in fields) {
data.package[k] = fields[k];
}
return yield* exports.updatePackage(id, data.package);
};
exports.updateReadme = function* (id, readme) {
var data = yield exports.getById(id);
if (!data) {
throw new Error('module#' + id + ' not exists');
}
data.package = data.package || {};
data.package.readme = readme;
return yield* exports.updatePackage(id, data.package);
};
exports.getTag = function* (name, tag) {
return yield mysql.queryOne(SELECT_TAG_SQL, [name, tag]);
};

View File

@@ -44,6 +44,20 @@ function* remove(name, usernames) {
return yield mysql.query(REMOVE_SQL, [name, usernames]);
}
var REMOVE_ALL_SQL = 'DELETE FROM module_maintainer WHERE name = ?';
exports.removeAll = function* (name) {
return yield mysql.query(REMOVE_ALL_SQL, [name]);
};
exports.addMulti = function* (name, usernames) {
var tasks = [];
for (var i = 0; i < usernames.length; i++) {
tasks.push(add(name, usernames[i]));
}
return yield tasks;
};
exports.update = function* (name, maintainers) {
// maintainers should be [name1, name2, ...] format
// find out the exists maintainers then remove the deletes and add the left
@@ -64,11 +78,8 @@ exports.update = function* (name, maintainers) {
}
}
}
var tasks = [];
for (var i = 0; i < addUsers.length; i++) {
tasks.push(add(name, addUsers[i]));
}
yield tasks;
yield* exports.addMulti(name, addUsers);
// make sure all add users success then remove users
if (removeUsers.length > 0) {
yield* remove(name, removeUsers);

View File

@@ -14,7 +14,7 @@
* Module dependencies.
*/
var urllib = require('co-urllib');
var urllib = require('../common/urllib');
var config = require('../config');
var USER_AGENT = 'cnpmjs.org/' + config.version + ' ' + urllib.USER_AGENT;
@@ -30,7 +30,7 @@ function* request(url, options) {
url = registry + url;
var r;
try {
r = yield* urllib.request(url, options);
r = yield urllib.request(url, options);
} catch (err) {
var statusCode = err.status || -1;
var data = err.data || '[empty]';

View File

@@ -0,0 +1,54 @@
/**!
* cnpmjs.org - proxy/npm_module_maintainer.js
*
* Copyright(c) fengmk2 and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
*/
'use strict';
/**
* Module dependencies.
*/
var mysql = require('../common/mysql');
exports.add = function* (name, username) {
var sql = 'INSERT INTO npm_module_maintainer(name, user, gmt_create) \
VALUES (?, ?, now());';
try {
yield mysql.query(sql, [name, username]);
} catch (err) {
if (err.code !== 'ER_DUP_ENTRY') {
throw err;
}
}
};
exports.remove = function* (name, username) {
var sql = 'DELETE FROM npm_module_maintainer WHERE name = ? AND user = ?;';
return yield mysql.query(sql, [name, username]);
};
exports.removeAll = function* (name) {
var sql = 'DELETE FROM npm_module_maintainer WHERE name = ?;';
return yield mysql.query(sql, [name]);
};
exports.list = function* (name) {
var sql = 'SELECT user FROM npm_module_maintainer WHERE name = ?;';
return yield mysql.query(sql, [name]);
};
exports.listByUsers = function* (users) {
var sql = 'SELECT name, user FROM npm_module_maintainer WHERE user = ?;';
var args = users;
if (users.length > 1) {
sql = 'SELECT name, user FROM npm_module_maintainer WHERE user in (?);';
args = [users];
}
return yield mysql.query(sql, args);
};

View File

@@ -25,7 +25,8 @@ var util = require('util');
var fs = require('fs');
var path = require('path');
var crypto = require('crypto');
var urllib = require('co-urllib');
var sleep = require('co-sleep');
var urllib = require('../common/urllib');
var utility = require('utility');
var ms = require('ms');
var urlparse = require('url').parse;
@@ -39,6 +40,7 @@ var config = require('../config');
var ModuleStar = require('./module_star');
var User = require('./user');
var ModuleUnpublished = require('./module_unpublished');
var NpmModuleMaintainer = require('./npm_module_maintainer');
var USER_AGENT = 'sync.cnpmjs.org/' + config.version + ' ' + urllib.USER_AGENT;
@@ -62,6 +64,7 @@ function SyncModuleWorker(options) {
this.nameMap[name] = true;
}.bind(this));
this.noDep = options.noDep; //do not sync dependences
this.syncDevDependencies = config.syncDevDependencies;
this.successes = [];
this.fails = [];
@@ -76,12 +79,14 @@ SyncModuleWorker.prototype.finish = function () {
if (this._finished || Object.keys(this.syncingNames).length > 0) {
return;
}
this._finished = true;
this.log('[done] Sync %s module finished, %d success, %d fail\nSuccess: [ %s ]\nFail: [ %s ]',
this.startName,
this.successes.length, this.fails.length,
this.successes.join(', '), this.fails.join(', '));
this.emit('end');
this._finished = true;
// make sure all event listeners release
this.removeAllListeners();
};
SyncModuleWorker.prototype.log = function (format, arg1, arg2) {
@@ -93,11 +98,16 @@ SyncModuleWorker.prototype.log = function (format, arg1, arg2) {
SyncModuleWorker.prototype.start = function () {
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);
var self = this;
var that = this;
co(function *() {
// sync upstream
if (config.sourceNpmRegistryIsCNpm) {
yield* that.syncUpstream(that.startName);
}
var arr = [];
for (var i = 0; i < self.concurrency; i++) {
arr.push(self.next(i));
for (var i = 0; i < that.concurrency; i++) {
arr.push(that.next(i));
}
yield arr;
})();
@@ -124,6 +134,8 @@ SyncModuleWorker.prototype.add = function (name) {
};
SyncModuleWorker.prototype._doneOne = function* (concurrencyId, name, success) {
this.log('----------------- Synced %s %s -------------------',
name, success ? 'success' : 'fail');
if (success) {
this.pushSuccess(name);
} else {
@@ -133,11 +145,77 @@ SyncModuleWorker.prototype._doneOne = function* (concurrencyId, name, success) {
var that = this;
// relase the stack: https://github.com/cnpm/cnpmjs.org/issues/328
defer.setImmediate(function *() {
that.log('[c#%s] setImmediate after, %s done, start next...', concurrencyId, name);
yield *that.next(concurrencyId);
});
};
SyncModuleWorker.prototype.syncUpstream = function* (name) {
var url = config.sourceNpmRegistry + '/' + name + '/sync';
if (this.noDep) {
url += '?nodeps=true';
}
var r = yield urllib.request(url, {
method: 'put',
timeout: 20000,
headers: {
'content-length': 0
},
dataType: 'json'
});
if (r.status !== 201 || !r.data.ok) {
return this.log('sync upstream %s error, status: %s, response: %j',
url, r.status, r.data);
}
var logURL = config.sourceNpmRegistry + '/' + name + '/sync/log/' + r.data.logId;
var offset = 0;
this.log('----------------- Syncing upstream %s -------------------', logURL);
var count = 0;
while (true) {
count++;
var synclogURL = logURL + '?offset=' + offset;
var rs = yield urllib.request(synclogURL, {
timeout: 20000,
dataType: 'json'
});
if (rs.status !== 200 || !rs.data.ok) {
this.log('sync upstream %s error, status: %s, response: %j',
synclogURL, rs.status, rs.data);
break;
}
var data = rs.data;
var syncDone = false;
if (data.log && data.log.indexOf('[done] Sync') >= 0) {
syncDone = true;
data.log = data.log.replace('[done] Sync', '[Upstream done] Sync');
}
if (data.log) {
this.log(data.log);
}
if (syncDone) {
break;
}
if (count >= 30) {
this.log('sync upstream %s fail, give up', logURL);
break;
}
if (data.log) {
offset += data.log.split('\n').length;
}
yield sleep(2000);
}
this.log('----------------- Synced upstream %s -------------------', logURL);
};
SyncModuleWorker.prototype.next = function *(concurrencyId) {
var name = this.names.shift();
if (!name) {
@@ -148,6 +226,9 @@ SyncModuleWorker.prototype.next = function *(concurrencyId) {
that.syncingNames[name] = true;
var pkg = null;
var status = 0;
this.log('----------------- Syncing %s -------------------', name);
// get from npm
try {
var result = yield npm.request('/' + name);
@@ -203,9 +284,9 @@ SyncModuleWorker.prototype.next = function *(concurrencyId) {
return;
}
that.log('[c#%d] [%s] synced success, %d versions: %s',
this.log('[c#%d] [%s] synced success, %d versions: %s',
concurrencyId, name, versions.length, versions.join(', '));
yield* that._doneOne(concurrencyId, name, true);
yield* this._doneOne(concurrencyId, name, true);
};
function *_listStarUsers(modName) {
@@ -229,6 +310,14 @@ function *_saveNpmUser(username) {
yield User.saveNpmUser(user);
}
function *_saveMaintainer(modName, username, action) {
if (action === 'add') {
yield* NpmModuleMaintainer.add(modName, username);
} else if (action === 'remove') {
yield* NpmModuleMaintainer.remove(modName, username);
}
}
SyncModuleWorker.prototype._unpublished = function* (name, unpublishedInfo) {
var mods = yield Module.listByName(name);
this.log(' [%s] start unpublished %d versions from local cnpm registry',
@@ -291,11 +380,13 @@ SyncModuleWorker.prototype._sync = function* (name, pkg) {
var result = yield [
Module.listByName(name),
Module.listTags(name),
_listStarUsers(name)
_listStarUsers(name),
NpmModuleMaintainer.list(name),
];
var moduleRows = result[0];
var tagRows = result[1];
var existsStarUsers = result[2];
var existsNpmMaintainers = result[3];
if (that._isLocalModule(moduleRows)) {
// publish on cnpm, dont sync this version package
@@ -339,6 +430,40 @@ SyncModuleWorker.prototype._sync = function* (name, pkg) {
var missingReadmes = [];
var missingStarUsers = [];
var npmUsernames = {};
var missingDeprecateds = [];
// [[user, 'add or remove'], ...]
var diffNpmMaintainers = [];
// find out new maintainers
var pkgMaintainers = pkg.maintainers || [];
if (Array.isArray(pkgMaintainers)) {
var existsMap = {};
var originalMap = {};
for (var i = 0; i < existsNpmMaintainers.length; i++) {
var item = existsNpmMaintainers[i];
existsMap[item.user] = item;
}
for (var i = 0; i < pkgMaintainers.length; i++) {
var item = pkgMaintainers[i];
originalMap[item.name] = item;
}
// find add users
for (var i = 0; i < pkgMaintainers.length; i++) {
var item = pkgMaintainers[i];
if (!existsMap[item.name]) {
diffNpmMaintainers.push([item.name, 'add']);
}
}
// find remove users
for (var i = 0; i < existsNpmMaintainers.length; i++) {
var item = existsNpmMaintainers[i];
if (!originalMap[item.user]) {
diffNpmMaintainers.push([item.user, 'remove']);
}
}
}
// find out all user names
for (var v in pkg.versions) {
@@ -428,8 +553,9 @@ SyncModuleWorker.prototype._sync = function* (name, pkg) {
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) {
if (exists.package &&
exists.package.dist.shasum === version.dist.shasum &&
exists.author === sourceAuthor) {
// * author make sure equal
// * shasum make sure equal
if ((version.publish_time === exists.publish_time) ||
@@ -452,6 +578,14 @@ SyncModuleWorker.prototype._sync = function* (name, pkg) {
readme: version.readme
});
}
if (version.deprecated && version.deprecated !== exists.package.deprecated) {
// need to sync deprecated field
missingDeprecateds.push({
id: exists.id,
deprecated: version.deprecated
});
}
continue;
}
}
@@ -508,7 +642,7 @@ SyncModuleWorker.prototype._sync = function* (name, pkg) {
syncedVersionNames.push(syncModule.version);
} catch (err) {
that.log(' [%s:%d] sync error, version: %s, %s: %s',
syncModule.name, index, syncModule.version, err.name, err.message);
syncModule.name, index, syncModule.version, err.name, err.stack);
}
}
@@ -602,6 +736,29 @@ SyncModuleWorker.prototype._sync = function* (name, pkg) {
}
}
function *syncDeprecateds() {
if (missingDeprecateds.length === 0) {
return;
}
that.log(' [%s] saving %d Deprecated fields', name, missingDeprecateds.length);
var res = yield gather(missingDeprecateds.map(function (item) {
return Module.updatePackageFields(item.id, {
deprecated: item.deprecated
});
}));
for (var i = 0; i < res.length; i++) {
var item = missingDeprecateds[i];
var r = res[i];
if (r.error) {
that.log(' save error, id: %s, error: %s', item.id, r.error.message);
} else {
that.log(' saved, id: %s', item.id);
}
}
}
function *syncMissingUsers() {
var missingUsers = [];
var names = Object.keys(npmUsernames);
@@ -658,7 +815,35 @@ SyncModuleWorker.prototype._sync = function* (name, pkg) {
}
}
yield [syncDes(), syncTag(), syncReadme(), syncMissingStarUsers(), syncMissingUsers()];
// sync diff npm package maintainers
function* syncNpmPackageMaintainers() {
if (diffNpmMaintainers.length === 0) {
return;
}
that.log(' [%s] syncing %d diff package maintainers: %j',
name, diffNpmMaintainers.length, diffNpmMaintainers);
var res = yield gather(diffNpmMaintainers.map(function (item) {
return _saveMaintainer(name, item[0], item[1]);
}));
for (var i = 0; i < res.length; i++) {
var r = res[i];
if (r.error) {
that.log(' save package maintainer error, %s', r.error.message);
}
}
}
yield [
syncDes(),
syncTag(),
syncReadme(),
syncDeprecateds(),
syncMissingStarUsers(),
syncMissingUsers(),
syncNpmPackageMaintainers(),
];
return syncedVersionNames;
};
@@ -680,13 +865,17 @@ SyncModuleWorker.prototype._syncOneVersion = function *(versionIndex, sourcePack
};
var dependencies = Object.keys(sourcePackage.dependencies || {});
var devDependencies = Object.keys(sourcePackage.devDependencies || {});
var devDependencies = [];
if (this.syncDevDependencies) {
devDependencies = Object.keys(sourcePackage.devDependencies || {});
}
that.log(' [%s:%d] syncing, version: %s, dist: %j, no deps: %s, ' +
'publish on cnpm: %s, dependencies: %d, devDependencies: %d',
'publish on cnpm: %s, dependencies: %d, devDependencies: %d, syncDevDependencies: %s',
sourcePackage.name, versionIndex, sourcePackage.version,
sourcePackage.dist, that.noDep, that._publish,
dependencies.length, devDependencies.length);
dependencies.length,
devDependencies.length, this.syncDevDependencies);
if (dependencies.length > config.maxDependencies) {
dependencies = dependencies.slice(0, config.maxDependencies);
@@ -720,7 +909,7 @@ SyncModuleWorker.prototype._syncOneVersion = function *(versionIndex, sourcePack
try {
// get tarball
var r = yield *urllib.request(downurl, options);
var r = yield urllib.request(downurl, options);
var statusCode = r.status || -1;
// https://github.com/cnpm/cnpmjs.org/issues/325
// if (statusCode === 404) {
@@ -829,21 +1018,6 @@ SyncModuleWorker.prototype._syncOneVersion = function *(versionIndex, sourcePack
SyncModuleWorker.sync = function* (name, username, options) {
options = options || {};
var result = yield npm.request('/' + name);
var pkg = result.data;
if (result.status === 404 &&
(!pkg.time || !pkg.time.unpublished || !pkg.time.unpublished.time)) {
pkg = null;
}
if (!pkg || !pkg._id) {
return {
ok: false,
pkg: pkg,
statusCode: 404
};
}
var result = yield Log.create({name: name, username: username});
var worker = new SyncModuleWorker({
logId: result.id,
@@ -853,9 +1027,5 @@ SyncModuleWorker.sync = function* (name, username, options) {
publish: options.publish,
});
worker.start();
return {
ok: true,
logId: result.id,
pkg: pkg
};
return result.id;
};

View File

@@ -23,6 +23,7 @@ var total = require('../controllers/total');
var mod = require('../controllers/registry/module');
var user = require('../controllers/registry/user');
var sync = require('../controllers/sync');
var userPackage = require('../controllers/registry/user_package');
function routes(app) {
@@ -64,6 +65,8 @@ function routes(app) {
// need limit by ip
app.get(/^\/(@[\w\-\.]+\/[\w\-\.]+)\/download\/(@[\w\-\.]+\/[\w\-\.]+)$/, limit, mod.download);
app.get('/:name/download/:filename', limit, mod.download);
app.get(/^\/(@[\w\-\.]+\/[\w\-\.]+)\/\-\/(@[\w\-\.]+\/[\w\-\.]+)$/, limit, mod.download);
app.get('/:name/-/:filename', limit, mod.download);
// delete tarball
app.delete(/^\/(@[\w\-\.]+\/[\w\-\.]+)\/download\/(@[\w\-\.]+\/[\w\-\.]+)\/\-rev\/([\w\-\.]+)$/,
@@ -81,6 +84,9 @@ function routes(app) {
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);
// list all packages of user
app.get('/-/by-user/:user', userPackage.list);
}
module.exports = routes;

View File

@@ -20,6 +20,7 @@ var user = require('../controllers/web/user');
var sync = require('../controllers/sync');
var total = require('../controllers/total');
var dist = require('../controllers/web/dist');
var badge = require('../controllers/web/badge');
function routes(app) {
app.get('/total', total.show);
@@ -51,6 +52,8 @@ function routes(app) {
app.get('/_list/search/search', pkg.rangeSearch);
app.get(/^\/dist(\/.*)?/, dist.list);
app.get(/^\/badge\/v\/([@\w\-\.\/]+)\.svg$/, badge.version);
}
module.exports = routes;

View File

@@ -105,6 +105,7 @@ routes(app);
app.on('error', function (err, ctx) {
err.url = err.url || ctx.request.url;
console.log(err.stack);
logger.error(err);
});

View File

@@ -36,6 +36,10 @@ exports.listMaintainerNamesOnly = function* (name) {
return yield* ModuleMaintainer.get(name);
};
exports.addMaintainers = function* (name, usernames) {
return yield* ModuleMaintainer.addMulti(name, usernames);
};
exports.updateMaintainers = function* (name, usernames) {
var rs = yield [
ModuleMaintainer.update(name, usernames),
@@ -44,20 +48,17 @@ exports.updateMaintainers = function* (name, usernames) {
return rs[0];
};
exports.isMaintainer = function* (name, username) {
exports.removeAllMaintainers = function* (name) {
return yield* ModuleMaintainer.removeAll(name);
};
exports.authMaintainer = function* (packageName, username) {
var rs = yield [
ModuleMaintainer.get(name),
Module.getLatest(name)
ModuleMaintainer.get(packageName),
Module.getLatest(packageName)
];
var maintainers = rs[0];
var latestMod = rs[1];
if (latestMod && !latestMod.package._publish_on_cnpm) {
// no one can update public package maintainers
// public package only sync from source npm registry
return false;
}
if (maintainers.length === 0) {
// if not found maintainers, try to get from latest module package info
var ms = latestMod && latestMod.package && latestMod.package.maintainers;
@@ -67,9 +68,27 @@ exports.isMaintainer = function* (name, username) {
});
}
}
if (maintainers.length === 0) {
var isMaintainer = false;
if (latestMod && !latestMod.package._publish_on_cnpm) {
// no one can update public package maintainers
// public package only sync from source npm registry
isMaintainer = false;
} else if (maintainers.length === 0) {
// no maintainers, meaning this module is free for everyone
return true;
isMaintainer = true;
} else if (maintainers.indexOf(username) >= 0) {
isMaintainer = true;
}
return maintainers.indexOf(username) >= 0;
return {
isMaintainer: isMaintainer,
maintainers: maintainers
};
};
exports.isMaintainer = function* (name, username) {
var result = yield* exports.authMaintainer(name, username);
return result.isMaintainer;
};

View File

@@ -15,7 +15,6 @@
*/
var debug = require('debug')('cnpmjs.org:sync:sync_all');
var eventproxy = require('eventproxy');
var ms = require('ms');
var utility = require('utility');
var config = require('../config');

View File

@@ -16,7 +16,7 @@
var debug = require('debug')('cnpmjs.org:sync:sync_dist');
var fs = require('fs');
var urllib = require('co-urllib');
var urllib = require('../common/urllib');
var co = require('co');
var bytes = require('bytes');
var crypto = require('crypto');
@@ -37,6 +37,9 @@ module.exports = sync;
function* sync(name) {
name = name || '/';
if (name[name.length - 1] !== '/') {
name += '/';
}
yield* syncDir(name);
}
@@ -100,7 +103,7 @@ function* syncFile(info) {
logger.syncInfo('downloading %s %s to %s, isPhantomjsURL: %s',
bytes(info.size), downurl, filepath, isPhantomjsURL);
// get tarball
var r = yield *urllib.request(downurl, options);
var r = yield urllib.request(downurl, options);
var statusCode = r.status || -1;
logger.syncInfo('download %s got status %s, headers: %j',
downurl, statusCode, r.headers);
@@ -136,7 +139,7 @@ function* syncFile(info) {
throw err;
}
info.size = dataSize;
} else if (dataSize !== info.size) {
} else if (info.size > 0 && dataSize !== info.size) {
var err = new Error('Download ' + downurl + ' file size is '
+ dataSize + ' not match ' + info.size);
err.name = 'DownloadDistFileSizeError';
@@ -171,40 +174,146 @@ function* syncFile(info) {
// <a href="node-v0.4.10.tar.gz">node-v0.4.10.tar.gz</a> 26-Aug-2011 16:22 12410018
var FILE_RE = /^<a[^>]+>([^<]+)<\/a>\s+(\d+\-\w+\-\d+ \d+\:\d+)\s+([\-\d]+)/;
// */docs/api/
var DOC_API_RE = /\/docs\/api\/$/;
// <li><a href="documentation.html">About these Docs</a></li>
// <li><a href="synopsis.html">Synopsis</a></li>
// <li><a href="assert.html">Assertion Testing</a></li>
// <li><a href="buffer.html">Buffer</a></li>
// <li><a href="addons.html">C/C++ Addons</a></li>
// <li><a href="child_process.html">Child Processes</a></li>
// <div id="gtoc">
// <p>
// <a href="index.html" name="toc">Index</a> |
// <a href="all.html">View on single page</a> |
// <a href="index.json">View as JSON</a>
// </p>
// </div>
var DOC_API_FILE_ALL_RE = /<a[^"]+\"(\w+\.(?:html|json))\"[^>]*>[^<]+<\/a>/gm;
var DOC_API_FILE_RE = /<a[^"]+\"(\w+\.(?:html|json))\"[^>]*>[^<]+<\/a>/;
function* listdir(fullname) {
var url = disturl + fullname;
var result = yield* urllib.request(url, {
var isDocPath = false;
if (DOC_API_RE.test(fullname)) {
isDocPath = true;
url += 'index.html';
}
var result = yield urllib.request(url, {
timeout: 60000,
});
debug('listdir %s got %s, %j', url, result.status, result.headers);
var html = result.data && result.data.toString() || '';
var lines = html.split('\n');
var items = [];
for (var i = 0; i < lines.length; i++) {
var m = FILE_RE.exec(lines[i].trim());
if (!m) {
continue;
}
var itemName = m[1].replace(/^\/+/, '');
if (!itemName) {
continue;
}
// "last-modified":"Tue, 11 Mar 2014 22:44:36 GMT"
var date = result.headers['last-modified'] || result.headers.date || '';
// filter /nightlies/*
if (itemName.indexOf('nightlies/') === 0) {
continue;
if (isDocPath) {
// add assets/
items.push({
name: 'assets/',
date: date,
size: '-',
type: 'dir',
parent: fullname,
});
var needJSON = false;
var htmlfileNames = [];
var lines = html.match(DOC_API_FILE_ALL_RE) || [];
for (var i = 0; i < lines.length; i++) {
var m = DOC_API_FILE_RE.exec(lines[i].trim());
if (!m) {
continue;
}
var itemName = m[1];
items.push({
name: itemName,
date: date,
size: 0,
type: 'file',
parent: fullname,
});
if (itemName.indexOf('.json') > 0) {
needJSON = true;
}
if (itemName.indexOf('.html') > 0 && itemName !== 'index.html') {
htmlfileNames.push(itemName);
}
}
debug('listdir %s got %j', fullname, htmlfileNames);
if (needJSON) {
// node >= 0.8.0
htmlfileNames.forEach(function (itemName) {
items.push({
name: itemName.replace('.html', '.json'), // download *.json format
date: date,
size: 0,
type: 'file',
parent: fullname,
});
});
}
} else {
var lines = html.split('\n');
for (var i = 0; i < lines.length; i++) {
var m = FILE_RE.exec(lines[i].trim());
if (!m) {
continue;
}
var itemName = m[1].replace(/^\/+/, '');
if (!itemName) {
continue;
}
// filter /nightlies/*
if (itemName.indexOf('nightlies/') === 0) {
continue;
}
items.push({
name: itemName, // 'SHASUMS.txt', 'x64/'
date: m[2],
size: m[3] === '-' ? '-' : parseInt(m[3]),
type: m[3] === '-' ? 'dir' : 'file',
parent: fullname, // '/', '/v0.10.28/'
});
}
}
// node <= v0.11.11, /docs/ is not list, has a index.html
if (items.length === 0 && /\/docs\/$/.test(fullname)) {
items.push({
name: 'api/',
date: date,
size: '-',
type: 'dir',
parent: fullname,
});
// sh_main.js
// sh_javascript.min.js
items.push({
name: 'sh_main.js',
date: date,
size: 0,
type: 'file',
parent: fullname,
});
items.push({
name: itemName, // 'SHASUMS.txt', 'x64/'
date: m[2],
size: m[3] === '-' ? '-' : parseInt(m[3]),
type: m[3] === '-' ? 'dir' : 'file',
parent: fullname, // '/', '/v0.10.28/'
name: 'sh_javascript.min.js',
date: date,
size: 0,
type: 'file',
parent: fullname,
});
}
return items;
}
sync.listdir = listdir;
sync.listdiff = function* (fullname) {
var items = yield* listdir(fullname);
@@ -270,7 +379,7 @@ sync.syncPhantomjsDir = syncPhantomjsDir;
function* listPhantomjsDir(fullname) {
var url = 'https://bitbucket.org/ariya/phantomjs/downloads';
var result = yield* urllib.request(url, {
var result = yield urllib.request(url, {
timeout: 60000,
});
debug('listPhantomjsDir %s got %s, %j', url, result.status, result.headers);

View File

@@ -18,9 +18,8 @@ var config = require('../config');
var Npm = require('../proxy/npm');
var Module = require('../proxy/module');
var Total = require('../proxy/total');
var eventproxy = require('eventproxy');
var SyncModuleWorker = require('../proxy/sync_module_worker');
var debug = require('debug')('cnpmjs.org:sync:sync_hot');
var debug = require('debug')('cnpmjs.org:sync:sync_exist');
var utility = require('utility');
var Status = require('./status');
var ms = require('ms');

View File

@@ -0,0 +1,211 @@
/**!
* cnpmjs.org - test/controllers/registry/deprecate.test.js
*
* Copyright(c) cnpmjs.org and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
*/
'use strict';
/**
* Module dependencies.
*/
var fs = require('fs');
var path = require('path');
var should = require('should');
var request = require('supertest');
var mm = require('mm');
var pedding = require('pedding');
var app = require('../../../servers/registry');
var utils = require('../../utils');
var fixtures = path.join(path.dirname(path.dirname(__dirname)), 'fixtures');
describe('controllers/registry/deprecate.test.js', function () {
var pkgname = 'testmodule-deprecate';
before(function (done) {
done = pedding(2, done);
var pkg = utils.getPackage(pkgname, '0.0.1', utils.admin);
request(app.listen())
.put('/' + pkgname)
.set('authorization', utils.adminAuth)
.send(pkg)
.expect(201, function (err) {
should.not.exist(err);
pkg = utils.getPackage(pkgname, '0.0.2', utils.admin);
// publish 0.0.2
request(app.listen())
.put('/' + pkgname)
.set('authorization', utils.adminAuth)
.send(pkg)
.expect(201, done);
});
pkg = utils.getPackage(pkgname, '1.0.0', utils.admin);
request(app.listen())
.put('/' + pkgname)
.set('authorization', utils.adminAuth)
.send(pkg)
.expect(201, done);
});
afterEach(mm.restore);
describe('PUT /:name', function () {
it('should deprecate version@1.0.0', function (done) {
request(app.listen())
.put('/' + pkgname)
.set('authorization', utils.adminAuth)
.send({
name: pkgname,
versions: {
'1.0.0': {
deprecated: 'mock test deprecated message 1.0.0'
}
}
})
.expect({
ok: true
})
.expect(201, function (err, res) {
should.not.exist(err);
request(app.listen())
.get('/' + pkgname + '/1.0.0')
.expect(200, function (err, res) {
should.not.exist(err);
res.body.deprecated.should.equal('mock test deprecated message 1.0.0');
// undeprecated
request(app.listen())
.put('/' + pkgname)
.set('authorization', utils.adminAuth)
.send({
name: pkgname,
versions: {
'1.0.0': {
deprecated: ''
}
}
})
.expect({
ok: true
})
.expect(201, function (err) {
should.not.exist(err);
request(app.listen())
.get('/' + pkgname + '/1.0.0')
.expect(200, function (err, res) {
should.not.exist(err);
res.body.deprecated.should.equal('');
done();
});
});
});
});
});
it('should deprecate version@<1.0.0', function (done) {
request(app.listen())
.put('/' + pkgname)
.set('authorization', utils.adminAuth)
.send({
name: pkgname,
versions: {
'1.0.0': {
version: '1.0.0'
},
'0.0.1': {
deprecated: 'mock test deprecated message 0.0.1'
},
'0.0.2': {
deprecated: 'mock test deprecated message 0.0.2'
}
}
})
.expect({
ok: true
})
.expect(201, function (err, res) {
should.not.exist(err);
done = pedding(3, done);
request(app.listen())
.get('/' + pkgname + '/0.0.1')
.expect(200, function (err, res) {
should.not.exist(err);
res.body.deprecated.should.equal('mock test deprecated message 0.0.1');
done();
});
request(app.listen())
.get('/' + pkgname + '/0.0.2')
.expect(200, function (err, res) {
should.not.exist(err);
res.body.deprecated.should.equal('mock test deprecated message 0.0.2');
done();
});
// not change 1.0.0
request(app.listen())
.get('/' + pkgname + '/1.0.0')
.expect(200, function (err, res) {
should.not.exist(err);
res.body.deprecated.should.equal('');
done();
});
});
});
it('should 404 deprecate not exists version', function (done) {
request(app.listen())
.put('/' + pkgname)
.set('authorization', utils.adminAuth)
.send({
name: pkgname,
versions: {
'1.0.1': {
deprecated: 'mock test deprecated message'
},
'1.0.0': {
deprecated: 'mock test deprecated message'
}
}
})
.expect({
error: 'version_error',
reason: 'Some versions: ["1.0.1","1.0.0"] not found'
})
.expect(400, done);
});
it('should 403', function (done) {
request(app.listen())
.put('/' + pkgname)
.set('authorization', utils.otherUserAuth)
.send({
name: pkgname,
versions: {
'1.0.0': {
version: '1.0.0'
},
'0.0.1': {
deprecated: 'mock test deprecated message 0.0.1'
},
'0.0.2': {
deprecated: 'mock test deprecated message 0.0.2'
}
}
})
.expect({
error: 'no_perms',
reason: 'Private mode enable, only admin can publish this module'
})
.expect(403, done);
});
});
});

View File

@@ -30,6 +30,7 @@ var controller = require('../../../controllers/registry/module');
var ModuleDeps = require('../../../proxy/module_deps');
var SyncModuleWorker = require('../../../proxy/sync_module_worker');
var utils = require('../../utils');
var mysql = require('../../../common/mysql');
var fixtures = path.join(path.dirname(path.dirname(__dirname)), 'fixtures');
@@ -73,7 +74,7 @@ describe('controllers/registry/module.test.js', function () {
it('should put /:name/sync success', function (done) {
mm.data(Npm, 'get', require(path.join(fixtures, 'utility.json')));
request(app)
.put('/utility/sync')
.put('/pedding/sync')
.set('authorization', utils.adminAuth)
.end(function (err, res) {
should.not.exist(err);
@@ -85,7 +86,7 @@ describe('controllers/registry/module.test.js', function () {
it('should get sync log', function (done) {
request(app)
.get('/utility/sync/log/' + logId)
.get('/pedding/sync/log/' + logId)
.end(function (err, res) {
should.not.exist(err);
res.body.should.have.keys('ok', 'log');
@@ -476,7 +477,7 @@ describe('controllers/registry/module.test.js', function () {
.send(pkg)
.expect(400, function (err, res) {
should.not.exist(err);
res.body.reason.should.containEql('filename or version not found');
res.body.reason.should.equal('version undefined not found');
done();
});
});
@@ -501,7 +502,7 @@ describe('controllers/registry/module.test.js', function () {
should.not.exist(err);
res.body.should.eql({
error: 'version_error',
reason: 'filename or version not found, filename: undefined, version: undefined'
reason: 'version undefined not found'
});
done();
});
@@ -532,7 +533,8 @@ describe('controllers/registry/module.test.js', function () {
describe('PUT /:name publish new flow addPackageAndDist()', function () {
it('should publish with tgz base64, addPackageAndDist()', function (done) {
var pkg = utils.getPackage('testpublishmodule', '0.0.2');
done = pedding(2, done);
var pkg = utils.getPackage('testpublishmodule-new-add', '0.0.2');
request(app)
.put('/' + pkg.name)
.set('authorization', utils.adminAuth)
@@ -555,6 +557,43 @@ describe('controllers/registry/module.test.js', function () {
});
done();
});
// maintainers should exists
mysql.query('SELECT user FROM module_maintainer WHERE name=?', ['testpublishmodule-new-add'],
function (err, rows) {
should.not.exist(err);
rows.length.should.above(0);
rows.should.eql([ { user: 'cnpmjstest10' } ]);
done();
});
});
});
it('should 403 when user is not maintainer', function (done) {
mm(config, 'enablePrivate', false);
var pkg = utils.getPackage('@cnpmtest/testpublishmodule-not-maintainer', '0.0.1');
request(app)
.put('/' + pkg.name)
.set('authorization', utils.adminAuth)
.send(pkg)
.expect(201, function (err, res) {
should.not.exist(err);
res.body.should.have.keys('ok', 'rev');
res.body.ok.should.equal(true);
// upload again should 403
request(app)
.put('/' + pkg.name)
.set('authorization', utils.otherUserAuth)
.send(pkg)
.expect(403, function (err, res) {
should.not.exist(err);
res.body.should.eql({
error: 'forbidden user',
reason: 'cnpmjstest101 not authorized to modify @cnpmtest/testpublishmodule-not-maintainer, please contact maintainers: cnpmjstest10'
});
done();
});
});
});
@@ -569,7 +608,7 @@ describe('controllers/registry/module.test.js', function () {
should.not.exist(err);
res.body.should.eql({
error: 'version_error',
reason: 'filename or version not found, filename: mk2testmodule-0.0.1.tgz, version: undefined'
reason: 'version undefined not found'
});
done();
});
@@ -768,11 +807,16 @@ describe('controllers/registry/module.test.js', function () {
});
describe('GET /:name/download/:filename', function () {
it('should download a file with 302 redirect', function (done) {
it('should download a file with 200', function (done) {
request(app)
.get('/cutter/download/cutter-0.0.2.tgz')
.expect('Location', config.qn.domain + '/cutter/-/cutter-0.0.2.tgz')
.expect(302, done);
.get('/mk2testmodule/download/mk2testmodule-0.0.1.tgz')
.expect(200, done);
});
it('should alias /:name/-/:filename to /:name/download/:filename', function (done) {
request(app)
.get('/mk2testmodule/-/mk2testmodule-0.0.1.tgz')
.expect(200, done);
});
});
@@ -922,7 +966,7 @@ describe('controllers/registry/module.test.js', function () {
.expect(201, done);
});
it('shold fail when user not maintainer', function (done) {
it('should fail when user not maintainer', function (done) {
request(app)
.del('/remove-all-module/-rev/1')
.set('authorization', utils.otherUserAuth)
@@ -936,14 +980,19 @@ describe('controllers/registry/module.test.js', function () {
});
});
it('shold ok', function (done) {
it('should remove all versions ok', function (done) {
request(app)
.del('/remove-all-module/-rev/1')
.set('authorization', utils.adminAuth)
.expect(200, function (err, res) {
should.not.exist(err);
should.not.exist(res.headers['set-cookie']);
done();
mysql.query('SELECT * FROM module_maintainer WHERE name=?', ['remove-all-module'],
function (err, rows) {
should.not.exist(err);
rows.should.length(0);
done();
});
});
});
});

View File

@@ -560,7 +560,7 @@ describe('controllers/registry/module/public_module.test.js', function () {
mm(config, 'enablePrivate', false);
mm(config, 'forcePublishWithScope', false);
});
before(function (done) {
beforeEach(function (done) {
mm(config, 'enablePrivate', false);
mm(config, 'forcePublishWithScope', false);
var pkg = utils.getPackage('public-test-delete-download-module', '0.1.9', utils.otherUser);
@@ -569,9 +569,11 @@ describe('controllers/registry/module/public_module.test.js', function () {
.set('content-type', 'application/json')
.set('authorization', utils.otherUserAuth)
.send(pkg)
.expect(201, function (err, res) {
.end(function (err, res) {
should.not.exist(err);
withoutScopeRev = res.body.rev;
if (res.body.rev) {
withoutScopeRev = res.body.rev;
}
done();
});
});
@@ -603,7 +605,7 @@ describe('controllers/registry/module/public_module.test.js', function () {
mm(config, 'enablePrivate', false);
mm(config, 'forcePublishWithScope', true);
});
before(function (done) {
beforeEach(function (done) {
mm(config, 'enablePrivate', false);
mm(config, 'forcePublishWithScope', true);
var pkg = utils.getPackage('@cnpm/public-test-delete-download-module', '0.1.9', utils.otherUser);
@@ -612,9 +614,11 @@ describe('controllers/registry/module/public_module.test.js', function () {
.set('content-type', 'application/json')
.set('authorization', utils.otherUserAuth)
.send(pkg)
.expect(201, function (err, res) {
.end(function (err, res) {
should.not.exist(err);
withScopeRev = res.body.rev;
if (res.body.rev) {
withScopeRev = res.body.rev;
}
done();
});
});

View File

@@ -145,8 +145,7 @@ describe('controllers/registry/module/scope_package.test.js', function () {
it('should download work', function (done) {
request(app)
.get('/@cnpm/test-scope-package/download/@cnpm/test-scope-package-0.0.2.tgz')
.expect('Location', /\.tgz$/)
.expect(302, done);
.expect(200, done);
});
describe('support adaptScope', function () {

View File

@@ -0,0 +1,162 @@
/**!
* cnpmjs.org - test/contributors/registry/user_package.test.js
*
* Copyright(c) fengmk2 and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
*/
'use strict';
/**
* Module dependencies.
*/
var should = require('should');
var request = require('supertest');
var pedding = require('pedding');
var co = require('co');
var app = require('../../../servers/registry');
var SyncModuleWorker = require('../../../proxy/sync_module_worker');
var NpmModuleMaintainer = require('../../../proxy/npm_module_maintainer');
var utils = require('../../utils');
describe('contributors/registry/user_package.test.js', function () {
before(function (done) {
co(function* () {
yield* NpmModuleMaintainer.removeAll('pedding');
})(function (err) {
should.not.exist(err);
// sync pedding
var worker = new SyncModuleWorker({
name: 'pedding',
noDep: true,
});
worker.start();
worker.on('end', function () {
var pkg = utils.getPackage('test-user-package-module', '0.0.1', utils.otherAdmin2);
request(app)
.put('/' + pkg.name)
.set('authorization', utils.otherAdmin2Auth)
.send(pkg)
.expect(201, done);
});
});
});
describe('listOne()', function () {
it('should return one user\'s all package names', function (done) {
request(app.listen())
.get('/-/by-user/fengmk2')
.expect(200)
.expect({
fengmk2: [
'pedding',
]
}, done);
});
it('should return {} when user not exists', function (done) {
request(app.listen())
.get('/-/by-user/user-not-exists')
.expect(200)
.expect({}, done);
});
});
describe('listMulti()', function () {
it('should return two exists user\'s all package names', function (done) {
done = pedding(2, done);
request(app.listen())
.get('/-/by-user/' + encodeURIComponent('fengmk2|dead-horse'))
.expect(200)
.expect({
fengmk2: [
'pedding',
],
'dead-horse': [
'pedding'
]
}, done);
request(app.listen())
.get('/-/by-user/fengmk2|dead-horse')
.expect(200)
.expect({
fengmk2: [
'pedding',
],
'dead-horse': [
'pedding'
]
}, done);
});
it('should return some exists user\'s all package names', function (done) {
done = pedding(2, done);
request(app.listen())
.get('/-/by-user/' + encodeURIComponent('fengmk2|user-not-exists'))
.expect(200)
.expect({
fengmk2: [
'pedding'
]
}, done);
request(app.listen())
.get('/-/by-user/' + utils.otherAdmin2 + '|fengmk2|user-not-exists|')
.expect(200)
.expect({
cnpmjstestAdmin2: [
'test-user-package-module'
],
fengmk2: [
'pedding'
]
}, done);
});
it('should return {} when users not exists', function (done) {
request(app.listen())
.get('/-/by-user/user-not-exists1|user-not-exists2')
.expect(200)
.expect({}, done);
});
it('should return {} when first user name empty', function (done) {
done = pedding(2, done);
request(app.listen())
.get('/-/by-user/|user-not-exists2')
.expect(200)
.expect({}, done);
request(app.listen())
.get('/-/by-user/|')
.expect(200)
.expect({}, done);
});
it('should return 200 when users length equal limit count', function (done) {
request(app.listen())
.get('/-/by-user/n1|n2|n3|n4|n5|n6|n7|n8|n9|n10|n11|n12|n13|n14|n15|n16|n17|n18|n19|n20')
.expect(200, done);
});
it('should return 400 when users reach limit count', function (done) {
request(app.listen())
.get('/-/by-user/n1|n2|n3|n4|n5|n6|n7|n8|n9|n10|n11|n12|n13|n14|n15|n16|n17|n18|n19|n20|n21')
.expect(400)
.expect({
error: 'bad_request',
reason: 'reach max user names limit, must <= 20 user names'
}, done);
});
});
});

View File

@@ -43,14 +43,14 @@ describe('controllers/sync.test.js', function () {
it('should sync as publish success', function (done) {
request(registryApp)
.del('/utility/-rev/123')
.del('/pedding/-rev/123')
.set('authorization', baseauth)
.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')
.put('/pedding/sync?publish=true&nodeps=true')
.set('authorization', baseauth)
.end(function (err, res) {
should.not.exist(err);
@@ -75,7 +75,7 @@ describe('controllers/sync.test.js', function () {
it('should sync through web success', function (done) {
mm.data(Npm, 'get', require(path.join(fixtures, 'utility.json')));
request(webApp)
.put('/sync/utility')
.put('/sync/pedding')
.end(function (err, res) {
should.not.exist(err);
res.body.should.have.keys('ok', 'logId');
@@ -87,7 +87,7 @@ describe('controllers/sync.test.js', function () {
it('should sync through registry success', function (done) {
mm.data(Npm, 'get', require(path.join(fixtures, 'utility.json')));
request(registryApp)
.put('/utility/sync')
.put('/pedding/sync')
.set('authorization', baseauth)
.end(function (err, res) {
should.not.exist(err);
@@ -100,7 +100,7 @@ describe('controllers/sync.test.js', function () {
it('should get sync log', function (done) {
done = pedding(2, done);
request(registryApp)
.get('/utility/sync/log/' + logIdRegistry)
.get('/pedding/sync/log/' + logIdRegistry)
.end(function (err, res) {
should.not.exist(err);
res.body.should.have.keys('ok', 'log');
@@ -108,7 +108,7 @@ describe('controllers/sync.test.js', function () {
});
request(webApp)
.get('/sync/utility/log/' + logIdWeb)
.get('/sync/pedding/log/' + logIdWeb)
.end(function (err, res) {
should.not.exist(err);
res.body.should.have.keys('ok', 'log');

View File

@@ -0,0 +1,108 @@
/*!
* cnpmjs.org - test/controllers/web/badge.test.js
*
* Copyright(c) cnpmjs.org and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
*/
'use strict';
/**
* Module dependencies.
*/
var should = require('should');
var request = require('supertest');
var mm = require('mm');
var path = require('path');
var pedding = require('pedding');
var mysql = require('../../../common/mysql');
var app = require('../../../servers/web');
var registry = require('../../../servers/registry');
var pkg = require('../../../controllers/web/package');
var utils = require('../../utils');
var config = require('../../../config');
var fixtures = path.join(path.dirname(path.dirname(__dirname)), 'fixtures');
describe('controllers/web/badge.test.js', function () {
before(function (done) {
done = pedding(2, done);
registry = registry.listen(0, done);
app = app.listen(0, done);
});
afterEach(mm.restore);
describe('GET /badge/v/:name.svg', function () {
it('should show blue version on >=1.0.0 when package exists', function (done) {
var pkg = utils.getPackage('badge-test-module', '1.0.1', utils.admin);
request(registry)
.put('/' + pkg.name)
.set('authorization', utils.adminAuth)
.send(pkg)
.end(function (err) {
should.not.exists(err);
request(app)
.get('/badge/v/badge-test-module.svg?style=flat-square')
.expect('Location', 'https://img.shields.io/badge/cnpm-1.0.1-blue.svg?style=flat-square')
.expect(302, done);
});
});
it('should support 1.0.0-beta1', function (done) {
var pkg = utils.getPackage('badge-test-module', '1.0.0-beta1', utils.admin);
request(registry)
.put('/' + pkg.name)
.set('authorization', utils.adminAuth)
.send(pkg)
.end(function (err) {
should.not.exists(err);
request(app)
.get('/badge/v/badge-test-module.svg?style=flat-square')
.expect('Location', 'https://img.shields.io/badge/cnpm-1.0.0--beta1-blue.svg?style=flat-square')
.expect(302, done);
});
});
it('should show green version on <1.0.0 & >=0.1.0 when package exists', function (done) {
var pkg = utils.getPackage('badge-test-module', '0.1.0', utils.admin);
request(registry)
.put('/' + pkg.name)
.set('authorization', utils.adminAuth)
.send(pkg)
.end(function (err) {
should.not.exists(err);
request(app)
.get('/badge/v/badge-test-module.svg?style=flat-square')
.expect('Location', 'https://img.shields.io/badge/cnpm-0.1.0-green.svg?style=flat-square')
.expect(302, done);
});
});
it('should show green version on <0.1.0 & >=0.0.0 when package exists', function (done) {
var pkg = utils.getPackage('badge-test-module', '0.0.0', utils.admin);
request(registry)
.put('/' + pkg.name)
.set('authorization', utils.adminAuth)
.send(pkg)
.end(function (err) {
should.not.exists(err);
request(app)
.get('/badge/v/badge-test-module.svg?style=flat-square')
.expect('Location', 'https://img.shields.io/badge/cnpm-0.0.0-red.svg?style=flat-square')
.expect(302, done);
});
});
it('should show invalid when package not exists', function (done) {
request(app)
.get('/badge/v/badge-test-module-not-exists.svg?style=flat')
.expect('Location', 'https://img.shields.io/badge/cnpm-invalid-lightgrey.svg?style=flat')
.expect(302, done);
});
});
});

View File

@@ -18,6 +18,8 @@ var should = require('should');
var request = require('supertest');
var pedding = require('pedding');
var mm = require('mm');
var fs = require('fs');
var nfs = require('../../../common/nfs');
var app = require('../../../servers/web');
var Dist = require('../../../proxy/dist');
@@ -89,36 +91,81 @@ describe('controllers/web/dist.test.js', function () {
});
describe('GET /dist/ files', function () {
it('should redirect to nfs url', function (done) {
it('should pipe txt', function (done) {
mm(Dist, 'getfile', function* () {
return {
name: 'foo.txt', size: 1024, date: '02-May-2014 00:54',
url: 'http://mock.com/dist/v0.10.28/SHASUMS.txt'
};
});
fs.writeFileSync(nfs._getpath('/dist/v0.10.28/SHASUMS.txt'), '6eff580cc8460741155d42ef1ef537961194443f');
request(app)
.get('/dist/v0.10.28/SHASUMS.txt')
.expect(302)
.expect('Location', 'http://mock.com/dist/v0.10.28/SHASUMS.txt', done);
.expect('Content-Type', 'text/plain; charset=utf-8')
.expect(200, function (err, res) {
should.not.exist(err);
should.not.exist(res.headers['Content-Disposition']);
done();
});
});
it('should GET /dist/npm-versions.txt redirect to nfs url', function (done) {
it('should pipe html', function (done) {
mm(Dist, 'getfile', function* () {
return {
name: 'foo.html', size: 1024, date: '02-May-2014 00:54',
url: 'http://mock.com/dist/v0.10.28/foo.html'
};
});
fs.writeFileSync(nfs._getpath('/dist/v0.10.28/foo.html'), '<p>hi</p>');
request(app)
.get('/dist/v0.10.28/foo.html')
.expect('Content-Type', 'text/html; charset=utf-8')
.expect('<p>hi</p>')
.expect(200, function (err, res) {
should.not.exist(err);
should.not.exist(res.headers['Content-Disposition']);
done();
});
});
it('should pipe json', function (done) {
mm(Dist, 'getfile', function* () {
return {
name: 'foo.json', date: '02-May-2014 00:54',
url: 'http://mock.com/dist/v0.10.28/foo.json'
};
});
fs.writeFileSync(nfs._getpath('/dist/v0.10.28/foo.json'), '{}');
request(app)
.get('/dist/v0.10.28/foo.json')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect('{}')
.expect(200, function (err, res) {
should.not.exist(err);
should.not.exist(res.headers['Content-Disposition']);
done();
});
});
it('should GET /dist/npm-versions.tgz redirect to nfs url', function (done) {
mm(Dist, 'getfile', function* (fullname) {
fullname.should.equal('/npm-versions.txt');
fullname.should.equal('/npm-versions.tgz');
return {
name: 'npm-versions.txt', size: 1024, date: '02-May-2014 00:54',
url: 'http://mock.com/dist/npm-versions.txt'
url: 'http://mock.com/dist/npm-versions.tgz'
};
});
request(app)
.get('/dist/npm-versions.txt')
.get('/dist/npm-versions.tgz')
.expect(302)
.expect('Location', 'http://mock.com/dist/npm-versions.txt', done);
.expect('Location', 'http://mock.com/dist/npm-versions.tgz', done);
});
it('should download nfs file and send it', function (done) {
it('should download nfs txt file and send it', function (done) {
mm(Dist, 'getfile', function* () {
return {
name: 'foo.txt',
@@ -127,11 +174,43 @@ describe('controllers/web/dist.test.js', function () {
url: '/dist/v0.10.28/SHASUMS.txt'
};
});
fs.writeFileSync(nfs._getpath('/dist/v0.10.28/SHASUMS.txt'), '6eff580cc8460741155d42ef1ef537961194443f');
request(app)
.get('/dist/v0.10.28/SHASUMS.txt')
.expect(200)
.expect(/6eff580cc8460741155d42ef1ef537961194443f/, done);
});
it('should download nfs tgz file and send it', function (done) {
mm(Dist, 'getfile', function* () {
return {
name: 'foo.tgz',
size: 1264,
date: '02-May-2014 00:54',
url: '/dist/v0.10.28/foo.tgz'
};
});
fs.writeFileSync(nfs._getpath('/dist/v0.10.28/foo.tgz'), '6eff580cc8460741155d42ef1ef537961194443f');
request(app)
.get('/dist/v0.10.28/foo.tgz')
.expect('Content-Disposition', 'attachment; filename="foo.tgz"')
.expect(200, done);
});
it.skip('should download nfs no-ascii attachment file name', function (done) {
mm(Dist, 'getfile', function* () {
return {
name: '中文名.tgz',
size: 1264,
date: '02-May-2014 00:54',
url: '/dist/v0.10.28/foo.tgz'
};
});
fs.writeFileSync(nfs._getpath('/dist/v0.10.28/foo.tgz'), '6eff580cc8460741155d42ef1ef537961194443f');
request(app)
.get('/dist/v0.10.28/foo.tgz')
.expect('Content-Disposition', 'attachment; filename="%E4%B8%AD%E6%96%87%E5%90%8D.tgz"')
.expect(200, done);
});
});
});

View File

@@ -218,7 +218,7 @@ describe('controllers/web/package.test.js', function () {
describe('unpublished package', function () {
before(function (done) {
var worker = new SyncModuleWorker({
name: ['browserjs'],
name: ['tnpm'],
username: 'fengmk2'
});
@@ -226,14 +226,14 @@ describe('controllers/web/package.test.js', function () {
worker.on('end', function () {
var names = worker.successes.concat(worker.fails);
names.sort();
names.should.eql(['browserjs']);
names.should.eql(['tnpm']);
done();
});
});
it('should display unpublished info', function (done) {
request(app)
.get('/package/browserjs')
.get('/package/tnpm')
.expect(200)
.expect(/This package has been unpublished\./, done);
});

View File

@@ -14,4 +14,4 @@
* Module dependencies.
*/
var varname = require('modulename');
var koa = require('koa');

View File

@@ -17,11 +17,21 @@
var crypto = require('crypto');
var utility = require('utility');
var User = require('../proxy/user');
var config = require('../config');
if (process.env.CNPM_SOURCE_NPM) {
config.sourceNpmRegistry = process.env.CNPM_SOURCE_NPM;
}
if (process.env.CNPM_SOURCE_NPM_ISCNPM === 'false') {
config.sourceNpmRegistryIsCNpm = false;
}
var usernames = [
'cnpmjstest101',
'cnpmjstest102',
'cnpmjstest10'
'cnpmjstest10', // admin
'cnpmjstestAdmin2', // other admin
'cnpmjstestAdmin3', // other admin
];
usernames.forEach(function (name) {

View File

@@ -77,7 +77,7 @@ describe('middleware/auth.test.js', function () {
});
request(app)
.get('/-/user/org.couchdb.user:cnpmjstest10')
.put('/-/user/org.couchdb.user:cnpmjstest10/-rev/1')
.set('authorization', 'basic ' + new Buffer('cnpmjstest10:cnpmjstest10').toString('base64'))
.expect({
error: 'UserSeriveAuthError',

View File

@@ -16,34 +16,40 @@
var should = require('should');
var Dist = require('../../proxy/dist');
var fs = require('fs');
var nfs = require('../../common/nfs');
describe('proxy/dist.test.js', function () {
describe('savefile() and getfile', function () {
it('should save and get /npm-versions.txt', function* () {
var name = 'npm-versions.txt';
var info = {
name: 'npm-versions.txt',
name: name,
parent: '/',
date: '15-Sep-2011 23:48',
size: 1676,
url: 'http://cnpmjs.org/dist/npm-versions.txt',
url: name,
sha1: '104731881047318810473188'
};
yield* Dist.savefile(info);
fs.writeFileSync(nfs._getpath('npm-versions.txt'), 'npm version');
var got = yield* Dist.getfile('/npm-versions.txt');
should.exist(got);
got.should.eql(info);
});
it('should save and get /v1.0.0/npm-versions.txt', function* () {
var name = 'v1.0.0/npm-versions.txt';
var info = {
name: 'npm-versions.txt',
parent: '/v1.0.0/',
date: '15-Sep-2011 23:48',
size: 1676,
url: 'http://cnpmjs.org/dist/v1.0.0/npm-versions.txt',
url: 'v1.0.0/npm-versions.txt',
sha1: '104731881047318810473188'
};
yield* Dist.savefile(info);
fs.writeFileSync(nfs._getpath('npm-versions.txt'), 'npm version 1.0.0');
var got = yield* Dist.getfile('/v1.0.0/npm-versions.txt');
should.exist(got);
got.should.eql(info);

View File

@@ -18,14 +18,30 @@ var should = require('should');
var mm = require('mm');
var fs = require('fs');
var path = require('path');
var request = require('supertest');
var mysql = require('../../common/mysql');
var Module = require('../../proxy/module');
var config = require('../../config');
var utils = require('../utils');
var app = require('../../servers/registry');
var fixtures = path.join(path.dirname(__dirname), 'fixtures');
var id;
var pkgname = 'module-proxy-test-pkg';
var pkgversion = '1.0.0';
describe('proxy/module.test.js', function () {
before(function (done) {
var pkg = utils.getPackage(pkgname, pkgversion, utils.admin);
request(app.listen())
.put('/' + pkgname)
.set('authorization', utils.adminAuth)
.send(pkg)
.expect(201, done);
});
afterEach(mm.restore);
describe('addTag()', function () {
@@ -145,27 +161,21 @@ describe('proxy/module.test.js', function () {
});
describe('listByAuthor()', function () {
it('should return author recent modules', function (done) {
Module.listByAuthor('fengmk2', function (err, rows) {
should.not.exist(err);
rows.forEach(function (r) {
r.should.have.keys('name', 'description');
});
done();
it('should return author recent modules', function* () {
var rows = yield Module.listByAuthor('fengmk2');
rows.forEach(function (r) {
r.should.have.keys('name', 'description');
});
});
});
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();
});
});
it('should update ok', function* () {
var row = yield Module.get(pkgname, pkgversion);
should.exist(row);
yield* Module.updateReadme(row.id, 'test');
var data = yield Module.getById(row.id);
data.package.readme.should.equal('test');
});
});
@@ -193,7 +203,7 @@ describe('proxy/module.test.js', function () {
var modules = yield Module.listPrivates();
modules.forEach(function (m) {
m.should.have.keys(['name', 'description']);
})
});
});
});
});

View File

@@ -36,7 +36,7 @@ describe('proxy/npm.test.js', function () {
should.not.exist(data);
});
it('should return error when http error', function *() {
it.skip('should return error when http error', function* () {
mm.http.request(/\//, new ChunkStream(['{']));
try {
var data = yield npm.get('pedding-not-exists');

View File

@@ -15,11 +15,15 @@
*/
var should = require('should');
var mm = require('mm');
var SyncModuleWorker = require('../../proxy/sync_module_worker');
var mysql = require('../../common/mysql');
var Log = require('../../proxy/module_log');
var config = require('../../config');
describe('proxy/sync_module_worker.test.js', function () {
afterEach(mm.restore);
it('should start a sync worker', function (done) {
Log.create({
name: 'mk2testmodule',
@@ -38,6 +42,25 @@ describe('proxy/sync_module_worker.test.js', function () {
});
});
it('should sync upstream first', function (done) {
mm(config, 'sourceNpmRegistryIsCNpm', true);
Log.create({
name: 'mk2testmodule',
username: 'fengmk2',
}, function (err, result) {
should.not.exist(err);
result.id.should.above(0);
var worker = new SyncModuleWorker({
logId: result.id,
name: 'mk2testmodule',
username: 'fengmk2'
});
worker.start();
worker.on('end', done);
});
});
it('should start a sync worker with names and noDep', function (done) {
var worker = new SyncModuleWorker({
name: ['mk2testmodule'],
@@ -66,14 +89,12 @@ describe('proxy/sync_module_worker.test.js', function () {
it('should sync unpublished module by name', function* () {
var result = yield* SyncModuleWorker.sync('tnpm', 'fengmk2');
result.ok.should.equal(true);
result.should.have.property('logId');
result.should.be.Number;
});
it('should not sync not exists module', function* () {
it('should sync not exists module', function* () {
var result = yield* SyncModuleWorker.sync('tnpm-not-exists', 'fengmk2');
result.ok.should.equal(false);
result.should.not.have.property('logId');
result.should.be.Number;
});
it('should sync unpublished info', function (done) {
@@ -90,4 +111,17 @@ describe('proxy/sync_module_worker.test.js', function () {
done();
});
});
describe('syncUpstream()', function () {
it('should sync upstream work', function* () {
var worker = new SyncModuleWorker({
name: ['tnpm'],
username: 'fengmk2'
});
yield [
worker.syncUpstream('tnpm'),
worker.syncUpstream('pedding'),
];
});
});
});

View File

@@ -21,7 +21,7 @@ var mysql = require('../common/mysql');
var Log = require('../proxy/module_log');
var config = require('../config');
config.sourceNpmRegistry = 'http://registry.npmjs.org';
config.sourceNpmRegistry = 'https://registry.npm.taobao.org';
var names = process.argv[2] || 'byte';
names = names.split(',');
@@ -29,6 +29,7 @@ names = names.split(',');
Log.create({
name: names[0],
username: 'fengmk2',
noDep: true,
}, function (err, result) {
if (err) {
throw err;

View File

@@ -16,7 +16,7 @@
var should = require('should');
var mm = require('mm');
var urllib = require('co-urllib');
var urllib = require('../../common/urllib');
var Dist = require('../../proxy/dist');
var distsync = require('../../sync/sync_dist');
@@ -33,9 +33,23 @@ describe('sync/sync_dist.test.js', function () {
});
});
describe('listdir()', function () {
it('should list /v0.11.12/', function* () {
var items = yield* distsync.listdir('/v0.11.12/');
items[0].name.should.equal('docs/');
var docsItems = yield* distsync.listdir('/v0.11.12/docs/');
docsItems[0].name.should.equal('api/');
});
it('should list /v0.11.12/docs/api/', function* () {
var items = yield* distsync.listdir('/v0.11.12/docs/api/');
items.length.should.above(5);
});
});
describe('listdiff()', function () {
it('should got all news', function* () {
mm(urllib, 'request', function* () {
mm(urllib, 'request', function () {
return {
status: 200,
data: '<a href="npm/">npm/</a> 06-May-2014 01:18 -\n<a href="npm-versions.txt">npm-versions.txt</a> 27-Feb-2014 00:01 1676',
@@ -63,7 +77,7 @@ describe('sync/sync_dist.test.js', function () {
});
it('should got empty when all exists', function* () {
mm(urllib, 'request', function* () {
mm(urllib, 'request', function () {
return {
status: 200,
data: '<a href="npm/">npm/</a> 06-May-2014 01:18 -\n<a href="npm-versions.txt">npm-versions.txt</a> 27-Feb-2014 00:01 1676',
@@ -92,7 +106,7 @@ describe('sync/sync_dist.test.js', function () {
});
it('should got date change dir', function* () {
mm(urllib, 'request', function* () {
mm(urllib, 'request', function () {
return {
status: 200,
data: '<a href="npm/">npm/</a> 06-May-2014 01:18 -\n<a href="npm-versions.txt">npm-versions.txt</a> 27-Feb-2014 00:01 1676',

View File

@@ -19,7 +19,9 @@ debug.enable('cnpmjs.org*');
var co = require('co');
var syncdist = require('../sync/sync_dist');
var dir = process.argv[2] || '/v0.11.13/docs/api/';
co(function* () {
// yield* syncdist('/v0.10.28/');
yield* syncdist.syncPhantomjsDir();
yield* syncdist(dir);
// yield* syncdist.syncPhantomjsDir();
})();

View File

@@ -16,11 +16,21 @@
var path = require('path');
var fs = require('fs');
var config = require('../config');
var fixtures = path.join(__dirname, 'fixtures');
var admin = exports.admin = 'cnpmjstest10';
exports.adminAuth = 'Basic ' + new Buffer(admin + ':' + admin).toString('base64');
config.admins[admin] = admin + '@cnpmjs.org';
var otherAdmin2 = exports.otherAdmin2 = 'cnpmjstestAdmin2';
exports.otherAdmin2Auth = 'Basic ' + new Buffer(otherAdmin2 + ':' + otherAdmin2).toString('base64');
config.admins[otherAdmin2] = otherAdmin2 + '@cnpmjs.org';
var otherAdmin3 = exports.otherAdmin3 = 'cnpmjstestAdmin3';
exports.otherAdmin3Auth = 'Basic ' + new Buffer(otherAdmin3 + ':' + otherAdmin3).toString('base64');
config.admins[otherAdmin3] = otherAdmin3 + '@cnpmjs.org';
var otherUser = exports.otherUser = 'cnpmjstest101';
exports.otherUserAuth = 'Basic ' + new Buffer(otherUser + ':' + otherUser).toString('base64');

83
tools/sync_not_exist.js Normal file
View File

@@ -0,0 +1,83 @@
/*!
* cnpmjs.org - tools/sync_not_exist.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 debug = require('debug')('cnpmjs.org:tools:sync_not_exist');
var SyncModuleWorker = require('../proxy/sync_module_worker');
var thunkify = require('thunkify-wrap');
var Module = require('../proxy/module');
var config = require('../config');
var Npm = require('../proxy/npm');
var utility = require('utility');
var co = require('co');
function subtraction(arrOne, arrTwo) {
arrOne = arrOne || [];
arrTwo = arrTwo || [];
var map = {};
var results = [];
arrTwo.forEach(function (name) {
map[name] = true;
});
arrOne.forEach(function (name) {
!map[name] && results.push(name);
});
return results;
}
function *sync(conf) {
if (conf) {
debug('load custom config');
config.loadConfig(conf);
}
var allExists = yield Module.listShort();
var existPackages = allExists.map(function (p) {
return p.name;
});
var allPackages = yield Npm.getShort();
var packages = subtraction(allPackages, existPackages);
if (!packages.length) {
debug('no packages need be sync');
return;
}
debug('Total %d packages to sync', packages.length);
var worker = new SyncModuleWorker({
username: 'admin',
name: packages,
concurrency: config.syncConcurrency
});
worker.start();
var end = thunkify.event(worker);
yield end();
debug('All packages sync done, successes %d, fails %d',
worker.successes.length, worker.fails.length);
return {
successes: worker.successes,
fails: worker.fails
};
}
module.exports = function (config, callback) {
co(sync(config))(callback);
};
if (!module.parent) {
console.log('[tools/sync_not_exist.js] start sync not exist modules');
module.exports();
}

View File

@@ -1,5 +1,13 @@
<% if (name) { %>
<div class="alert alert-warning">
Can not found package match <%= name %>. You can
<a href="/sync/<%= name %>" target="_blank">SYNC</a> from official npm registry or
<a href="https://npmjs.org/search?q=<%= name %>" target="_blank">SEARCH</a> in official npm website.
</div>
<% } else { %>
<div class="row">
<div class="col-lg-8 col-lg-offset-2 text-center">
<h1>OPPS, Error 404 !</h1>
</div>
</div>
<% } %>

View File

@@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/favicon.png">
<!-- Bootstrap -->
<link href="//dn-staticfile.qbox.me/twitter-bootstrap/3.0.0-rc2/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="//dn-staticfile.qbox.me/twitter-bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="//dn-staticfile.qbox.me/prettify/r298/prettify.min.css" rel="stylesheet" media="screen">
<!-- JavaScript plugins (requires jQuery) -->
<script src="//dn-staticfile.qbox.me/jquery/2.0.3/jquery.min.js"></script>
@@ -34,6 +34,7 @@
.nav-tabs{margin:20px 0;}
.nav-cont{display:none;}
.nav-cont.active{display:block;}
.deprecated{color:red;}
</style>
<script>
$(function () {
@@ -77,7 +78,7 @@
</div>
</div>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="//dn-staticfile.qbox.me/twitter-bootstrap/3.0.0-rc2/js/bootstrap.min.js"></script>
<script src="//dn-staticfile.qbox.me/twitter-bootstrap/3.2.0/js/bootstrap.min.js"></script>
<!-- Enable responsive features in IE8 with Respond.js (https://github.com/scottjehl/Respond) -->
<script src="//dn-staticfile.qbox.me/respond.js/1.2.0/respond.min.js"></script>

View File

@@ -1,6 +1,7 @@
<div id="package">
<h1>
<%= package.name %>
<img title="<%= package.version %>" src="/badge/v/<%= package.name %>.svg?style=flat-square">
<small>
<% if (package._publish_on_cnpm) { %>
(Private package)
@@ -11,7 +12,7 @@
</h1>
<% if (package.deprecated) { %>
<p class="deprecated"><%= package.deprecated %></p>
<p class="deprecated">[DEPRECATED] <%= package.deprecated %></p>
<% } %>
<% if (package.description) { %>
@@ -76,9 +77,7 @@
<tr>
<th>Version</th>
<td>
<b>
<%= package.version %>
</b>
<img title="<%= package.version %>" src="/badge/v/<%= package.name %>.svg?style=flat-square">
<% if (package.fromNow) { %>
last updated
<%= package.fromNow %>
@@ -89,11 +88,11 @@
<tr>
<th>Engines</th>
<td>
<ul>
<% for (var k in package.engines) { %>
<li><%= k %>: <%= package.engines[k] %></li>
<% } %>
</ul>
<% for (var k in package.engines) {
var engine = package.engines[k];
%>
<img title="<%= engine.title %>" src="<%- engine.badgeURL %>">
<% } %>
</td>
</tr>
<% } %>

View File

@@ -31,12 +31,18 @@
<tbody>
<tr>
<th>Name</th>
<th>IM</th>
<th>Last modified</th>
<th>Is admin</th>
<th>Publish scopes</th>
</tr>
<tr>
<td>@<%= user.json.fullname || user.name %></td>
<td>
<% if (user.json.im) { %>
<a href="<%- user.json.im %>" target="_blank"><span class="glyphicon glyphicon-comment"></span></a>
<% } %>
</td>
<td><%- lastModified %></td>
<td><%- isAdmin %></td>
<td>

View File

@@ -49,8 +49,7 @@
var offset = 0;
var logs = '';
var successFlag = false;
var failFlag = false;
var syncDone = false;
var hasFail = false;
function getSyncLog(id) {
$.ajax({
@@ -64,17 +63,16 @@
offset += data.log.split('\n').length;
logs = logs + '\n' + data.log;
if (data.log.indexOf('Success: [') >= 0) {
successFlag = true;
if (data.log.indexOf('[done] Sync') >= 0) {
syncDone = true;
}
if (data.log.indexOf('Fail: [') >= 0) {
failFlag = true;
var failInfo = data.log.match(/Fail: \[ (.*?) \]/);
if (failInfo && failInfo[1]) {
hasFail = true;
}
}
if (successFlag && failFlag) {
if (syncDone) {
logs += '\nSync package ' + name + ' complete!';
if (hasFail) {
logs += ' But some packages sync failed, you can refresh to sync again.';