Compare commits
419 Commits
2.0.0-rc.1
...
egg
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d64ea76647 | ||
|
|
c9f958d194 | ||
|
|
889a9c7ee5 | ||
|
|
29a7cced3a | ||
|
|
0d86d05d45 | ||
|
|
1598c2a3d9 | ||
|
|
997e9c5cb5 | ||
|
|
9cfe0502dd | ||
|
|
ff2536fcc5 | ||
|
|
df5564b1ea | ||
|
|
093031e720 | ||
|
|
65b595b899 | ||
|
|
bf5f02908f | ||
|
|
6c3140d422 | ||
|
|
dd27edc36b | ||
|
|
2065c975e0 | ||
|
|
0020a33e65 | ||
|
|
dd423c08d8 | ||
|
|
f9f049c177 | ||
|
|
034bdbb344 | ||
|
|
d7d4cb7fa7 | ||
|
|
b83483e3c0 | ||
|
|
9b909b3233 | ||
|
|
fac9df1de5 | ||
|
|
3262adadd4 | ||
|
|
74e9bdde72 | ||
|
|
f567ef5567 | ||
|
|
c89d7023c4 | ||
|
|
72aa64258f | ||
|
|
b5b63c11f2 | ||
|
|
4da684f3b6 | ||
|
|
fb29419c27 | ||
|
|
8789dadaef | ||
|
|
1c936d4b73 | ||
|
|
7c2f947518 | ||
|
|
bfbfef87d2 | ||
|
|
ea3beceef7 | ||
|
|
b0f0bc0331 | ||
|
|
932547af2a | ||
|
|
79ac9fb823 | ||
|
|
a437eb01eb | ||
|
|
6d921a9c46 | ||
|
|
abcb81d28c | ||
|
|
ea54f32805 | ||
|
|
3dbf29afac | ||
|
|
2c520d97a9 | ||
|
|
38148b24cb | ||
|
|
97895bdfa5 | ||
|
|
0c1c12680c | ||
|
|
6485e4b019 | ||
|
|
ee1e084455 | ||
|
|
5c8d679a6d | ||
|
|
94dc13088c | ||
|
|
9b572d77aa | ||
|
|
c1fa6de038 | ||
|
|
227e1927b4 | ||
|
|
ea98b61ddf | ||
|
|
9d1d60b764 | ||
|
|
7509d909e8 | ||
|
|
9612f64aba | ||
|
|
1b04d59539 | ||
|
|
e6998506f3 | ||
|
|
576397b2b0 | ||
|
|
6c1935bc61 | ||
|
|
1e68cfa568 | ||
|
|
8188d9a07a | ||
|
|
d7ae8d28c1 | ||
|
|
afa5639752 | ||
|
|
e0213e18a0 | ||
|
|
a74d60c7eb | ||
|
|
fcabc49d39 | ||
|
|
ad0722b57b | ||
|
|
6e11a2c8a7 | ||
|
|
0329cfad61 | ||
|
|
ede8a3ce5f | ||
|
|
cde4f2179e | ||
|
|
374dc17a6b | ||
|
|
626259c379 | ||
|
|
36644bda67 | ||
|
|
236e9e2fb3 | ||
|
|
b551216517 | ||
|
|
c8d9d9f075 | ||
|
|
4d43588b10 | ||
|
|
5f71add418 | ||
|
|
3fcfc6306d | ||
|
|
e78c774dbf | ||
|
|
6a54b1328f | ||
|
|
47c8273b7d | ||
|
|
0f01a4c076 | ||
|
|
17b43e3ae4 | ||
|
|
7fd6b10ddf | ||
|
|
7f16050f9e | ||
|
|
f57d525452 | ||
|
|
f05046b8bd | ||
|
|
a34aa7d72f | ||
|
|
72646ffee2 | ||
|
|
060fc65ffb | ||
|
|
4169ee9c6e | ||
|
|
51f380a800 | ||
|
|
c90062e7a0 | ||
|
|
26007f8318 | ||
|
|
0146ce5c30 | ||
|
|
87518df394 | ||
|
|
e49f5474f6 | ||
|
|
af4401fc62 | ||
|
|
c2d608a5cc | ||
|
|
b91b160b66 | ||
|
|
46a3df95bd | ||
|
|
d08aee047e | ||
|
|
406d8cf9a1 | ||
|
|
e1b9ab6b09 | ||
|
|
71f9014777 | ||
|
|
adca5adff2 | ||
|
|
1857f1d0e5 | ||
|
|
2d56820e8b | ||
|
|
119094b230 | ||
|
|
744b6e1e15 | ||
|
|
17f47732a0 | ||
|
|
3a46b97544 | ||
|
|
44976f4afa | ||
|
|
9da7c6ccf2 | ||
|
|
4b68eecf53 | ||
|
|
8d7058b947 | ||
|
|
933ae69d0b | ||
|
|
1af36f0a7a | ||
|
|
f4e9de5094 | ||
|
|
2ccaf404ab | ||
|
|
44c79c7646 | ||
|
|
a845d3f74d | ||
|
|
730113424c | ||
|
|
658be3004f | ||
|
|
214d0ad5c3 | ||
|
|
ca70c8a06d | ||
|
|
1c680367a7 | ||
|
|
3bd43d5ba9 | ||
|
|
0965f8f8e5 | ||
|
|
005eb603ae | ||
|
|
65a9303dff | ||
|
|
3bc6b625ec | ||
|
|
2b0dc6d17f | ||
|
|
842d790dcb | ||
|
|
20eac48349 | ||
|
|
efb80e8c33 | ||
|
|
35fbc651cd | ||
|
|
e55779ffa7 | ||
|
|
878176ea9c | ||
|
|
e3a2eab000 | ||
|
|
7478846754 | ||
|
|
8b244e6c26 | ||
|
|
19217de010 | ||
|
|
93a57b5dae | ||
|
|
defb447f29 | ||
|
|
93b73de164 | ||
|
|
ffc6124c0e | ||
|
|
ab40a992c2 | ||
|
|
5258569044 | ||
|
|
04d8055d56 | ||
|
|
68b6d54f60 | ||
|
|
a950a1e44b | ||
|
|
22f5472dbe | ||
|
|
d6d37a623d | ||
|
|
757184fbc8 | ||
|
|
043fa2c32a | ||
|
|
f94f5ca714 | ||
|
|
788bfc68bc | ||
|
|
dacc39c1d9 | ||
|
|
3fb2228031 | ||
|
|
4535178fa9 | ||
|
|
42e9e1603f | ||
|
|
9a0c3c6c62 | ||
|
|
ba864a62bf | ||
|
|
6dbfe18f58 | ||
|
|
d8c65ff1f3 | ||
|
|
426990f94e | ||
|
|
6d57929e89 | ||
|
|
2b51171592 | ||
|
|
701c9ffa5f | ||
|
|
4260b1c2b6 | ||
|
|
5e926f658d | ||
|
|
78e13bb1d3 | ||
|
|
9e5ec3406d | ||
|
|
21804d277b | ||
|
|
95d1a6b35c | ||
|
|
78395d48b4 | ||
|
|
c6795f201f | ||
|
|
8e7a362bc2 | ||
|
|
7ff3e9d017 | ||
|
|
902b0bb638 | ||
|
|
8097352a6c | ||
|
|
ecf902b73e | ||
|
|
bb0ace7e23 | ||
|
|
d964b11b8c | ||
|
|
53fa67f3bf | ||
|
|
adf7ece3e9 | ||
|
|
02d5b4d16b | ||
|
|
67f8e64140 | ||
|
|
45ceb17238 | ||
|
|
a1ee99618c | ||
|
|
de854a76f1 | ||
|
|
d59ebb44be | ||
|
|
5a2ac54c73 | ||
|
|
8fd8bae5aa | ||
|
|
5929b9b1ea | ||
|
|
aae14f1a6e | ||
|
|
96ad637882 | ||
|
|
73aa9129a8 | ||
|
|
1c89a6f6f9 | ||
|
|
c2beb96dda | ||
|
|
4c4fc3fc7f | ||
|
|
82395fdc33 | ||
|
|
ced4887269 | ||
|
|
8f96a5a57b | ||
|
|
f6e79ff5e7 | ||
|
|
e932f16424 | ||
|
|
622c93c3fe | ||
|
|
ccf3e8a83c | ||
|
|
2069b4334c | ||
|
|
ef84cedd79 | ||
|
|
ba07f87ee0 | ||
|
|
10cbe70378 | ||
|
|
244ce60857 | ||
|
|
97a4f6cd92 | ||
|
|
10197ef2aa | ||
|
|
d2e7350b27 | ||
|
|
9a4a7c6bf0 | ||
|
|
550024176f | ||
|
|
90485d33dd | ||
|
|
02d9bd923e | ||
|
|
a256e044c5 | ||
|
|
a194fc8f3c | ||
|
|
0f61c71e2b | ||
|
|
2acfc52057 | ||
|
|
e144506634 | ||
|
|
cc9b547c86 | ||
|
|
e8bea69a4d | ||
|
|
cd36984a56 | ||
|
|
ec00eeee75 | ||
|
|
571aea5277 | ||
|
|
9e9fd84e12 | ||
|
|
dbe0f96855 | ||
|
|
66f17619e6 | ||
|
|
1d491a244b | ||
|
|
bbb6a59441 | ||
|
|
76e0563308 | ||
|
|
5e969cc305 | ||
|
|
9d886b0599 | ||
|
|
cd2e96f460 | ||
|
|
f86734674d | ||
|
|
e2c37d312f | ||
|
|
689e7e1c08 | ||
|
|
cd6f78d91b | ||
|
|
b832c91d21 | ||
|
|
646c830a68 | ||
|
|
e543f8578b | ||
|
|
5ff7e2867f | ||
|
|
98e8e7d498 | ||
|
|
b7eb9f8374 | ||
|
|
12a8eff1f6 | ||
|
|
9156be88a9 | ||
|
|
cebbf7dda2 | ||
|
|
ea226e8ad6 | ||
|
|
eb3b79cae2 | ||
|
|
49b70b4b4d | ||
|
|
af724960c2 | ||
|
|
79797376d3 | ||
|
|
7fd264440e | ||
|
|
1982b9404e | ||
|
|
4bea6f4e5f | ||
|
|
3dd04b6aac | ||
|
|
ec605efc9c | ||
|
|
7f27447dac | ||
|
|
a2c151f246 | ||
|
|
35efc132b3 | ||
|
|
dd37527651 | ||
|
|
a82e772097 | ||
|
|
70fb543e7a | ||
|
|
bbfc3e57db | ||
|
|
9b9ec50ccf | ||
|
|
4098d966b8 | ||
|
|
6e7d528c9f | ||
|
|
701abe831f | ||
|
|
449deab2ed | ||
|
|
20f1ab3af8 | ||
|
|
a932b6487d | ||
|
|
8f05a6e8b9 | ||
|
|
4a91795288 | ||
|
|
de72396cd2 | ||
|
|
7f48d45e0d | ||
|
|
553c1daf85 | ||
|
|
084b83e8d7 | ||
|
|
05e5ac86ba | ||
|
|
2a530a3d6e | ||
|
|
bde9de9f90 | ||
|
|
d538658be9 | ||
|
|
81a010bc53 | ||
|
|
7f2c5725e5 | ||
|
|
7f89b3be92 | ||
|
|
1c6eb50e05 | ||
|
|
aa8d4ac850 | ||
|
|
e0eeefa43e | ||
|
|
662b91ea9a | ||
|
|
cc70f9e6b1 | ||
|
|
7312d761ca | ||
|
|
d5c0e07c1c | ||
|
|
e108b4804d | ||
|
|
92c218d755 | ||
|
|
df2a974b2c | ||
|
|
7fc1a8411c | ||
|
|
0759328140 | ||
|
|
3fc2ea7f25 | ||
|
|
2f2794785f | ||
|
|
ea1f253624 | ||
|
|
b25eaaf73e | ||
|
|
0b0164cbf4 | ||
|
|
8a727c351d | ||
|
|
2c6a08908d | ||
|
|
9a7e94f7a4 | ||
|
|
9a2fba42c6 | ||
|
|
ab8d6bfd19 | ||
|
|
619f4310e8 | ||
|
|
41eea6747d | ||
|
|
4e3a50f3bb | ||
|
|
e5a9a22f86 | ||
|
|
eb66d8958f | ||
|
|
8a0dcb5063 | ||
|
|
cba9d5dbbb | ||
|
|
233b736401 | ||
|
|
58d72bde22 | ||
|
|
38683a82ef | ||
|
|
71cc54fb3b | ||
|
|
b0eb611dc4 | ||
|
|
7e810dba48 | ||
|
|
f4dc41ede5 | ||
|
|
5574301909 | ||
|
|
261c97f1e8 | ||
|
|
af8ae63eab | ||
|
|
89e7ae3ba2 | ||
|
|
46d65a1878 | ||
|
|
77074e3ae3 | ||
|
|
34fa887aa8 | ||
|
|
6dc779a9b4 | ||
|
|
24d6831a68 | ||
|
|
d83c52b32f | ||
|
|
25334e5d95 | ||
|
|
e27af73ccc | ||
|
|
f85da0a384 | ||
|
|
1b6159132d | ||
|
|
2130041f7f | ||
|
|
b5646e12a6 | ||
|
|
d70c284b83 | ||
|
|
ddbb0b4fed | ||
|
|
35c1a956f7 | ||
|
|
416e2650cc | ||
|
|
964cfd5242 | ||
|
|
dd5ac02876 | ||
|
|
54a11ebb17 | ||
|
|
9131dcb105 | ||
|
|
6e276c58c2 | ||
|
|
7b1929b717 | ||
|
|
ec4a74f439 | ||
|
|
027d2bb46b | ||
|
|
2b6bd06bec | ||
|
|
ff523d7374 | ||
|
|
931afd7f4b | ||
|
|
f2724d959f | ||
|
|
ca884d92ca | ||
|
|
44c8e05563 | ||
|
|
8c0f9057ac | ||
|
|
fde319a788 | ||
|
|
c6704782a7 | ||
|
|
491b91ac0e | ||
|
|
f7819186e7 | ||
|
|
4652eca74e | ||
|
|
ebb7cbcf68 | ||
|
|
20b98b1227 | ||
|
|
7e288a442c | ||
|
|
17d1527551 | ||
|
|
4de50e2bf8 | ||
|
|
80bf9d2d73 | ||
|
|
7d8f6ec92f | ||
|
|
1bbf4d7ebe | ||
|
|
88f8cb8fa9 | ||
|
|
7c59fa5e37 | ||
|
|
ccb24025b5 | ||
|
|
6f24c10cad | ||
|
|
2579b62e3a | ||
|
|
38ed0a91b2 | ||
|
|
57a025d96e | ||
|
|
eef7467321 | ||
|
|
4c89b8a4c1 | ||
|
|
353177deee | ||
|
|
603fdeea06 | ||
|
|
1850d33b83 | ||
|
|
8827ca26a7 | ||
|
|
9e34566a19 | ||
|
|
8e4fd68cca | ||
|
|
a8fbeb7be5 | ||
|
|
cd0249dfb9 | ||
|
|
e34d1948fb | ||
|
|
4cd46b1857 | ||
|
|
c8a7343d45 | ||
|
|
0689cc93ce | ||
|
|
6c98c1f07f | ||
|
|
94021b0553 | ||
|
|
9ed3b3ad7a | ||
|
|
d651c2ee6f | ||
|
|
3653daf261 | ||
|
|
01a722190f | ||
|
|
4aec25d4ab | ||
|
|
2049978a68 | ||
|
|
93b98bcb7e | ||
|
|
4838efc141 | ||
|
|
1e48c47010 | ||
|
|
81d742d210 | ||
|
|
665d72ed32 | ||
|
|
c70888d7ac | ||
|
|
5acda5ee57 | ||
|
|
84587bfa86 | ||
|
|
263910c13c |
35
.autod.conf.js
Normal file
35
.autod.conf.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
'ues strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
write: true,
|
||||||
|
prefix: '^',
|
||||||
|
devprefix: '^',
|
||||||
|
registry: 'https://r.cnpmjs.org',
|
||||||
|
exclude: [
|
||||||
|
'test/fixtures',
|
||||||
|
'examples',
|
||||||
|
'docs',
|
||||||
|
'public',
|
||||||
|
],
|
||||||
|
dep: [
|
||||||
|
'mysql',
|
||||||
|
'egg',
|
||||||
|
'koa-router',
|
||||||
|
],
|
||||||
|
devdep: [
|
||||||
|
'autod',
|
||||||
|
'autod-egg',
|
||||||
|
'eslint',
|
||||||
|
'eslint-config-egg',
|
||||||
|
'egg-bin',
|
||||||
|
'egg-mock',
|
||||||
|
],
|
||||||
|
keep: [
|
||||||
|
],
|
||||||
|
semver: [
|
||||||
|
'changes-stream@1',
|
||||||
|
'nodemailer@1',
|
||||||
|
'koa-router@3',
|
||||||
|
'supertest@2',
|
||||||
|
],
|
||||||
|
};
|
||||||
6
.eslintignore
Normal file
6
.eslintignore
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
test/fixtures
|
||||||
|
test/mocks
|
||||||
|
examples/**/app/public
|
||||||
|
logs
|
||||||
|
run
|
||||||
|
public/
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
node_modules/
|
|
||||||
coverage/
|
|
||||||
.tmp/
|
|
||||||
.git/
|
|
||||||
95
.jshintrc
95
.jshintrc
@@ -1,95 +0,0 @@
|
|||||||
{
|
|
||||||
// JSHint Default Configuration File (as on JSHint website)
|
|
||||||
// See http://jshint.com/docs/ for more details
|
|
||||||
|
|
||||||
"maxerr" : 50, // {int} Maximum error before stopping
|
|
||||||
|
|
||||||
// Enforcing
|
|
||||||
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
|
|
||||||
"camelcase" : false, // true: Identifiers must be in camelCase
|
|
||||||
"curly" : true, // true: Require {} for every new block or scope
|
|
||||||
"eqeqeq" : true, // true: Require triple equals (===) for comparison
|
|
||||||
"forin" : false, // true: Require filtering for..in loops with obj.hasOwnProperty()
|
|
||||||
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
|
|
||||||
"indent" : false, // {int} Number of spaces to use for indentation
|
|
||||||
"latedef" : false, // true: Require variables/functions to be defined before being used
|
|
||||||
"newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()`
|
|
||||||
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
|
|
||||||
"noempty" : true, // true: Prohibit use of empty blocks
|
|
||||||
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
|
|
||||||
"plusplus" : false, // true: Prohibit use of `++` & `--`
|
|
||||||
"quotmark" : false, // Quotation mark consistency:
|
|
||||||
// false : do nothing (default)
|
|
||||||
// true : ensure whatever is used is consistent
|
|
||||||
// "single" : require single quotes
|
|
||||||
// "double" : require double quotes
|
|
||||||
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
|
|
||||||
"unused" : true, // true: Require all defined variables be used
|
|
||||||
"strict" : true, // true: Requires all functions run in ES5 Strict Mode
|
|
||||||
"trailing" : false, // true: Prohibit trailing whitespaces
|
|
||||||
"maxparams" : false, // {int} Max number of formal params allowed per function
|
|
||||||
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
|
|
||||||
"maxstatements" : false, // {int} Max number statements per function
|
|
||||||
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
|
|
||||||
"maxlen" : false, // {int} Max number of characters per line
|
|
||||||
|
|
||||||
// Relaxing
|
|
||||||
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
|
|
||||||
"boss" : true, // true: Tolerate assignments where comparisons would be expected
|
|
||||||
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
|
|
||||||
"eqnull" : false, // true: Tolerate use of `== null`
|
|
||||||
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
|
|
||||||
"esnext" : true, // true: Allow ES.next (ES6) syntax (ex: `const`)
|
|
||||||
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
|
|
||||||
// (ex: `for each`, multiple try/catch, function expression…)
|
|
||||||
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
|
|
||||||
"expr" : true, // true: Tolerate `ExpressionStatement` as Programs
|
|
||||||
"funcscope" : false, // true: Tolerate defining variables inside control statements"
|
|
||||||
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
|
|
||||||
"iterator" : false, // true: Tolerate using the `__iterator__` property
|
|
||||||
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
|
|
||||||
"laxbreak" : true, // true: Tolerate possibly unsafe line breakings
|
|
||||||
"laxcomma" : false, // true: Tolerate comma-first style coding
|
|
||||||
"loopfunc" : false, // true: Tolerate functions being defined in loops
|
|
||||||
"multistr" : true, // true: Tolerate multi-line strings
|
|
||||||
"proto" : false, // true: Tolerate using the `__proto__` property
|
|
||||||
"scripturl" : false, // true: Tolerate script-targeted URLs
|
|
||||||
"smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment
|
|
||||||
"shadow" : true, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
|
|
||||||
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
|
|
||||||
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
|
|
||||||
"validthis" : true, // true: Tolerate using this in a non-constructor function
|
|
||||||
|
|
||||||
// Environments
|
|
||||||
"browser" : true, // Web Browser (window, document, etc)
|
|
||||||
"couch" : false, // CouchDB
|
|
||||||
"devel" : true, // Development/debugging (alert, confirm, etc)
|
|
||||||
"dojo" : false, // Dojo Toolkit
|
|
||||||
"jquery" : false, // jQuery
|
|
||||||
"mootools" : false, // MooTools
|
|
||||||
"node" : true, // Node.js
|
|
||||||
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
|
|
||||||
"prototypejs" : false, // Prototype and Scriptaculous
|
|
||||||
"rhino" : false, // Rhino
|
|
||||||
"worker" : false, // Web Workers
|
|
||||||
"wsh" : false, // Windows Scripting Host
|
|
||||||
"yui" : false, // Yahoo User Interface
|
|
||||||
"noyield" : true, // allow generators without a yield
|
|
||||||
|
|
||||||
// Legacy
|
|
||||||
"nomen" : false, // true: Prohibit dangling `_` in variables
|
|
||||||
"onevar" : false, // true: Allow only one `var` statement per function
|
|
||||||
"passfail" : false, // true: Stop on first error
|
|
||||||
"white" : false, // true: Check against strict whitespace and indentation rules
|
|
||||||
|
|
||||||
// Custom Globals
|
|
||||||
"globals" : { // additional predefined global variables
|
|
||||||
// mocha
|
|
||||||
"describe": true,
|
|
||||||
"it": true,
|
|
||||||
"before": true,
|
|
||||||
"afterEach": true,
|
|
||||||
"beforeEach": true,
|
|
||||||
"after": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"notify": false
|
|
||||||
}
|
|
||||||
@@ -22,3 +22,4 @@ config/web_readme.md
|
|||||||
config/config.js
|
config/config.js
|
||||||
*.sqlite
|
*.sqlite
|
||||||
.node-dev.json
|
.node-dev.json
|
||||||
|
nohup.out
|
||||||
|
|||||||
13
.travis.yml
13
.travis.yml
@@ -1,6 +1,11 @@
|
|||||||
|
sudo: false
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- '0.11.14'
|
- '6'
|
||||||
before_install: "npm install --build-from-source"
|
- '7'
|
||||||
script: "make test-travis-all"
|
addons:
|
||||||
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
|
- postgresql: '9.3'
|
||||||
|
script:
|
||||||
|
- TEST_TIMEOUT=60000 CNPM_SOURCE_NPM=https://registry.npmjs.org CNPM_SOURCE_NPM_ISCNPM=false npm run test-all
|
||||||
|
after_script:
|
||||||
|
- npm i codecov && codecov
|
||||||
|
|||||||
8
AUTHORS
8
AUTHORS
@@ -1,8 +1,12 @@
|
|||||||
# Ordered by date of first contribution.
|
# Ordered by date of first contribution.
|
||||||
# Auto-generated by 'contributors' on Mon, 03 Mar 2014 13:01:28 GMT.
|
|
||||||
# https://github.com/xingrz/node-contributors
|
|
||||||
|
|
||||||
fengmk2 <fengmk2@gmail.com> (https://github.com/fengmk2)
|
fengmk2 <fengmk2@gmail.com> (https://github.com/fengmk2)
|
||||||
dead-horse <dead_horse@qq.com> (https://github.com/dead-horse)
|
dead-horse <dead_horse@qq.com> (https://github.com/dead-horse)
|
||||||
alsotang <alsotang@gmail.com> (https://github.com/alsotang)
|
alsotang <alsotang@gmail.com> (https://github.com/alsotang)
|
||||||
4simple <wondger@qq.com> (https://github.com/4simple)
|
4simple <wondger@qq.com> (https://github.com/4simple)
|
||||||
|
afc163 <afc163@gmail.com> (https://github.com/afc163)
|
||||||
|
Yuwei Ba <i@xiaoba.me> (https://github.com/ibigbug)
|
||||||
|
dickeylth <dickeylth@gmail.com> (https://github.com/dickeylth)
|
||||||
|
wenbing <wenbing@users.noreply.github.com> (https://github.com/wenbing)
|
||||||
|
21paradox <1036339815@qq.com> (https://github.com/21paradox)
|
||||||
|
|
||||||
|
|||||||
478
History.md
478
History.md
@@ -1,4 +1,474 @@
|
|||||||
|
|
||||||
|
2.19.2 / 2017-01-05
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: should auto sync un-deprecate message (#1105)
|
||||||
|
|
||||||
|
2.19.1 / 2016-12-29
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: try to use the best repository url (#1102)
|
||||||
|
|
||||||
|
2.19.0 / 2016-12-21
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat: keyword search with limit to support keywords > 100 (#1097)
|
||||||
|
|
||||||
|
2.18.0 / 2016-12-05
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: support downloads total on scope package (#1088)
|
||||||
|
* fix: try to sync from official replicate (#1076)
|
||||||
|
* feat: add change password script (#1070)
|
||||||
|
* test: skip always fail tests
|
||||||
|
* test: add node v7
|
||||||
|
* feat: show more sync info
|
||||||
|
|
||||||
|
2.17.2 / 2016-11-13
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: ignore long package name on unpublished sync (#1067)
|
||||||
|
|
||||||
|
2.17.1 / 2016-11-08
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: add publish_time for private packages (#1061)
|
||||||
|
|
||||||
|
2.17.0 / 2016-11-03
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat: make snyk.io url configable (#1058)
|
||||||
|
|
||||||
|
2.16.2 / 2016-09-27
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: try to use config.registryHost first on setDownloadURL (#1044)
|
||||||
|
|
||||||
|
2.16.1 / 2016-08-22
|
||||||
|
==================
|
||||||
|
|
||||||
|
* refactor: refine publishable's code (#1022)
|
||||||
|
|
||||||
|
2.16.0 / 2016-08-22
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat: admin can do everything (#1021)
|
||||||
|
|
||||||
|
2.15.0 / 2016-08-22
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat: return dist-tag on package registry ([#1020](https://github.com/cnpm/cnpmjs.org/issues/1020))
|
||||||
|
* chore(package): update supertest to version 2.0.0 ([#1004](https://github.com/cnpm/cnpmjs.org/issues/1004))
|
||||||
|
|
||||||
|
2.14.0 / 2016-08-04
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat: password may contains ":" ([#999](https://github.com/cnpm/cnpmjs.org/issues/999))
|
||||||
|
* fix: limit sync fails email notice ([#1006](https://github.com/cnpm/cnpmjs.org/issues/1006))
|
||||||
|
|
||||||
|
2.13.0 / 2016-07-26
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat: enable maxrequests middleware ([#1003](https://github.com/cnpm/cnpmjs.org/issues/1003))
|
||||||
|
|
||||||
|
2.12.2 / 2016-07-11
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: getModuleByRange don't list all packages ([#990](https://github.com/cnpm/cnpmjs.org/issues/990))
|
||||||
|
* fix: should show new version package count ([#984](https://github.com/cnpm/cnpmjs.org/issues/984))
|
||||||
|
|
||||||
|
2.12.1 / 2016-07-01
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: make sure chagnes stream destroy ([#982](https://github.com/cnpm/cnpmjs.org/issues/982))
|
||||||
|
* chore(package): update semver to version 5.2.0 ([#978](https://github.com/cnpm/cnpmjs.org/issues/978))
|
||||||
|
* deps: use ^ instead of ~ ([#976](https://github.com/cnpm/cnpmjs.org/issues/976))
|
||||||
|
* chore(package): update mini-logger to version 1.1.1 ([#973](https://github.com/cnpm/cnpmjs.org/issues/973))
|
||||||
|
|
||||||
|
2.12.0 / 2016-06-26
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: logger seperator should be one EOL ([#972](https://github.com/cnpm/cnpmjs.org/issues/972))
|
||||||
|
* feat: add security check badge for public package ([#971](https://github.com/cnpm/cnpmjs.org/issues/971))
|
||||||
|
|
||||||
|
2.11.0 / 2016-06-25
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat: add changes stream syncer ([#970](https://github.com/cnpm/cnpmjs.org/issues/970))
|
||||||
|
* chore(package): update pg to version 5.1.0 ([#953](https://github.com/cnpm/cnpmjs.org/issues/953))
|
||||||
|
|
||||||
|
2.10.1 / 2016-06-05
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: should sync missing public scoped package on install ([#946](https://github.com/cnpm/cnpmjs.org/issues/946))
|
||||||
|
* chore(package): update bytes to version 2.4.0 ([#943](https://github.com/cnpm/cnpmjs.org/issues/943))
|
||||||
|
* userService ([#926](https://github.com/cnpm/cnpmjs.org/issues/926))
|
||||||
|
* chore(package): update should to version 8.4.0 ([#928](https://github.com/cnpm/cnpmjs.org/issues/928))
|
||||||
|
* chore(package): update humanize-ms to version 1.2.0 ([#927](https://github.com/cnpm/cnpmjs.org/issues/927))
|
||||||
|
* chore(package): update kcors to version 1.2.1 ([#918](https://github.com/cnpm/cnpmjs.org/issues/918))
|
||||||
|
* chore(package): update urllib to version 2.9.0 ([#898](https://github.com/cnpm/cnpmjs.org/issues/898))
|
||||||
|
|
||||||
|
2.10.0 / 2016-04-15
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat: show tarball url on package page ([#894](https://github.com/cnpm/cnpmjs.org/issues/894))
|
||||||
|
* chore(package): update koa-mock to version 1.6.1 ([#891](https://github.com/cnpm/cnpmjs.org/issues/891))
|
||||||
|
|
||||||
|
2.9.5 / 2016-04-12
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: change logo url to a better https source
|
||||||
|
* fix: http://cnpmjs.org/package/fms pre style ([#739](https://github.com/cnpm/cnpmjs.org/issues/739))
|
||||||
|
|
||||||
|
2.9.4 / 2016-04-09
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: don't sync constructor package on exists mode ([#883](https://github.com/cnpm/cnpmjs.org/issues/883))
|
||||||
|
* Update utility to version 1.7.0 🚀
|
||||||
|
* chore: update sponsor link
|
||||||
|
|
||||||
|
2.9.3 / 2016-04-05
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: use better diff time to check sync status
|
||||||
|
* Update sequelize to version 3.21.0 🚀
|
||||||
|
* chore(package): update agentkeepalive to version 2.1.0
|
||||||
|
* chore(package): update pg to version 4.5.2
|
||||||
|
|
||||||
|
2.9.2 / 2016-03-29
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: override antd for ul & ol list number & icon.
|
||||||
|
|
||||||
|
2.9.1 / 2016-03-29
|
||||||
|
==================
|
||||||
|
|
||||||
|
* refactor: add more ua info on syncer
|
||||||
|
|
||||||
|
2.9.0 / 2016-03-26
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat: only admin can unpublish
|
||||||
|
* chore(package): update gravatar to version 1.5.0
|
||||||
|
* chore(package): update sequelize to version 3.20.0
|
||||||
|
* fix: fix save download count unqiue constraint error
|
||||||
|
* chore(package): update moment to version 2.12.0
|
||||||
|
|
||||||
|
2.8.1 / 2016-03-07
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: only send warning email if no any sync data after 24h
|
||||||
|
* chore(package): update kcors to version 1.1.0
|
||||||
|
* chore(package): update koa to version 1.2.0
|
||||||
|
* chore(package): update urllib to version 2.8.0
|
||||||
|
|
||||||
|
2.8.0 / 2016-02-23
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: convert `*` to latest tag
|
||||||
|
* deps: upgrade deps and remove node 2.0.0 support
|
||||||
|
* doc: update sponsors on readme
|
||||||
|
* fix: update copyright year
|
||||||
|
* doc: fix disturl typo
|
||||||
|
* deps: sequelize@3.19.0
|
||||||
|
|
||||||
|
2.7.1 / 2016-02-01
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix(semver): when have invalid version([#817](https://github.com/cnpm/cnpmjs.org/issues/817))
|
||||||
|
|
||||||
|
2.7.0 / 2016-02-01
|
||||||
|
==================
|
||||||
|
|
||||||
|
* test: fix all test cases
|
||||||
|
* test: fix unpublish
|
||||||
|
* test: add complex range test case
|
||||||
|
* feat: support semver([#816](https://github.com/cnpm/cnpmjs.org/issues/816))
|
||||||
|
|
||||||
|
2.6.2 / 2016-01-19
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat: list & show support jsonp
|
||||||
|
* chore(package): update urllib to version 2.7.0
|
||||||
|
* Delete install.md
|
||||||
|
|
||||||
|
2.6.1 / 2016-01-12
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: source registry is not cnpm, ignore check status
|
||||||
|
|
||||||
|
2.6.0 / 2016-01-12
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat(sync): monitor sync status
|
||||||
|
* chore(package): update agentkeepalive to version 2.0.3
|
||||||
|
* fix SequelizeDatabaseError: ER_NO_SUCH_TABLE: Table 'qnpm.total' doesn't exist\nreproduce this bug:\nthe first startup of cnpmjs.org
|
||||||
|
* chore(package): update moment to version 2.11.0
|
||||||
|
* chore(package): update xss to version 0.2.10
|
||||||
|
* chore(package): update pg-hstore to version 2.3.2
|
||||||
|
* chore(package): update mini-logger to version 1.1.0
|
||||||
|
* chore(package): update urllib to version 2.6.0
|
||||||
|
* fix: row.package will json parse error
|
||||||
|
* remove bluebird
|
||||||
|
* chore(package): update utility to version 1.6.0
|
||||||
|
|
||||||
|
2.5.1 / 2015-12-02
|
||||||
|
==================
|
||||||
|
|
||||||
|
* chore(package): update bluebird to version 3.0.6
|
||||||
|
* fix: SequelizeDatabaseError
|
||||||
|
* fix(dist_tag): disable delete latest tag
|
||||||
|
* feat: count total private pkgs
|
||||||
|
* fix: use isoweek. a week start from monday
|
||||||
|
* chore(package): update xss to version 0.2.8
|
||||||
|
* chore(package): update semver to version 5.1.0
|
||||||
|
|
||||||
|
2.5.0 / 2015-11-17
|
||||||
|
==================
|
||||||
|
|
||||||
|
* test: add node v5
|
||||||
|
* feat(sync): sync deleted user
|
||||||
|
* Update show.js
|
||||||
|
* chore(package): update bytes to version 2.2.0
|
||||||
|
* do not sync inner username
|
||||||
|
* gzip static file
|
||||||
|
* chore(package): update bytes to version 2.1.0
|
||||||
|
* chore(package): update is-type-of to version 1.0.0
|
||||||
|
* Update static.js
|
||||||
|
* chore(package): update cfork to version 1.4.0
|
||||||
|
* chore(package): update bluebird to version 3.0.5
|
||||||
|
|
||||||
|
2.4.1 / 2015-10-27
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: improve registry index page performance with cache
|
||||||
|
* Configable badge URL prefix.
|
||||||
|
* chore(package): update koa-mock to version 1.5.0
|
||||||
|
* chore(package): update urllib to version 2.5.0
|
||||||
|
* chore(package): update co to version 4.6.0
|
||||||
|
* chore(package): update semver to version 5.0.3
|
||||||
|
|
||||||
|
2.4.0 / 2015-10-21
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat(registry): add package's dependents api
|
||||||
|
* fix: show package's dependents
|
||||||
|
* chore(package): update utility to version 1.5.0
|
||||||
|
* chore(package): update bluebird to version 2.10.2
|
||||||
|
|
||||||
|
2.3.1 / 2015-10-15
|
||||||
|
==================
|
||||||
|
|
||||||
|
* refactor: remove gnode
|
||||||
|
* deps: upgrade giturl
|
||||||
|
* Some fixes
|
||||||
|
|
||||||
|
2.3.0 / 2015-10-15
|
||||||
|
==================
|
||||||
|
|
||||||
|
* Add dev dependencies.
|
||||||
|
* Package page fix.
|
||||||
|
* refactor: add more sync log
|
||||||
|
* Add mock data.
|
||||||
|
* refactor: add more sync log
|
||||||
|
* Fix sidebar overflow.
|
||||||
|
* Merge pull request [#680](https://github.com/cnpm/cnpmjs.org/issues/680) from ibigbug/ant-design
|
||||||
|
* Clean code.
|
||||||
|
* Indent.
|
||||||
|
* chore(package): update debug to version 2.2.0
|
||||||
|
* chore(package): update should to version 7.1.0
|
||||||
|
* chore(package): update koa to version 1.1.0
|
||||||
|
* Remove default adBanner.
|
||||||
|
* Package pages.
|
||||||
|
* Common styles.
|
||||||
|
* search page.
|
||||||
|
* Sync page.
|
||||||
|
* Profile page antd style.
|
||||||
|
* Unpublished pkg page style.
|
||||||
|
* Add page title for unpubed pkg.
|
||||||
|
* Index page style use antd.
|
||||||
|
* chore(package): update pg to version 4.4.2
|
||||||
|
* chore(package): update cfork to version 1.3.1
|
||||||
|
* chore(package): update moment to version 2.10.6
|
||||||
|
* feat(badge): Use qiniu cdn
|
||||||
|
|
||||||
|
2.2.1 / 2015-09-30
|
||||||
|
==================
|
||||||
|
|
||||||
|
* test: use istanbul
|
||||||
|
* pref: move out try/catch block
|
||||||
|
* fix: support nfs.url is generator
|
||||||
|
|
||||||
|
2.2.0 / 2015-09-29
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat: list packages by username
|
||||||
|
* test: use codecov
|
||||||
|
* feat(badge): support custom subject
|
||||||
|
* fix(sync): add recover logic
|
||||||
|
* feat(sync): add sync scripts
|
||||||
|
|
||||||
|
2.1.5 / 2015-09-05
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: only sync update packages
|
||||||
|
|
||||||
|
2.1.4 / 2015-09-05
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: support new array and old map format both
|
||||||
|
* fix: /-/all/since had been redirect to /-/all/static/today.json
|
||||||
|
* fix(list): let koa-etag to caculate the etag
|
||||||
|
|
||||||
|
2.1.3 / 2015-08-18
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: sync public scope package download url is wrong
|
||||||
|
* fix: default registry change to taobao registry
|
||||||
|
|
||||||
|
2.1.2 / 2015-08-09
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix(syncer): sync worker pkg null bug
|
||||||
|
* feat(web): add downloads badge
|
||||||
|
|
||||||
|
2.1.1 / 2015-07-27
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: fix private scope package detect
|
||||||
|
* fix: dont sync if upstream is npm registry
|
||||||
|
* fix(sync): support sync public scope package
|
||||||
|
* test: fix fails tests
|
||||||
|
* fix: ignore 503 server error
|
||||||
|
* fix: ignore sync 503 server error
|
||||||
|
|
||||||
|
2.1.0 / 2015-07-08
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat(web): search support jsonp
|
||||||
|
* fix function name
|
||||||
|
|
||||||
|
2.0.0 / 2015-05-11
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix: real download as stream
|
||||||
|
* add custom ad banner config
|
||||||
|
* add sponsors: ucloud.cn
|
||||||
|
* fix small typo
|
||||||
|
* feat(urllib): support http_proxy
|
||||||
|
* force using https links
|
||||||
|
|
||||||
|
2.0.0-rc.15 / 2015-02-15
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix(markdown): filter xss after markdown render
|
||||||
|
* feat(database): support PostgreSQL
|
||||||
|
|
||||||
|
2.0.0-rc.14 / 2015-02-14
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat: support always-auth
|
||||||
|
* fix mysql select args = [] bug
|
||||||
|
* fix [#597](https://github.com/cnpm/cnpmjs.org/issues/597) sequelize raw query.
|
||||||
|
* fix(markdown): hotfix markdown-it cpu problem
|
||||||
|
* feat: upgrade to co4
|
||||||
|
* use kcors fixes [#594](https://github.com/cnpm/cnpmjs.org/issues/594)
|
||||||
|
|
||||||
|
2.0.0-rc.13 / 2015-02-04
|
||||||
|
==================
|
||||||
|
|
||||||
|
* docs: Deploy a private npm registry in 5 minutes
|
||||||
|
* refactor(config): move application data to ~/.cnpmjs.org/
|
||||||
|
* fix(sync): make get popular pakcage faster
|
||||||
|
* feat(sync): web page also redirect to npm www
|
||||||
|
* refactor(config): make syncModel to none by default
|
||||||
|
* test: fix admin can not publish non-scoped package test cases
|
||||||
|
* docs: add chinese mirror link
|
||||||
|
* fix: admin can not publish non scoped package on "none" sync model
|
||||||
|
* feat(sync): enable none syncModel proxy all public packages
|
||||||
|
* fix: ignore username start with " or '
|
||||||
|
* fix(bin): fix stop not work on iojs
|
||||||
|
|
||||||
|
2.0.0-rc.12 / 2015-02-01
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat(syncer): add hostname ua
|
||||||
|
* fix(web): remove pkg.contributors logic
|
||||||
|
|
||||||
|
2.0.0-rc.11 / 2015-02-01
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix xss tests
|
||||||
|
* fix(markdown): revert marky-markdown
|
||||||
|
|
||||||
|
2.0.0-rc.10 / 2015-01-31
|
||||||
|
==================
|
||||||
|
|
||||||
|
* feat(middleware): CORS headers for GET and HEAD requests
|
||||||
|
* fix(readme): fix index page markdown
|
||||||
|
* feat(markdown): use npm same markdown parser
|
||||||
|
* feat(download): support download redirect to nfs
|
||||||
|
* feat(syncer): request npm registry with gzip
|
||||||
|
* change(sync): remove dist syncer
|
||||||
|
* feat(registry): add dist tag api
|
||||||
|
* refactor(common): remove redis store
|
||||||
|
|
||||||
|
2.0.0-rc.9 / 2015-01-22
|
||||||
|
==================
|
||||||
|
|
||||||
|
* hotfix reame render error, pin xss
|
||||||
|
* fix registry user auth api
|
||||||
|
|
||||||
|
2.0.0-rc.8 / 2015-01-10
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix(markdown): readme.md allow scripts
|
||||||
|
* fix(style) flexbox compatibility for both chrome and firefox (@afc163)
|
||||||
|
* feat(sync): default sync exist packages
|
||||||
|
|
||||||
|
2.0.0-rc.7 / 2015-01-07
|
||||||
|
==================
|
||||||
|
|
||||||
|
* install sync dont check `enablePrivate`
|
||||||
|
* fix(markdown): filter xss readme before markdown render
|
||||||
|
|
||||||
|
2.0.0-rc.6 / 2015-01-05
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix(markdown): use markdown-it
|
||||||
|
* add userService options on config
|
||||||
|
* add upload to nfs sync info log
|
||||||
|
|
||||||
|
2.0.0-rc.5 / 2015-01-03
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix(markdown): use marked instead of remarkable
|
||||||
|
* fix(package): pkg.readme is not a string, dont remarkable it
|
||||||
|
* feat(sync): sync user profile
|
||||||
|
|
||||||
|
2.0.0-rc.4 / 2014-12-25
|
||||||
|
==================
|
||||||
|
|
||||||
|
* refactor(download): try to use nsf.url() first
|
||||||
|
* use __all__ for full downloads
|
||||||
|
* refactor(download_total): optimize download total
|
||||||
|
* fix sqlite raw sql return datetime is string format
|
||||||
|
* fix(download_total): change column date to DateTime
|
||||||
|
* fix(services/download_total): fix download_total slow sql on `date >= $start and date <= $end`
|
||||||
|
* fix(markdown): replace marked use remarkable
|
||||||
|
|
||||||
|
2.0.0-rc.3 / 2014-12-14
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix(services): need to detect instance isDirty or not before save()
|
||||||
|
|
||||||
|
2.0.0-rc.2 / 2014-12-11
|
||||||
|
==================
|
||||||
|
|
||||||
|
* add download API, closes [#529](https://github.com/cnpm/cnpmjs.org/issues/529)
|
||||||
|
* fix missing home page title (@rockdai)
|
||||||
|
* Fix typo in view/web/package.html (@LoicMahieu)
|
||||||
|
|
||||||
2.0.0-rc.1 / 2014-12-09
|
2.0.0-rc.1 / 2014-12-09
|
||||||
==================
|
==================
|
||||||
|
|
||||||
@@ -8,7 +478,7 @@
|
|||||||
2.0.0-beta5 / 2014-12-05
|
2.0.0-beta5 / 2014-12-05
|
||||||
==================
|
==================
|
||||||
|
|
||||||
* hotfix package.html typo. Closes #521
|
* hotfix package.html typo. Closes [#521](https://github.com/cnpm/cnpmjs.org/issues/521)
|
||||||
* Add editorconfig
|
* Add editorconfig
|
||||||
* fix(web/package): package name to long cause style problem fix
|
* fix(web/package): package name to long cause style problem fix
|
||||||
* fix(css): use github-markdown-css for markdown body
|
* fix(css): use github-markdown-css for markdown body
|
||||||
@@ -20,7 +490,7 @@
|
|||||||
* fix(registry): add missing /-/short api
|
* fix(registry): add missing /-/short api
|
||||||
* zoom sync link
|
* zoom sync link
|
||||||
* new design for package page
|
* new design for package page
|
||||||
* image max width, fixed #505
|
* image max width, fixed [#505](https://github.com/cnpm/cnpmjs.org/issues/505)
|
||||||
* feat(middleware): block Ruby user-agent
|
* feat(middleware): block Ruby user-agent
|
||||||
|
|
||||||
2.0.0-beta3 / 2014-11-12
|
2.0.0-beta3 / 2014-11-12
|
||||||
@@ -50,7 +520,7 @@
|
|||||||
2.0.0-beta0 / 2014-11-02
|
2.0.0-beta0 / 2014-11-02
|
||||||
==================
|
==================
|
||||||
|
|
||||||
* ungrade koa-markdown to use remarkable, close #482
|
* ungrade koa-markdown to use remarkable, close [#482](https://github.com/cnpm/cnpmjs.org/issues/482)
|
||||||
* fix(module_log): limit module sync log size to 1MB
|
* fix(module_log): limit module sync log size to 1MB
|
||||||
* refactor(config): remove adaptScope config key
|
* refactor(config): remove adaptScope config key
|
||||||
* chore(Makefile): $ make install-production
|
* chore(Makefile): $ make install-production
|
||||||
@@ -513,7 +983,7 @@
|
|||||||
* npm publish dont contains .jshint*
|
* npm publish dont contains .jshint*
|
||||||
* npm test run jshint
|
* npm test run jshint
|
||||||
* Add jshint check: $ make jshint
|
* Add jshint check: $ make jshint
|
||||||
* use `yield* next` instead of `yield next`
|
* use `yield next` instead of `yield next`
|
||||||
* replace dist.u.qiniudn.com with cnpmjs.org/dist
|
* replace dist.u.qiniudn.com with cnpmjs.org/dist
|
||||||
|
|
||||||
0.3.5 / 2014-03-05
|
0.3.5 / 2014-03-05
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
This software is licensed under the MIT License.
|
This software is licensed under the MIT License.
|
||||||
|
|
||||||
Copyright(c) cnpmjs.org and other contributors.
|
Copyright(c) cnpm and other contributors.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
103
Makefile
103
Makefile
@@ -1,103 +0,0 @@
|
|||||||
TESTS = $(shell ls -S `find test -type f -name "*.test.js" -print`)
|
|
||||||
REPORTER = spec
|
|
||||||
TIMEOUT = 30000
|
|
||||||
MOCHA_OPTS =
|
|
||||||
REGISTRY = --registry=https://registry.npm.taobao.org
|
|
||||||
DB = sqlite
|
|
||||||
|
|
||||||
install:
|
|
||||||
@npm install --build-from-source $(REGISTRY) \
|
|
||||||
--disturl=https://npm.taobao.org/dist
|
|
||||||
|
|
||||||
install-production production:
|
|
||||||
@NODE_ENV=production $(MAKE) install
|
|
||||||
|
|
||||||
jshint: install
|
|
||||||
@-node_modules/.bin/jshint ./
|
|
||||||
|
|
||||||
init-database:
|
|
||||||
@node --harmony test/init_db.js
|
|
||||||
|
|
||||||
init-mysql:
|
|
||||||
@mysql -uroot -e 'DROP DATABASE IF EXISTS cnpmjs_test;'
|
|
||||||
@mysql -uroot -e 'CREATE DATABASE cnpmjs_test;'
|
|
||||||
|
|
||||||
test: install init-database
|
|
||||||
@NODE_ENV=test DB=${DB} node_modules/.bin/mocha \
|
|
||||||
--harmony \
|
|
||||||
--reporter $(REPORTER) \
|
|
||||||
--timeout $(TIMEOUT) \
|
|
||||||
--require should \
|
|
||||||
--require should-http \
|
|
||||||
--require co-mocha \
|
|
||||||
--require ./test/init.js \
|
|
||||||
$(MOCHA_OPTS) \
|
|
||||||
$(TESTS)
|
|
||||||
|
|
||||||
test-sqlite:
|
|
||||||
@$(MAKE) test DB=sqlite
|
|
||||||
|
|
||||||
test-mysql: init-mysql
|
|
||||||
@$(MAKE) test DB=mysql
|
|
||||||
|
|
||||||
test-all: test-sqlite test-mysql
|
|
||||||
|
|
||||||
test-cov cov: install init-database
|
|
||||||
@NODE_ENV=test DB=${DB} node --harmony \
|
|
||||||
node_modules/.bin/istanbul cover --preserve-comments \
|
|
||||||
node_modules/.bin/_mocha \
|
|
||||||
-- -u exports \
|
|
||||||
--reporter $(REPORTER) \
|
|
||||||
--timeout $(TIMEOUT) \
|
|
||||||
--require should \
|
|
||||||
--require should-http \
|
|
||||||
--require co-mocha \
|
|
||||||
--require ./test/init.js \
|
|
||||||
$(MOCHA_OPTS) \
|
|
||||||
$(TESTS)
|
|
||||||
|
|
||||||
test-cov-sqlite:
|
|
||||||
@$(MAKE) test-cov DB=sqlite
|
|
||||||
|
|
||||||
test-cov-mysql: init-mysql
|
|
||||||
@$(MAKE) test-cov DB=mysql
|
|
||||||
|
|
||||||
test-travis: install init-database
|
|
||||||
@NODE_ENV=test DB=${DB} 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 \
|
|
||||||
-- \
|
|
||||||
--reporter dot \
|
|
||||||
--timeout $(TIMEOUT) \
|
|
||||||
--require should \
|
|
||||||
--require should-http \
|
|
||||||
--require co-mocha \
|
|
||||||
--require ./test/init.js \
|
|
||||||
$(MOCHA_OPTS) \
|
|
||||||
$(TESTS)
|
|
||||||
|
|
||||||
test-travis-sqlite:
|
|
||||||
@$(MAKE) test-travis DB=sqlite
|
|
||||||
|
|
||||||
test-travis-mysql: init-mysql
|
|
||||||
@$(MAKE) test-travis DB=mysql
|
|
||||||
|
|
||||||
test-travis-all: test-travis-sqlite test-travis-mysql
|
|
||||||
|
|
||||||
dev:
|
|
||||||
@NODE_ENV=development 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 \
|
|
||||||
--prefix "~" \
|
|
||||||
--exclude public,view,docs,backup,coverage \
|
|
||||||
--dep bluebird,mysql \
|
|
||||||
--keep should,supertest,should-http,chunkstream,mm,pedding
|
|
||||||
@$(MAKE) install
|
|
||||||
|
|
||||||
.PHONY: test
|
|
||||||
56
README.md
56
README.md
@@ -3,29 +3,23 @@ cnpmjs.org
|
|||||||
|
|
||||||
[![NPM version][npm-image]][npm-url]
|
[![NPM version][npm-image]][npm-url]
|
||||||
[![build status][travis-image]][travis-url]
|
[![build status][travis-image]][travis-url]
|
||||||
[![Test coverage][coveralls-image]][coveralls-url]
|
[![Test coverage][codecov-image]][codecov-url]
|
||||||
[![Gittip][gittip-image]][gittip-url]
|
|
||||||
[![David deps][david-image]][david-url]
|
[![David deps][david-image]][david-url]
|
||||||
[![node version][node-image]][node-url]
|
[![Known Vulnerabilities][snyk-image]][snyk-url]
|
||||||
[![npm download][download-image]][download-url]
|
[![npm download][download-image]][download-url]
|
||||||
[![gitter][gitter-image]][gitter-url]
|
|
||||||
|
|
||||||
[npm-image]: http://cnpmjs.org/badge/v/cnpmjs.org.svg?style=flat-square
|
[npm-image]: http://cnpmjs.org/badge/v/cnpmjs.org.svg?style=flat-square
|
||||||
[npm-url]: http://cnpmjs.org/package/cnpmjs.org
|
[npm-url]: http://cnpmjs.org/package/cnpmjs.org
|
||||||
[travis-image]: https://img.shields.io/travis/cnpm/cnpmjs.org.svg?style=flat-square
|
[travis-image]: https://img.shields.io/travis/cnpm/cnpmjs.org.svg?style=flat-square
|
||||||
[travis-url]: https://travis-ci.org/cnpm/cnpmjs.org
|
[travis-url]: https://travis-ci.org/cnpm/cnpmjs.org
|
||||||
[coveralls-image]: https://img.shields.io/coveralls/cnpm/cnpmjs.org.svg?style=flat-square
|
[codecov-image]: https://codecov.io/gh/cnpm/cnpmjs.org/branch/master/graph/badge.svg
|
||||||
[coveralls-url]: https://coveralls.io/r/cnpm/cnpmjs.org?branch=master
|
[codecov-url]: https://codecov.io/gh/cnpm/cnpmjs.org
|
||||||
[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-square
|
[david-image]: https://img.shields.io/david/cnpm/cnpmjs.org.svg?style=flat-square
|
||||||
[david-url]: https://david-dm.org/cnpm/cnpmjs.org
|
[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
|
[snyk-image]: https://snyk.io/test/npm/cnpmjs.org/badge.svg?style=flat-square
|
||||||
[node-url]: http://nodejs.org/download/
|
[snyk-url]: https://snyk.io/test/npm/cnpmjs.org
|
||||||
[download-image]: https://img.shields.io/npm/dm/cnpmjs.org.svg?style=flat-square
|
[download-image]: https://img.shields.io/npm/dm/cnpmjs.org.svg?style=flat-square
|
||||||
[download-url]: https://npmjs.org/package/cnpmjs.org
|
[download-url]: https://npmjs.org/package/cnpmjs.org
|
||||||
[gitter-image]: https://badges.gitter.im/Join%20Chat.svg
|
|
||||||
[gitter-url]: https://gitter.im/cnpm/cnpmjs.org?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -42,9 +36,10 @@ Our goal is to provide a low cost maintenance and easy to use solution for priva
|
|||||||
* Build a mirror NPM. (we use it to build a mirror in China: [cnpmjs.org](http://cnpmjs.org/))
|
* Build a mirror NPM. (we use it to build a mirror in China: [cnpmjs.org](http://cnpmjs.org/))
|
||||||
* Build a completely independent NPM registry to store whatever you like.
|
* Build a completely independent NPM registry to store whatever you like.
|
||||||
|
|
||||||
### Features
|
## Features
|
||||||
|
|
||||||
* **Support "scoped" packages**: [npm/npm#5239](https://github.com/npm/npm/issues/5239)
|
* **Support "scoped" packages**: [npm/npm#5239](https://github.com/npm/npm/issues/5239)
|
||||||
|
* **Support [CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing)**
|
||||||
* **Simple to deploy**: only need `mysql` and a [simple store system](https://github.com/cnpm/cnpmjs.org/wiki/NFS-Guide).
|
* **Simple to deploy**: only need `mysql` and a [simple store system](https://github.com/cnpm/cnpmjs.org/wiki/NFS-Guide).
|
||||||
You can get the source code through `npm` or `git`.
|
You can get the source code through `npm` or `git`.
|
||||||
* **Low cost and easy maintenance**: `package.json` info store in MySQL, MariaDB, SQLite or PostgreSQL databases,
|
* **Low cost and easy maintenance**: `package.json` info store in MySQL, MariaDB, SQLite or PostgreSQL databases,
|
||||||
@@ -59,24 +54,27 @@ 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`,
|
* **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).
|
only need to change the registry in config. Even include manual synchronization (through `install` command).
|
||||||
* **Version badge**: base on [shields.io](http://shields.io/) 
|
* **Version badge**: base on [shields.io](http://shields.io/) 
|
||||||
|
* **Support http_proxy**: if you're behind firewall, need to request through http proxy
|
||||||
|
|
||||||
**PROTIP** Be sure to read [Migrating from 1.x to 2.x](https://github.com/cnpm/cnpmjs.org/wiki/Migrating-from-1.x-to-2.x)
|
**PROTIP** Be sure to read [Migrating from 1.x to 2.x](https://github.com/cnpm/cnpmjs.org/wiki/Migrating-from-1.x-to-2.x)
|
||||||
as well as [New features in 2.x](https://github.com/cnpm/cnpmjs.org/wiki/New-features-in-2.x).
|
as well as [New features in 2.x](https://github.com/cnpm/cnpmjs.org/wiki/New-features-in-2.x).
|
||||||
|
|
||||||
## Getting Start
|
## Getting Start
|
||||||
|
|
||||||
|
* [Deploy a private npm registry in 5 minutes](https://github.com/cnpm/cnpmjs.org/wiki/Deploy-a-private-npm-registry-in-5-minutes)
|
||||||
* @[dead-horse](https://github.com/dead-horse): [What is cnpm?](http://deadhorse.me/slides/cnpmjs.html)
|
* @[dead-horse](https://github.com/dead-horse): [What is cnpm?](http://deadhorse.me/slides/cnpmjs.html)
|
||||||
* install and deploy cnpmjs.org through npm: [examples](https://github.com/cnpm/custom-cnpm-example)
|
* install and deploy cnpmjs.org through npm: [examples](https://github.com/cnpm/custom-cnpm-example)
|
||||||
* Mirror NPM in China: [cnpmjs.org](http://cnpmjs.org)
|
* Mirror NPM in China: [cnpmjs.org](http://cnpmjs.org)
|
||||||
* cnpm client: [cnpm](https://github.com/cnpm/cnpm), `npm install -g cnpm`
|
* 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)
|
* [How to deploy cnpmjs.org](https://github.com/cnpm/cnpmjs.org/wiki/Deploy)
|
||||||
|
* [Sync packages through `http_proxy`](https://github.com/cnpm/cnpmjs.org/wiki/Sync-packages-through-http_proxy)
|
||||||
* [wiki](https://github.com/cnpm/cnpmjs.org/wiki)
|
* [wiki](https://github.com/cnpm/cnpmjs.org/wiki)
|
||||||
|
|
||||||
## Develop on your local machine
|
## Develop on your local machine
|
||||||
|
|
||||||
### Dependencies
|
### Dependencies
|
||||||
|
|
||||||
* [node](http://nodejs.org) >=0.11.12, use `--harmony`
|
* [node](http://nodejs.org) >= 4.3.1
|
||||||
* Databases: only required one type
|
* Databases: only required one type
|
||||||
* [sqlite3](https://npm.taobao.org/package/sqlite3) >= 3.0.2, we use `sqlite3` by default
|
* [sqlite3](https://npm.taobao.org/package/sqlite3) >= 3.0.2, we use `sqlite3` by default
|
||||||
* [MySQL](http://dev.mysql.com/downloads/) >= 0.5.0, include `mysqld` and `mysql cli`. I test on `mysql@5.6.16`.
|
* [MySQL](http://dev.mysql.com/downloads/) >= 0.5.0, include `mysqld` and `mysql cli`. I test on `mysql@5.6.16`.
|
||||||
@@ -98,7 +96,7 @@ $ make test
|
|||||||
# coverage
|
# coverage
|
||||||
$ make test-cov
|
$ make test-cov
|
||||||
|
|
||||||
# udpate dependencies
|
# update dependencies
|
||||||
$ make autod
|
$ make autod
|
||||||
|
|
||||||
# start server with development mode
|
# start server with development mode
|
||||||
@@ -114,27 +112,11 @@ $ make dev
|
|||||||
|
|
||||||
Tips: make sure your code is following the [node-style-guide](https://github.com/felixge/node-style-guide).
|
Tips: make sure your code is following the [node-style-guide](https://github.com/felixge/node-style-guide).
|
||||||
|
|
||||||
|
## Sponsors
|
||||||
|
|
||||||
|
- [](http://click.aliyun.com/m/4288/) (2016.2 - now)
|
||||||
|
- [](http://www.ucloud.cn?sem=sdk-CNPMJS) (2015.3 - 2016.3)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
(The MIT License)
|
[MIT](LICENSE.txt)
|
||||||
|
|
||||||
Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
a copy of this software and associated documentation files (the
|
|
||||||
'Software'), to deal in the Software without restriction, including
|
|
||||||
without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
|
||||||
included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
||||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
||||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
||||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|||||||
142
backup/dump.js
142
backup/dump.js
@@ -1,142 +0,0 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - backup/dump.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 1. dump module
|
|
||||||
* 2. dump tag
|
|
||||||
* 3. dump user
|
|
||||||
* 4. total
|
|
||||||
* 5. download_total
|
|
||||||
*/
|
|
||||||
|
|
||||||
var path = require('path');
|
|
||||||
var fs = require('fs');
|
|
||||||
var moment = require('moment');
|
|
||||||
var eventproxy = require('eventproxy');
|
|
||||||
var util = require('util');
|
|
||||||
var zlib = require('zlib');
|
|
||||||
var mysql = require('../common/mysql');
|
|
||||||
var nfs = require('../common/nfs');
|
|
||||||
var config = require('../config');
|
|
||||||
|
|
||||||
function dumpTable(name, lastRow, callback) {
|
|
||||||
var sql = 'SELECT * from ' + name + ' WHERE gmt_modified >=? ORDER BY gmt_modified ASC LIMIT 10000;';
|
|
||||||
mysql.query(sql, [lastRow.gmt_modified], function (err, rows) {
|
|
||||||
if (err || rows.length === 0) {
|
|
||||||
return callback(err, rows);
|
|
||||||
}
|
|
||||||
if (rows[0].id === lastRow.id) {
|
|
||||||
rows = rows.slice(1);
|
|
||||||
}
|
|
||||||
callback(null, rows);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function log() {
|
|
||||||
var str = '[' + moment().format('YYYY-MM-DD HH:mm:ss') + '] ' + util.format.apply(util, arguments);
|
|
||||||
console.log(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
function syncTable(name, callback) {
|
|
||||||
var datadir = __dirname;
|
|
||||||
var dataFile = path.join(datadir, moment().format('YYYY-MM-DD-HH') + '_' + name + '.json');
|
|
||||||
var lastRowFile = path.join(datadir, name + '_lastdate.json');
|
|
||||||
var lastRow = null;
|
|
||||||
if (fs.existsSync(lastRowFile)) {
|
|
||||||
lastRow = require(lastRowFile);
|
|
||||||
lastRow.gmt_modified = new Date(Date.parse(lastRow.gmt_modified));
|
|
||||||
} else {
|
|
||||||
lastRow = {
|
|
||||||
gmt_modified: new Date('2011-11-11'),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
log('getting "%s" since %j', name, lastRow);
|
|
||||||
dumpTable(name, lastRow, function (err, rows) {
|
|
||||||
console.log('[%s] got %d rows', Date(), rows && rows.length || 0);
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rows || rows.length === 0) {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
var writeStream = fs.createWriteStream(dataFile, {flags: 'a'});
|
|
||||||
writeStream.once('error', callback);
|
|
||||||
for (var i = 0; i < rows.length; i++) {
|
|
||||||
writeStream.write(JSON.stringify(rows[i]) + '\n');
|
|
||||||
}
|
|
||||||
writeStream.end();
|
|
||||||
writeStream.on('finish', function () {
|
|
||||||
log('append %d rows to %s', rows.length, dataFile);
|
|
||||||
var gzfile = dataFile + '.gz';
|
|
||||||
var gzip = zlib.createGzip();
|
|
||||||
var inp = fs.createReadStream(dataFile);
|
|
||||||
var out = fs.createWriteStream(gzfile);
|
|
||||||
inp.pipe(gzip).pipe(out);
|
|
||||||
out.once('error', callback);
|
|
||||||
out.on('finish', function () {
|
|
||||||
var key = path.join(config.backupFilePrefix, path.basename(gzfile));
|
|
||||||
log('saving %s to %s ...', gzfile, key);
|
|
||||||
nfs.upload(gzfile, {key: key}, function (err, result) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
lastRow = rows[rows.length - 1];
|
|
||||||
lastRow = {gmt_modified: lastRow.gmt_modified, id: lastRow.id};
|
|
||||||
fs.writeFileSync(lastRowFile, JSON.stringify(lastRow));
|
|
||||||
log('save %s data file to %j, lastrow: %j', name, result, lastRow);
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var ep = eventproxy.create();
|
|
||||||
ep.fail(function (err) {
|
|
||||||
log('error: %s', err.stack);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
syncTable('module', ep.done('module'));
|
|
||||||
|
|
||||||
ep.on('module', function () {
|
|
||||||
syncTable('tag', ep.done('tag'));
|
|
||||||
});
|
|
||||||
|
|
||||||
ep.on('tag', function () {
|
|
||||||
syncTable('user', ep.done('user'));
|
|
||||||
});
|
|
||||||
|
|
||||||
ep.on('user', function () {
|
|
||||||
syncTable('total', ep.done('total'));
|
|
||||||
});
|
|
||||||
|
|
||||||
ep.on('total', function () {
|
|
||||||
syncTable('download_total', ep.done('download_total'));
|
|
||||||
});
|
|
||||||
|
|
||||||
ep.on('download_total', function () {
|
|
||||||
ep.emit('finish');
|
|
||||||
});
|
|
||||||
|
|
||||||
ep.on('finish', function () {
|
|
||||||
log('finish, %d process exit', process.pid);
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
||||||
24
bin/change_password.js
Normal file
24
bin/change_password.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
'use strict';
|
||||||
|
// Only support for ./services/DefaultUserService. If you use custom user service, ignore this file.
|
||||||
|
// call with:
|
||||||
|
// $ node ./bin/change_password.js 'username' 'new_password'
|
||||||
|
|
||||||
|
const UserModel = require('../models').User;
|
||||||
|
const co = require('co');
|
||||||
|
const utility = require('utility');
|
||||||
|
|
||||||
|
const username = process.argv[2];
|
||||||
|
const newPassword = process.argv[3];
|
||||||
|
|
||||||
|
co(function* () {
|
||||||
|
let user = yield UserModel.find({ where: { name: username } });
|
||||||
|
const salt = user.salt;
|
||||||
|
console.log(`user original password_sha: ${user.password_sha}`);
|
||||||
|
const newPasswordSha = utility.sha1(newPassword + salt);
|
||||||
|
user.password_sha = newPasswordSha;
|
||||||
|
user = yield user.save();
|
||||||
|
console.log(`change user password successful!! user new password_sha: ${user.password_sha}`);
|
||||||
|
process.exit(0);
|
||||||
|
}).catch(function(e) {
|
||||||
|
console.log(e);
|
||||||
|
});
|
||||||
118
bin/cli.js
Executable file
118
bin/cli.js
Executable file
@@ -0,0 +1,118 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const debug = require('debug')('cnpmjs.org:cli');
|
||||||
|
const program = require('commander');
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
const mkdirp = require('mkdirp');
|
||||||
|
const treekill = require('treekill');
|
||||||
|
const version = require('../package.json').version;
|
||||||
|
|
||||||
|
function list(val) {
|
||||||
|
return val.split(',');
|
||||||
|
}
|
||||||
|
|
||||||
|
program
|
||||||
|
.version(version);
|
||||||
|
|
||||||
|
program
|
||||||
|
.command('start')
|
||||||
|
.description('start cnpmjs.org server')
|
||||||
|
.option('--admins <admins>', 'set admins', list)
|
||||||
|
.option('--scopes <scopes>', 'set scopes', list)
|
||||||
|
// .option('--cluster', 'enable cluster mode')
|
||||||
|
.option('--dataDir <dataDir>', 'cnpmjs.org data dir, default is `$HOME/.cnpmjs.org`')
|
||||||
|
.action(start);
|
||||||
|
|
||||||
|
program
|
||||||
|
.command('stop')
|
||||||
|
.description('stop cnpmjs.org server')
|
||||||
|
.option('--dataDir <dataDir>', 'cnpmjs.org data dir, default is `$HOME/.cnpmjs.org`')
|
||||||
|
.action(stop);
|
||||||
|
|
||||||
|
program.parse(process.argv);
|
||||||
|
|
||||||
|
|
||||||
|
function start(options) {
|
||||||
|
stop(options);
|
||||||
|
const dataDir = options.dataDir || path.join(process.env.HOME, '.cnpmjs.org');
|
||||||
|
mkdirp.sync(dataDir);
|
||||||
|
|
||||||
|
const configfile = path.join(dataDir, 'config.json');
|
||||||
|
let config = {};
|
||||||
|
if (fs.existsSync(configfile)) {
|
||||||
|
try {
|
||||||
|
config = require(configfile);
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('load old %s error: %s', configfile, err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// config.enableCluster = !!options.cluster;
|
||||||
|
if (options.admins) {
|
||||||
|
config.admins = {};
|
||||||
|
for (let i = 0; i < options.admins.length; i++) {
|
||||||
|
config.admins[options.admins[i]] = options.admins[i] + '@localhost.com';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (options.scopes) {
|
||||||
|
config.scopes = options.scopes.map(function(name) {
|
||||||
|
if (name[0] !== '@') {
|
||||||
|
name = '@' + name;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const configJSON = JSON.stringify(config, null, 2);
|
||||||
|
fs.writeFileSync(configfile, configJSON);
|
||||||
|
|
||||||
|
debug('save config %s to %s', configJSON, configfile);
|
||||||
|
|
||||||
|
// if sqlite db file not exists, init first
|
||||||
|
initDatabase(function() {
|
||||||
|
require('../dispatch');
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.writeFileSync(path.join(dataDir, 'pid'), process.pid + '');
|
||||||
|
}
|
||||||
|
|
||||||
|
function stop(options) {
|
||||||
|
const dataDir = options.dataDir || path.join(process.env.HOME, '.cnpmjs.org');
|
||||||
|
const pidfile = path.join(dataDir, 'pid');
|
||||||
|
if (fs.existsSync(pidfile)) {
|
||||||
|
const pid = Number(fs.readFileSync(pidfile, 'utf8'));
|
||||||
|
treekill(pid, function(err) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
console.log('cnpmjs.org server:%d stop', pid);
|
||||||
|
fs.unlinkSync(pidfile);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function initDatabase(callback) {
|
||||||
|
const models = require('../models');
|
||||||
|
|
||||||
|
models.sequelize.sync({ force: false })
|
||||||
|
.then(function() {
|
||||||
|
models.Total.init(function(err) {
|
||||||
|
if (err) {
|
||||||
|
console.error('[models/init_script.js] sequelize init fail');
|
||||||
|
console.error(err);
|
||||||
|
throw err;
|
||||||
|
} else {
|
||||||
|
console.log('[models/init_script.js] `sqlite` sequelize sync and init success');
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
console.error('[models/init_script.js] sequelize sync fail');
|
||||||
|
console.error(err);
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ export NODE_ENV='production'
|
|||||||
ulimit -c unlimited
|
ulimit -c unlimited
|
||||||
|
|
||||||
cd `dirname $0`/..
|
cd `dirname $0`/..
|
||||||
NODEJS='node --harmony'
|
NODEJS='node'
|
||||||
BASE_HOME=`pwd`
|
BASE_HOME=`pwd`
|
||||||
PROJECT_NAME=`basename ${BASE_HOME}`
|
PROJECT_NAME=`basename ${BASE_HOME}`
|
||||||
STDOUT_LOG=`$NODEJS -e "console.log(require('path').join(require('$BASE_HOME/config').logdir, 'nodejs_stdout.log'));\
|
STDOUT_LOG=`$NODEJS -e "console.log(require('path').join(require('$BASE_HOME/config').logdir, 'nodejs_stdout.log'));\
|
||||||
@@ -52,9 +52,9 @@ stop()
|
|||||||
kill -15 $PID
|
kill -15 $PID
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|
||||||
node_num=`ps -ef |grep node|grep ${PROJECT_NAME}|grep -v grep|wc -l`
|
node_num=`ps -ef | grep ${PROJECT_NAME} | grep -v grep | wc -l`
|
||||||
if [ $node_num != 0 ]; then
|
if [ $node_num != 0 ]; then
|
||||||
ps -ef |grep node | grep ${PROJECT_NAME} |grep -v grep|awk '{print $2}'|xargs kill -9
|
ps -ef | grep ${PROJECT_NAME} |grep -v grep|awk '{print $2}'|xargs kill -9
|
||||||
ipcs -s | grep 0x | awk '{print $2}' | xargs -n1 ipcrm -s > /dev/null 2>&1
|
ipcs -s | grep 0x | awk '{print $2}' | xargs -n1 ipcrm -s > /dev/null 2>&1
|
||||||
ipcs -m | grep 0x | awk '{print $2}' | xargs -n1 ipcrm -m > /dev/null 2>&1
|
ipcs -m | grep 0x | awk '{print $2}' | xargs -n1 ipcrm -m > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,74 +0,0 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - bin/restore_module_deps.js
|
|
||||||
*
|
|
||||||
* Copyright(c) 2014
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var mysql = require('../common/mysql');
|
|
||||||
var Module = require('../proxy/module');
|
|
||||||
var ModuleDeps = require('../proxy/module_deps');
|
|
||||||
|
|
||||||
var addCount = 0;
|
|
||||||
|
|
||||||
function restore(id, callback) {
|
|
||||||
var sql = 'SELECT id, name, package FROM module WHERE id > ? ORDER BY id ASC LIMIT 1000';
|
|
||||||
mysql.query(sql, [id], function (err, rows) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
if (rows.length === 0) {
|
|
||||||
return callback(null, []);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('[%s] got %d rows', id, rows.length);
|
|
||||||
|
|
||||||
rows.forEach(function (r) {
|
|
||||||
Module.parseRow(r);
|
|
||||||
if (!r.package) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var deps = Object.keys(r.package.dependencies || {});
|
|
||||||
if (!Array.isArray(deps) || !deps.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
deps.forEach(function (dep) {
|
|
||||||
ModuleDeps.add(dep, r.name, function (err) {
|
|
||||||
// console.log('[%s] add %s <= %s, error: %s', id, dep, r.name, err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
addCount += deps.length;
|
|
||||||
});
|
|
||||||
setTimeout(function () {
|
|
||||||
console.log('[%s] add %d relations', id, addCount);
|
|
||||||
callback(null, rows);
|
|
||||||
}, 1000);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var id = 0;
|
|
||||||
function run() {
|
|
||||||
restore(id, function (err, rows) {
|
|
||||||
if (err) {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
if (rows.length === 0) {
|
|
||||||
console.log('finished, last id: %s, exit.', id);
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
id = rows[rows.length - 1].id;
|
|
||||||
run();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
run();
|
|
||||||
@@ -1,62 +1,56 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - common/logger.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const debug = require('debug')('cnpmjs.org:logger');
|
||||||
* Module dependencies.
|
const formater = require('error-formater');
|
||||||
*/
|
const Logger = require('mini-logger');
|
||||||
|
const utility = require('utility');
|
||||||
|
const util = require('util');
|
||||||
|
const os = require('os');
|
||||||
|
const config = require('../config');
|
||||||
|
const mail = require('./mail');
|
||||||
|
|
||||||
var formater = require('error-formater');
|
const isTEST = process.env.NODE_ENV === 'test';
|
||||||
var Logger = require('mini-logger');
|
const categories = [ 'sync_info', 'sync_error' ];
|
||||||
var utility = require('utility');
|
|
||||||
var util = require('util');
|
|
||||||
var config = require('../config');
|
|
||||||
var mail = require('./mail');
|
|
||||||
|
|
||||||
var isTEST = process.env.NODE_ENV === 'test';
|
const logger = module.exports = Logger({
|
||||||
var categories = ['sync_info', 'sync_error'];
|
categories,
|
||||||
|
|
||||||
var logger = module.exports = Logger({
|
|
||||||
categories: categories,
|
|
||||||
dir: config.logdir,
|
dir: config.logdir,
|
||||||
duration: '1d',
|
duration: '1d',
|
||||||
format: '[{category}.]YYYY-MM-DD[.log]',
|
format: '[{category}.]YYYY-MM-DD[.log]',
|
||||||
stdout: config.debug && !isTEST,
|
stdout: config.debug && !isTEST,
|
||||||
errorFormater: errorFormater
|
errorFormater,
|
||||||
|
seperator: os.EOL,
|
||||||
});
|
});
|
||||||
|
|
||||||
var to = [];
|
const to = [];
|
||||||
for (var user in config.admins) {
|
for (const user in config.admins) {
|
||||||
to.push(config.admins[user]);
|
to.push(config.admins[user]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function errorFormater(err) {
|
function errorFormater(err) {
|
||||||
var msg = formater.both(err);
|
const msg = formater.both(err);
|
||||||
mail.error(to, msg.json.name, msg.text);
|
mail.error(to, msg.json.name, msg.text);
|
||||||
return msg.text;
|
return msg.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.syncInfo = function () {
|
logger.syncInfo = function() {
|
||||||
var args = [].slice.call(arguments);
|
const args = [].slice.call(arguments);
|
||||||
if (typeof args[0] === 'string') {
|
if (typeof args[0] === 'string') {
|
||||||
args[0] = util.format('[%s][%s] ', utility.logDate(), process.pid) + args[0];
|
args[0] = util.format('[%s][%s] ', utility.logDate(), process.pid) + args[0];
|
||||||
}
|
}
|
||||||
|
if (debug.enabled) {
|
||||||
|
debug.apply(debug, args);
|
||||||
|
}
|
||||||
logger.sync_info.apply(logger, args);
|
logger.sync_info.apply(logger, args);
|
||||||
};
|
};
|
||||||
|
|
||||||
logger.syncError =function () {
|
logger.syncError = function() {
|
||||||
var args = [].slice.call(arguments);
|
const args = [].slice.call(arguments);
|
||||||
if (typeof args[0] === 'string') {
|
if (typeof args[0] === 'string') {
|
||||||
args[0] = util.format('[%s][%s] ', utility.logDate(), process.pid) + args[0];
|
args[0] = util.format('[%s][%s] ', utility.logDate(), process.pid) + args[0];
|
||||||
}
|
}
|
||||||
|
if (debug.enabled) {
|
||||||
|
debug.apply(debug, args);
|
||||||
|
}
|
||||||
logger.sync_error.apply(logger, arguments);
|
logger.sync_error.apply(logger, arguments);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,30 +1,17 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - common/mail.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const nodemailer = require('nodemailer');
|
||||||
* Module dependencies.
|
const utility = require('utility');
|
||||||
*/
|
const os = require('os');
|
||||||
|
const mailConfig = require('../config').mail;
|
||||||
|
|
||||||
var mailConfig = require('../config').mail;
|
let smtpConfig;
|
||||||
var nodemailer = require('nodemailer');
|
|
||||||
var utility = require('utility');
|
|
||||||
var os = require('os');
|
|
||||||
|
|
||||||
var smtpConfig;
|
|
||||||
if (mailConfig.auth) {
|
if (mailConfig.auth) {
|
||||||
// new style
|
// new style
|
||||||
smtpConfig = mailConfig;
|
smtpConfig = mailConfig;
|
||||||
} else {
|
} else {
|
||||||
smtpConfig = {
|
smtpConfig = {
|
||||||
|
enable: mailConfig.enable,
|
||||||
// backward compat
|
// backward compat
|
||||||
host: mailConfig.host,
|
host: mailConfig.host,
|
||||||
port: mailConfig.port,
|
port: mailConfig.port,
|
||||||
@@ -32,12 +19,12 @@ if (mailConfig.auth) {
|
|||||||
debug: mailConfig.debug,
|
debug: mailConfig.debug,
|
||||||
auth: {
|
auth: {
|
||||||
user: mailConfig.user,
|
user: mailConfig.user,
|
||||||
pass: mailConfig.pass
|
pass: mailConfig.pass,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var transport = nodemailer.createTransport(smtpConfig);
|
let transport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send notice email with mail level and appname.
|
* Send notice email with mail level and appname.
|
||||||
@@ -48,15 +35,16 @@ var transport = nodemailer.createTransport(smtpConfig);
|
|||||||
* @param {String} html
|
* @param {String} html
|
||||||
* @param {Function(err, result)} callback
|
* @param {Function(err, result)} callback
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.notice = function sendLogMail(to, level, subject, html, callback) {
|
exports.notice = function sendLogMail(to, level, subject, html, callback) {
|
||||||
subject = '[' + mailConfig.appname + '] [' + level + '] [' + os.hostname() + '] ' + subject;
|
subject = '[' + mailConfig.appname + '] [' + level + '] [' + os.hostname() + '] ' + subject;
|
||||||
html = String(html);
|
html = String(html);
|
||||||
exports.send(to, subject, html.replace(/\n/g, '<br/>'), callback);
|
exports.send(to, subject, html.replace(/\n/g, '<br/>'), callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
var LEVELS = [ 'log', 'warn', 'error' ];
|
const LEVELS = [ 'log', 'warn', 'error' ];
|
||||||
LEVELS.forEach(function (level) {
|
LEVELS.forEach(function(level) {
|
||||||
exports[level] = function (to, subject, html, callback) {
|
exports[level] = function(to, subject, html, callback) {
|
||||||
exports.notice(to, level, subject, html, callback);
|
exports.notice(to, level, subject, html, callback);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -68,17 +56,27 @@ LEVELS.forEach(function (level) {
|
|||||||
* @param {String} html
|
* @param {String} html
|
||||||
* @param {Function(err, result)} callback
|
* @param {Function(err, result)} callback
|
||||||
*/
|
*/
|
||||||
exports.send = function (to, subject, html, callback) {
|
|
||||||
|
exports.send = function(to, subject, html, callback) {
|
||||||
callback = callback || utility.noop;
|
callback = callback || utility.noop;
|
||||||
|
|
||||||
var message = {
|
if (mailConfig.enable === false) {
|
||||||
|
console.log('[send mail debug] [%s] to: %s, subject: %s\n%s', Date(), to, subject, html);
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!transport) {
|
||||||
|
transport = nodemailer.createTransport(smtpConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
const message = {
|
||||||
from: mailConfig.from || mailConfig.sender,
|
from: mailConfig.from || mailConfig.sender,
|
||||||
to: to,
|
to,
|
||||||
subject: subject,
|
subject,
|
||||||
html: html,
|
html,
|
||||||
};
|
};
|
||||||
|
|
||||||
transport.sendMail(message, function (err, result) {
|
transport.sendMail(message, function(err, result) {
|
||||||
callback(err, result);
|
callback(err, result);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
34
common/markdown.js
Normal file
34
common/markdown.js
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/**!
|
||||||
|
* cnpmjs.org - common/markdown.js
|
||||||
|
*
|
||||||
|
* Copyright(c) fengmk2 and other contributors.
|
||||||
|
* MIT Licensed
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module dependencies.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const xss = require('xss');
|
||||||
|
const MarkdownIt = require('markdown-it');
|
||||||
|
|
||||||
|
// allow class attr on code
|
||||||
|
xss.whiteList.code = [ 'class' ];
|
||||||
|
|
||||||
|
const md = new MarkdownIt({
|
||||||
|
html: true,
|
||||||
|
linkify: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
exports.render = function(content, filterXss) {
|
||||||
|
let html = md.render(content);
|
||||||
|
if (filterXss !== false) {
|
||||||
|
html = xss(html);
|
||||||
|
}
|
||||||
|
return html;
|
||||||
|
};
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
/*!
|
/* !
|
||||||
* cnpmjs.org - common/nfs.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
* Copyright(c) cnpmjs.org and other contributors.
|
||||||
* MIT Licensed
|
* MIT Licensed
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
@@ -14,6 +12,6 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var config = require('../config');
|
const config = require('../config');
|
||||||
|
|
||||||
module.exports = config.nfs;
|
module.exports = config.nfs;
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - common/redis.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var config = require('../config');
|
|
||||||
|
|
||||||
// close redis by set config.redis to `null` or `{}`
|
|
||||||
if (config.redis && config.redis.host && config.redis.port) {
|
|
||||||
|
|
||||||
var redis = require('redis');
|
|
||||||
var wrapper = require('co-redis');
|
|
||||||
var logger = require('./logger');
|
|
||||||
var _client = redis.createClient(config.redis.port, config.redis.host);
|
|
||||||
|
|
||||||
_client.on('error', function (err) {
|
|
||||||
logger.error(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = wrapper(_client);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
console.warn('[%s] [worker:%s:common/redis.js] Redis config can not found',
|
|
||||||
Date(), process.pid);
|
|
||||||
module.exports = null;
|
|
||||||
}
|
|
||||||
@@ -14,9 +14,9 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Sequelize = require('sequelize');
|
const Sequelize = require('sequelize');
|
||||||
var DataTypes = require('sequelize/lib/data-types');
|
const DataTypes = require('sequelize/lib/data-types');
|
||||||
var config = require('../config');
|
const config = require('../config');
|
||||||
|
|
||||||
if (config.mysqlServers && config.database.dialect === 'sqlite') {
|
if (config.mysqlServers && config.database.dialect === 'sqlite') {
|
||||||
// https://github.com/cnpm/cnpmjs.org/wiki/Migrating-from-1.x-to-2.x
|
// https://github.com/cnpm/cnpmjs.org/wiki/Migrating-from-1.x-to-2.x
|
||||||
@@ -34,7 +34,7 @@ if (config.mysqlServers && config.database.dialect === 'sqlite') {
|
|||||||
// mysqlQueryTimeout: 5000,
|
// mysqlQueryTimeout: 5000,
|
||||||
|
|
||||||
console.warn('[WARNNING] your config.js was too old, please @see https://github.com/cnpm/cnpmjs.org/wiki/Migrating-from-1.x-to-2.x');
|
console.warn('[WARNNING] your config.js was too old, please @see https://github.com/cnpm/cnpmjs.org/wiki/Migrating-from-1.x-to-2.x');
|
||||||
var server = config.mysqlServers[0];
|
const server = config.mysqlServers[0];
|
||||||
config.database = {
|
config.database = {
|
||||||
db: config.mysqlDatabase,
|
db: config.mysqlDatabase,
|
||||||
username: server.user,
|
username: server.user,
|
||||||
@@ -45,13 +45,13 @@ if (config.mysqlServers && config.database.dialect === 'sqlite') {
|
|||||||
pool: {
|
pool: {
|
||||||
maxConnections: config.mysqlMaxConnections || 10,
|
maxConnections: config.mysqlMaxConnections || 10,
|
||||||
minConnections: 0,
|
minConnections: 0,
|
||||||
maxIdleTime: 30000
|
maxIdleTime: 30000,
|
||||||
},
|
},
|
||||||
logging: !!process.env.SQL_DEBUG,
|
logging: !!process.env.SQL_DEBUG,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var database = config.database;
|
const database = config.database;
|
||||||
|
|
||||||
// sync database before app start, defaul is false
|
// sync database before app start, defaul is false
|
||||||
database.syncFirst = false;
|
database.syncFirst = false;
|
||||||
@@ -70,6 +70,6 @@ database.define = {
|
|||||||
collate: 'utf8_general_ci',
|
collate: 'utf8_general_ci',
|
||||||
};
|
};
|
||||||
|
|
||||||
var sequelize = new Sequelize(database.db, database.username, database.password, database);
|
const sequelize = new Sequelize(database.db, database.username, database.password, database);
|
||||||
|
|
||||||
module.exports = sequelize;
|
module.exports = sequelize;
|
||||||
|
|||||||
@@ -14,21 +14,61 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var urllib = require('urllib');
|
const urlparse = require('url').parse;
|
||||||
var HttpAgent = require('agentkeepalive');
|
const urllib = require('urllib');
|
||||||
var HttpsAgent = require('agentkeepalive').HttpsAgent;
|
const HttpAgent = require('agentkeepalive');
|
||||||
|
const HttpsAgent = require('agentkeepalive').HttpsAgent;
|
||||||
|
const config = require('../config');
|
||||||
|
|
||||||
var httpAgent = new HttpAgent({
|
let httpAgent;
|
||||||
timeout: 0,
|
let httpsAgent;
|
||||||
keepAliveTimeout: 15000
|
|
||||||
});
|
if (config.httpProxy) {
|
||||||
var httpsAgent = new HttpsAgent({
|
const tunnel = require('tunnel-agent');
|
||||||
timeout: 0,
|
const urlinfo = urlparse(config.httpProxy);
|
||||||
keepAliveTimeout: 15000
|
if (urlinfo.protocol === 'http:') {
|
||||||
});
|
httpAgent = tunnel.httpOverHttp({
|
||||||
var client = urllib.create({
|
proxy: {
|
||||||
|
host: urlinfo.hostname,
|
||||||
|
port: urlinfo.port,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
httpsAgent = tunnel.httpsOverHttp({
|
||||||
|
proxy: {
|
||||||
|
host: urlinfo.hostname,
|
||||||
|
port: urlinfo.port,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else if (urlinfo.protocol === 'https:') {
|
||||||
|
httpAgent = tunnel.httpOverHttps({
|
||||||
|
proxy: {
|
||||||
|
host: urlinfo.hostname,
|
||||||
|
port: urlinfo.port,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
httpsAgent = tunnel.httpsOverHttps({
|
||||||
|
proxy: {
|
||||||
|
host: urlinfo.hostname,
|
||||||
|
port: urlinfo.port,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw new TypeError('httpProxy format error: ' + config.httpProxy);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
httpAgent = new HttpAgent({
|
||||||
|
timeout: 0,
|
||||||
|
keepAliveTimeout: 15000,
|
||||||
|
});
|
||||||
|
httpsAgent = new HttpsAgent({
|
||||||
|
timeout: 0,
|
||||||
|
keepAliveTimeout: 15000,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = urllib.create({
|
||||||
agent: httpAgent,
|
agent: httpAgent,
|
||||||
httpsAgent: httpsAgent
|
httpsAgent,
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = client;
|
module.exports = client;
|
||||||
|
|||||||
151
config/index.js
151
config/index.js
@@ -1,32 +1,19 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - config/index.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* dead_horse <dead_horse@qq.com>
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const mkdirp = require('mkdirp');
|
||||||
* Module dependencies.
|
const copy = require('copy-to');
|
||||||
*/
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
const os = require('os');
|
||||||
|
|
||||||
var mkdirp = require('mkdirp');
|
const version = require('../package.json').version;
|
||||||
var copy = require('copy-to');
|
|
||||||
var path = require('path');
|
|
||||||
var fs = require('fs');
|
|
||||||
var os = require('os');
|
|
||||||
|
|
||||||
var version = require('../package.json').version;
|
const root = path.dirname(__dirname);
|
||||||
|
const dataDir = path.join(process.env.HOME || root, '.cnpmjs.org');
|
||||||
|
|
||||||
var root = path.dirname(__dirname);
|
const config = {
|
||||||
|
version,
|
||||||
var config = {
|
dataDir,
|
||||||
version: version,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cluster mode
|
* Cluster mode
|
||||||
@@ -37,6 +24,7 @@ var config = {
|
|||||||
/*
|
/*
|
||||||
* server configure
|
* server configure
|
||||||
*/
|
*/
|
||||||
|
|
||||||
registryPort: 7001,
|
registryPort: 7001,
|
||||||
webPort: 7002,
|
webPort: 7002,
|
||||||
bindingHost: '127.0.0.1', // only binding on 127.0.0.1 for local access
|
bindingHost: '127.0.0.1', // only binding on 127.0.0.1 for local access
|
||||||
@@ -44,15 +32,17 @@ var config = {
|
|||||||
// debug mode
|
// debug mode
|
||||||
// if in debug mode, some middleware like limit wont load
|
// if in debug mode, some middleware like limit wont load
|
||||||
// logger module will print to stdout
|
// logger module will print to stdout
|
||||||
debug: true,
|
debug: process.env.NODE_ENV === 'development',
|
||||||
|
// page mode, enable on development env
|
||||||
|
pagemock: process.env.NODE_ENV === 'development',
|
||||||
// session secret
|
// session secret
|
||||||
sessionSecret: 'cnpmjs.org test session secret',
|
sessionSecret: 'cnpmjs.org test session secret',
|
||||||
// max request json body size
|
// max request json body size
|
||||||
jsonLimit: '10mb',
|
jsonLimit: '10mb',
|
||||||
// log dir name
|
// log dir name
|
||||||
logdir: path.join(root, '.tmp/logs'),
|
logdir: path.join(dataDir, 'logs'),
|
||||||
// update file template dir
|
// update file template dir
|
||||||
uploadDir: path.join(root, '.dist'),
|
uploadDir: path.join(dataDir, 'downloads'),
|
||||||
// web page viewCache
|
// web page viewCache
|
||||||
viewCache: false,
|
viewCache: false,
|
||||||
|
|
||||||
@@ -81,28 +71,18 @@ var config = {
|
|||||||
// email notification for errors
|
// email notification for errors
|
||||||
// check https://github.com/andris9/Nodemailer for more informations
|
// check https://github.com/andris9/Nodemailer for more informations
|
||||||
mail: {
|
mail: {
|
||||||
|
enable: false,
|
||||||
appname: 'cnpmjs.org',
|
appname: 'cnpmjs.org',
|
||||||
from: 'cnpmjs.org mail sender <adderss@gmail.com>',
|
from: 'cnpmjs.org mail sender <adderss@gmail.com>',
|
||||||
service: 'gmail',
|
service: 'gmail',
|
||||||
auth: {
|
auth: {
|
||||||
user: 'address@gmail.com',
|
user: 'address@gmail.com',
|
||||||
pass: 'your password'
|
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: 'https://os.alipayobjects.com/rmsportal/oygxuIUkkrRccUz.jpg', // cnpm logo image url
|
||||||
logoURL: '//ww4.sinaimg.cn/large/69c1d4acgw1ebfly5kjlij208202oglr.jpg', // cnpm logo image url
|
adBanner: '',
|
||||||
customReadmeFile: '', // you can use your custom readme file instead the cnpm one
|
customReadmeFile: '', // you can use your custom readme file instead the cnpm one
|
||||||
customFooter: '', // you can add copyright and site total script html here
|
customFooter: '', // you can add copyright and site total script html here
|
||||||
npmClientName: 'cnpm', // use `${name} install package`
|
npmClientName: 'cnpm', // use `${name} install package`
|
||||||
@@ -137,24 +117,22 @@ var config = {
|
|||||||
pool: {
|
pool: {
|
||||||
maxConnections: 10,
|
maxConnections: 10,
|
||||||
minConnections: 0,
|
minConnections: 0,
|
||||||
maxIdleTime: 30000
|
maxIdleTime: 30000,
|
||||||
},
|
},
|
||||||
|
|
||||||
// the storage engine for 'sqlite'
|
// the storage engine for 'sqlite'
|
||||||
// default store into ~/cnpmjs.org.sqlite
|
// default store into ~/.cnpmjs.org/data.sqlite
|
||||||
storage: path.join(process.env.HOME || root, 'cnpmjs.org.sqlite'),
|
storage: path.join(dataDir, 'data.sqlite'),
|
||||||
|
|
||||||
logging: !!process.env.SQL_DEBUG,
|
logging: !!process.env.SQL_DEBUG,
|
||||||
},
|
},
|
||||||
|
|
||||||
// redis config
|
|
||||||
// use for koa-limit module as storage
|
|
||||||
redis: null,
|
|
||||||
|
|
||||||
// package tarball store in local filesystem by default
|
// package tarball store in local filesystem by default
|
||||||
nfs: require('fs-cnpm')({
|
nfs: require('fs-cnpm')({
|
||||||
dir: path.join(root, '.tmp', 'dist')
|
dir: path.join(dataDir, 'nfs'),
|
||||||
}),
|
}),
|
||||||
|
// if set true, will 302 redirect to `nfs.url(dist.key)`
|
||||||
|
downloadRedirectToNFS: false,
|
||||||
|
|
||||||
// registry url name
|
// registry url name
|
||||||
registryHost: 'r.cnpmjs.org',
|
registryHost: 'r.cnpmjs.org',
|
||||||
@@ -163,18 +141,13 @@ var config = {
|
|||||||
* registry mode config
|
* registry mode config
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// enable private mode, only admin can publish, other use just can sync package from source npm
|
// enable private mode or not
|
||||||
enablePrivate: true,
|
// private mode: only admins can publish, other users just can sync package from source npm
|
||||||
|
// public mode: all users can publish
|
||||||
|
enablePrivate: false,
|
||||||
|
|
||||||
// registry scopes, if don't set, means do not support scopes
|
// registry scopes, if don't set, means do not support scopes
|
||||||
scopes: [
|
scopes: [ '@cnpm', '@cnpmtest', '@cnpm-test' ],
|
||||||
'@cnpm',
|
|
||||||
'@cnpmtest'
|
|
||||||
],
|
|
||||||
|
|
||||||
// force user publish with scope
|
|
||||||
// but admins still can publish without scope
|
|
||||||
forcePublishWithScope: true,
|
|
||||||
|
|
||||||
// some registry already have some private packages in global scope
|
// some registry already have some private packages in global scope
|
||||||
// but we want to treat them as scoped private packages,
|
// but we want to treat them as scoped private packages,
|
||||||
@@ -185,25 +158,17 @@ var config = {
|
|||||||
* sync configs
|
* sync configs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// sync dist config
|
|
||||||
// sync node.js dist from nodejs.org
|
|
||||||
noticeSyncDistError: true,
|
|
||||||
disturl: 'http://nodejs.org/dist',
|
|
||||||
syncDist: false,
|
|
||||||
|
|
||||||
pythonDisturl: 'https://www.python.org/ftp',
|
|
||||||
syncPythonDist: false,
|
|
||||||
|
|
||||||
// the official npm registry
|
// the official npm registry
|
||||||
// cnpm wont directly sync from this one
|
// cnpm wont directly sync from this one
|
||||||
// but sometimes will request it for some package infomations
|
// but sometimes will request it for some package infomations
|
||||||
// please don't change it if not necessary
|
// please don't change it if not necessary
|
||||||
officialNpmRegistry: 'https://registry.npmjs.org',
|
officialNpmRegistry: 'https://registry.npmjs.com',
|
||||||
|
officialNpmReplicate: 'https://replicate.npmjs.com',
|
||||||
|
|
||||||
// sync source, upstream registry
|
// sync source, upstream registry
|
||||||
// If you want to directly sync from official npm's registry
|
// If you want to directly sync from official npm's registry
|
||||||
// please drop them an email first
|
// please drop them an email first
|
||||||
sourceNpmRegistry: 'http://registry.npm.taobao.org',
|
sourceNpmRegistry: 'https://registry.npm.taobao.org',
|
||||||
|
|
||||||
// upstream registry is base on cnpm/cnpmjs.org or not
|
// upstream registry is base on cnpm/cnpmjs.org or not
|
||||||
// if your upstream is official npm registry, please turn it off
|
// if your upstream is official npm registry, please turn it off
|
||||||
@@ -213,7 +178,7 @@ var config = {
|
|||||||
syncByInstall: true,
|
syncByInstall: true,
|
||||||
|
|
||||||
// sync mode select
|
// sync mode select
|
||||||
// none: do not sync any module
|
// none: do not sync any module, proxy all public modules from sourceNpmRegistry
|
||||||
// exist: only sync exist modules
|
// exist: only sync exist modules
|
||||||
// all: sync all modules
|
// all: sync all modules
|
||||||
syncModel: 'none', // 'none', 'all', 'exist'
|
syncModel: 'none', // 'none', 'all', 'exist'
|
||||||
@@ -233,14 +198,46 @@ var config = {
|
|||||||
// sync devDependencies or not, default is false
|
// sync devDependencies or not, default is false
|
||||||
syncDevDependencies: false,
|
syncDevDependencies: false,
|
||||||
|
|
||||||
|
// changes streaming sync
|
||||||
|
syncChangesStream: false,
|
||||||
|
handleSyncRegistry: 'http://127.0.0.1:7001',
|
||||||
|
|
||||||
// badge subject on http://shields.io/
|
// badge subject on http://shields.io/
|
||||||
|
badgePrefixURL: 'https://img.shields.io/badge',
|
||||||
badgeSubject: 'cnpm',
|
badgeSubject: 'cnpm',
|
||||||
|
|
||||||
|
// custom user service, @see https://github.com/cnpm/cnpmjs.org/wiki/Use-Your-Own-User-Authorization
|
||||||
|
// when you not intend to ingegrate with your company's user system, then use null, it would
|
||||||
|
// use the default cnpm user system
|
||||||
|
userService: null,
|
||||||
|
|
||||||
|
// always-auth https://docs.npmjs.com/misc/config#always-auth
|
||||||
|
// Force npm to always require authentication when accessing the registry, even for GET requests.
|
||||||
|
alwaysAuth: false,
|
||||||
|
|
||||||
|
// if you're behind firewall, need to request through http proxy, please set this
|
||||||
|
// e.g.: `httpProxy: 'http://proxy.mycompany.com:8080'`
|
||||||
|
httpProxy: null,
|
||||||
|
|
||||||
|
// snyk.io root url
|
||||||
|
snykUrl: 'https://snyk.io',
|
||||||
};
|
};
|
||||||
|
|
||||||
// load config/config.js, everything in config.js will cover the same key in index.js
|
if (process.env.NODE_ENV !== 'test') {
|
||||||
var customConfig = path.join(root, 'config/config.js');
|
let customConfig;
|
||||||
if (fs.existsSync(customConfig)) {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
copy(require(customConfig)).override(config);
|
customConfig = path.join(root, 'config', 'config.js');
|
||||||
|
} else {
|
||||||
|
// 1. try to load `$dataDir/config.json` first, not exists then goto 2.
|
||||||
|
// 2. load config/config.js, everything in config.js will cover the same key in index.js
|
||||||
|
customConfig = path.join(dataDir, 'config.json');
|
||||||
|
if (!fs.existsSync(customConfig)) {
|
||||||
|
customConfig = path.join(root, 'config', 'config.js');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fs.existsSync(customConfig)) {
|
||||||
|
copy(require(customConfig)).override(config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mkdirp.sync(config.logdir);
|
mkdirp.sync(config.logdir);
|
||||||
@@ -248,7 +245,7 @@ mkdirp.sync(config.uploadDir);
|
|||||||
|
|
||||||
module.exports = config;
|
module.exports = config;
|
||||||
|
|
||||||
config.loadConfig = function (customConfig) {
|
config.loadConfig = function(customConfig) {
|
||||||
if (!customConfig) {
|
if (!customConfig) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var packageService = require('../../../services/package');
|
const packageService = require('../../../services/package');
|
||||||
|
|
||||||
module.exports = deprecateVersions;
|
module.exports = deprecateVersions;
|
||||||
|
|
||||||
@@ -22,28 +22,28 @@ module.exports = deprecateVersions;
|
|||||||
* @see https://github.com/cnpm/cnpmjs.org/issues/415
|
* @see https://github.com/cnpm/cnpmjs.org/issues/415
|
||||||
*/
|
*/
|
||||||
function* deprecateVersions() {
|
function* deprecateVersions() {
|
||||||
var body = this.request.body;
|
const body = this.request.body;
|
||||||
var name = this.params.name || this.params[0];
|
const name = this.params.name || this.params[0];
|
||||||
|
|
||||||
var tasks = [];
|
const tasks = [];
|
||||||
for (var version in body.versions) {
|
for (const version in body.versions) {
|
||||||
tasks.push(packageService.getModule(name, version));
|
tasks.push(packageService.getModule(name, version));
|
||||||
}
|
}
|
||||||
var rs = yield tasks;
|
const rs = yield tasks;
|
||||||
|
|
||||||
var updateTasks = [];
|
const updateTasks = [];
|
||||||
for (var i = 0; i < rs.length; i++) {
|
for (let i = 0; i < rs.length; i++) {
|
||||||
var row = rs[i];
|
const row = rs[i];
|
||||||
if (!row) {
|
if (!row) {
|
||||||
// some version not exists
|
// some version not exists
|
||||||
this.status = 400;
|
this.status = 400;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'version_error',
|
error: 'version_error',
|
||||||
reason: 'Some versions: ' + JSON.stringify(Object.keys(body.versions)) + ' not found'
|
reason: 'Some versions: ' + JSON.stringify(Object.keys(body.versions)) + ' not found',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var data = body.versions[row.package.version];
|
const data = body.versions[row.package.version];
|
||||||
if (typeof data.deprecated === 'string') {
|
if (typeof data.deprecated === 'string') {
|
||||||
row.package.deprecated = data.deprecated;
|
row.package.deprecated = data.deprecated;
|
||||||
updateTasks.push(packageService.updateModulePackage(row.id, row.package));
|
updateTasks.push(packageService.updateModulePackage(row.id, row.package));
|
||||||
@@ -51,10 +51,10 @@ function* deprecateVersions() {
|
|||||||
}
|
}
|
||||||
yield updateTasks;
|
yield updateTasks;
|
||||||
// update last modified
|
// update last modified
|
||||||
yield* packageService.updateModuleLastModified(name);
|
yield packageService.updateModuleLastModified(name);
|
||||||
|
|
||||||
this.status = 201;
|
this.status = 201;
|
||||||
this.body = {
|
this.body = {
|
||||||
ok: true
|
ok: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
78
controllers/registry/package/dist_tag.js
Normal file
78
controllers/registry/package/dist_tag.js
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const packageService = require('../../../services/package');
|
||||||
|
|
||||||
|
function ok() {
|
||||||
|
return {
|
||||||
|
ok: 'dist-tags updated',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /-/package/:pkg/dist-tags -- returns the package's dist-tags
|
||||||
|
exports.index = function* () {
|
||||||
|
const name = this.params.name || this.params[0];
|
||||||
|
const rows = yield packageService.listModuleTags(name);
|
||||||
|
const tags = {};
|
||||||
|
for (let i = 0; i < rows.length; i++) {
|
||||||
|
const row = rows[i];
|
||||||
|
tags[row.tag] = row.version;
|
||||||
|
}
|
||||||
|
this.body = tags;
|
||||||
|
};
|
||||||
|
|
||||||
|
// PUT /-/package/:pkg/dist-tags -- Set package's dist-tags to provided object body (removing missing)
|
||||||
|
exports.save = function* () {
|
||||||
|
const name = this.params.name || this.params[0];
|
||||||
|
yield packageService.removeModuleTags(name);
|
||||||
|
yield exports.update.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
// POST /-/package/:pkg/dist-tags -- Add/modify dist-tags from provided object body (merge)
|
||||||
|
exports.update = function* () {
|
||||||
|
const name = this.params.name || this.params[0];
|
||||||
|
const tags = this.request.body;
|
||||||
|
for (const tag in tags) {
|
||||||
|
const version = tags[tag];
|
||||||
|
yield packageService.addModuleTag(name, tag, version);
|
||||||
|
}
|
||||||
|
this.status = 201;
|
||||||
|
this.body = ok();
|
||||||
|
};
|
||||||
|
|
||||||
|
// PUT /-/package/:pkg/dist-tags/:tag -- Set package's dist-tags[tag] to provided string body
|
||||||
|
// POST /-/package/:pkg/dist-tags/:tag -- Same as PUT /-/package/:pkg/dist-tags/:tag
|
||||||
|
exports.set = function* () {
|
||||||
|
const name = this.params.name || this.params[0];
|
||||||
|
const tag = this.params.tag || this.params[1];
|
||||||
|
const version = this.request.body;
|
||||||
|
// make sure version exists
|
||||||
|
const pkg = yield packageService.getModule(name, version);
|
||||||
|
if (!pkg) {
|
||||||
|
this.status = 400;
|
||||||
|
this.body = {
|
||||||
|
error: 'version_error',
|
||||||
|
reason: name + '@' + version + ' not exists',
|
||||||
|
};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
yield packageService.addModuleTag(name, tag, version);
|
||||||
|
this.status = 201;
|
||||||
|
this.body = ok();
|
||||||
|
};
|
||||||
|
|
||||||
|
// DELETE /-/package/:pkg/dist-tags/:tag -- Remove tag from dist-tags
|
||||||
|
exports.destroy = function* () {
|
||||||
|
const name = this.params.name || this.params[0];
|
||||||
|
const tag = this.params.tag || this.params[1];
|
||||||
|
if (tag === 'latest') {
|
||||||
|
this.status = 400;
|
||||||
|
this.body = {
|
||||||
|
error: 'dist_tag_error',
|
||||||
|
reason: 'Can\'t not delete latest tag',
|
||||||
|
};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
yield packageService.removeModuleTagsByNames(name, tag);
|
||||||
|
this.body = ok();
|
||||||
|
};
|
||||||
@@ -1,49 +1,41 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - controllers/registry/package/download.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const debug = require('debug')('cnpmjs.org:controllers:registry:download');
|
||||||
* Module dependencies.
|
const mime = require('mime');
|
||||||
*/
|
const utility = require('utility');
|
||||||
|
const defer = require('co-defer');
|
||||||
|
const is = require('is-type-of');
|
||||||
|
const nfs = require('../../../common/nfs');
|
||||||
|
const logger = require('../../../common/logger');
|
||||||
|
const common = require('../../../lib/common');
|
||||||
|
const downloadAsReadStream = require('../../utils').downloadAsReadStream;
|
||||||
|
const packageService = require('../../../services/package');
|
||||||
|
const downloadTotalService = require('../../../services/download_total');
|
||||||
|
const config = require('../../../config');
|
||||||
|
|
||||||
var debug = require('debug')('cnpmjs.org:controllers:registry:download');
|
let _downloads = {};
|
||||||
var mime = require('mime');
|
|
||||||
var utility = require('utility');
|
|
||||||
var defer = require('co-defer');
|
|
||||||
var nfs = require('../../../common/nfs');
|
|
||||||
var logger = require('../../../common/logger');
|
|
||||||
var common = require('../../../lib/common');
|
|
||||||
var downloadAsReadStream = require('../../utils').downloadAsReadStream;
|
|
||||||
var packageService = require('../../../services/package');
|
|
||||||
var downloadTotalService = require('../../../services/download_total');
|
|
||||||
|
|
||||||
var _downloads = {};
|
|
||||||
|
|
||||||
module.exports = function* download(next) {
|
module.exports = function* download(next) {
|
||||||
var name = this.params.name || this.params[0];
|
const name = this.params.name || this.params[0];
|
||||||
var filename = this.params.filename || this.params[1];
|
const filename = this.params.filename || this.params[1];
|
||||||
var version = filename.slice(name.length + 1, -4);
|
const version = filename.slice(name.length + 1, -4);
|
||||||
var row = yield* packageService.getModule(name, version);
|
const row = yield packageService.getModule(name, version);
|
||||||
// can not get dist
|
// can not get dist
|
||||||
var url = null;
|
let url = null;
|
||||||
|
|
||||||
if (typeof nfs.url === 'function') {
|
if (typeof nfs.url === 'function') {
|
||||||
url = nfs.url(common.getCDNKey(name, filename));
|
if (is.generatorFunction(nfs.url)) {
|
||||||
|
url = yield nfs.url(common.getCDNKey(name, filename));
|
||||||
|
} else {
|
||||||
|
url = nfs.url(common.getCDNKey(name, filename));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug('download %s %s %s %s', name, filename, version, url);
|
debug('download %s %s %s %s', name, filename, version, url);
|
||||||
|
|
||||||
if (!row || !row.package || !row.package.dist) {
|
if (!row || !row.package || !row.package.dist) {
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
this.status = 302;
|
this.status = 302;
|
||||||
this.set('Location', url);
|
this.set('Location', url);
|
||||||
@@ -51,22 +43,25 @@ module.exports = function* download(next) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var dist = row.package.dist;
|
_downloads[name] = (_downloads[name] || 0) + 1;
|
||||||
if (!dist.key) {
|
|
||||||
debug('get tarball by 302, url: %s', dist.tarball || url);
|
if (config.downloadRedirectToNFS && url) {
|
||||||
this.status = 302;
|
this.status = 302;
|
||||||
this.set('Location', dist.tarball || url);
|
this.set('Location', url);
|
||||||
_downloads[name] = (_downloads[name] || 0) + 1;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dist = row.package.dist;
|
||||||
|
if (!dist.key) {
|
||||||
|
// try to use nsf.url() first
|
||||||
|
url = url || dist.tarball;
|
||||||
|
debug('get tarball by 302, url: %s', url);
|
||||||
|
this.status = 302;
|
||||||
|
this.set('Location', url);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// else use `dist.key` to get tarball from nfs
|
// else use `dist.key` to get tarball from nfs
|
||||||
if (!nfs.download) {
|
|
||||||
return yield* next;
|
|
||||||
}
|
|
||||||
|
|
||||||
_downloads[name] = (_downloads[name] || 0) + 1;
|
|
||||||
|
|
||||||
if (typeof dist.size === 'number' && dist.size > 0) {
|
if (typeof dist.size === 'number' && dist.size > 0) {
|
||||||
this.length = dist.size;
|
this.length = dist.size;
|
||||||
}
|
}
|
||||||
@@ -74,15 +69,15 @@ module.exports = function* download(next) {
|
|||||||
this.attachment(filename);
|
this.attachment(filename);
|
||||||
this.etag = dist.shasum;
|
this.etag = dist.shasum;
|
||||||
|
|
||||||
this.body = yield* downloadAsReadStream(dist.key);
|
this.body = yield downloadAsReadStream(dist.key);
|
||||||
};
|
};
|
||||||
|
|
||||||
defer.setInterval(function* () {
|
defer.setInterval(function* () {
|
||||||
// save download count
|
// save download count
|
||||||
var totals = [];
|
const totals = [];
|
||||||
for (var name in _downloads) {
|
for (const name in _downloads) {
|
||||||
var count = _downloads[name];
|
const count = _downloads[name];
|
||||||
totals.push([name, count]);
|
totals.push([ name, count ]);
|
||||||
}
|
}
|
||||||
_downloads = {};
|
_downloads = {};
|
||||||
|
|
||||||
@@ -92,18 +87,20 @@ defer.setInterval(function* () {
|
|||||||
|
|
||||||
debug('save download total: %j', totals);
|
debug('save download total: %j', totals);
|
||||||
|
|
||||||
var date = utility.YYYYMMDD();
|
const date = utility.YYYYMMDD();
|
||||||
for (var i = 0; i < totals.length; i++) {
|
for (let i = 0; i < totals.length; i++) {
|
||||||
var item = totals[i];
|
const item = totals[i];
|
||||||
var name = item[0];
|
const name = item[0];
|
||||||
var count = item[1];
|
const count = item[1];
|
||||||
try {
|
try {
|
||||||
yield* downloadTotalService.plusModuleTotal({ name: name, date: date, count: count });
|
yield downloadTotalService.plusModuleTotal({ name, date, count });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
err.message += '; name: ' + name + ', count: ' + count + ', date: ' + date;
|
if (err.name !== 'SequelizeUniqueConstraintError') {
|
||||||
logger.error(err);
|
err.message += '; name: ' + name + ', count: ' + count + ', date: ' + date;
|
||||||
|
logger.error(err);
|
||||||
|
}
|
||||||
// save back to _downloads, try again next time
|
// save back to _downloads, try again next time
|
||||||
_downloads[name] = (_downloads[name] || 0) + count;
|
_downloads[name] = (_downloads[name] || 0) + count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 5000);
|
}, 5000 + Math.ceil(Math.random() * 1000));
|
||||||
|
|||||||
66
controllers/registry/package/download_total.js
Normal file
66
controllers/registry/package/download_total.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const DownloadTotal = require('../../../services/download_total');
|
||||||
|
const DATE_REG = /^\d{4}-\d{2}-\d{2}$/;
|
||||||
|
|
||||||
|
module.exports = function* downloadTotal() {
|
||||||
|
let range = this.params.range || this.params[0] || '';
|
||||||
|
const name = this.params.name || this.params[1];
|
||||||
|
|
||||||
|
range = range.split(':');
|
||||||
|
if (range.length !== 2
|
||||||
|
|| !range[0].match(DATE_REG)
|
||||||
|
|| !range[1].match(DATE_REG)) {
|
||||||
|
this.status = 400;
|
||||||
|
this.body = {
|
||||||
|
error: 'range_error',
|
||||||
|
reason: 'range must be YYYY-MM-DD:YYYY-MM-DD style',
|
||||||
|
};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.body = name
|
||||||
|
? yield getPackageTotal(name, range[0], range[1])
|
||||||
|
: yield getTotal(range[0], range[1]);
|
||||||
|
};
|
||||||
|
|
||||||
|
function* getPackageTotal(name, start, end) {
|
||||||
|
const res = yield DownloadTotal.getModuleTotal(name, start, end);
|
||||||
|
const downloads = res.map(function(row) {
|
||||||
|
return {
|
||||||
|
day: row.date,
|
||||||
|
downloads: row.count,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
downloads.sort(function(a, b) {
|
||||||
|
return a.day > b.day ? 1 : -1;
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
downloads,
|
||||||
|
package: name,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function* getTotal(start, end) {
|
||||||
|
const res = yield DownloadTotal.getTotal(start, end);
|
||||||
|
const downloads = res.map(function(row) {
|
||||||
|
return {
|
||||||
|
day: row.date,
|
||||||
|
downloads: row.count,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
downloads.sort(function(a, b) {
|
||||||
|
return a.day > b.day ? 1 : -1;
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
downloads,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,54 +1,36 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - controllers/registry/package/list.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const debug = require('debug')('cnpmjs.org:controllers:registry:package:list');
|
||||||
* Module dependencies.
|
const packageService = require('../../../services/package');
|
||||||
*/
|
const common = require('../../../lib/common');
|
||||||
|
const SyncModuleWorker = require('../../sync_module_worker');
|
||||||
var debug = require('debug')('cnpmjs.org:controllers:registry:package:list');
|
const config = require('../../../config');
|
||||||
var packageService = require('../../../services/package');
|
|
||||||
var npmService = require('../../../services/npm');
|
|
||||||
var config = require('../../../config');
|
|
||||||
var setDownloadURL = require('../../../lib/common').setDownloadURL;
|
|
||||||
var SyncModuleWorker = require('../../sync_module_worker');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list all version of a module
|
* list all version of a module
|
||||||
* GET /:name
|
* GET /:name
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function* list() {
|
module.exports = function* list() {
|
||||||
var orginalName = this.params.name || this.params[0];
|
const orginalName = this.params.name || this.params[0];
|
||||||
var name = orginalName;
|
const name = orginalName;
|
||||||
var rs = yield [
|
const rs = yield [
|
||||||
packageService.getModuleLastModified(name),
|
packageService.getModuleLastModified(name),
|
||||||
packageService.listModuleTags(name)
|
packageService.listModuleTags(name),
|
||||||
];
|
];
|
||||||
var modifiedTime = rs[0];
|
let modifiedTime = rs[0];
|
||||||
var tags = rs[1];
|
const tags = rs[1];
|
||||||
|
|
||||||
debug('show %s(%s), last modified: %s, tags: %j', name, orginalName, modifiedTime, tags);
|
debug('show %s(%s), last modified: %s, tags: %j', name, orginalName, modifiedTime, tags);
|
||||||
if (modifiedTime) {
|
if (modifiedTime) {
|
||||||
// find out the latest modfied time
|
// find out the latest modfied time
|
||||||
// because update tags only modfied tag, wont change module gmt_modified
|
// because update tags only modfied tag, wont change module gmt_modified
|
||||||
for (var i = 0; i < tags.length; i++) {
|
for (const tag of tags) {
|
||||||
var tag = tags[i];
|
|
||||||
if (tag.gmt_modified > modifiedTime) {
|
if (tag.gmt_modified > modifiedTime) {
|
||||||
modifiedTime = tag.gmt_modified;
|
modifiedTime = tag.gmt_modified;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use modifiedTime as etag
|
|
||||||
this.set('ETag', '"' + modifiedTime.getTime() + '"');
|
|
||||||
|
|
||||||
// must set status first
|
// must set status first
|
||||||
this.status = 200;
|
this.status = 200;
|
||||||
if (this.fresh) {
|
if (this.fresh) {
|
||||||
@@ -58,27 +40,29 @@ module.exports = function* list() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var r = yield [
|
const r = yield [
|
||||||
packageService.listModulesByName(name),
|
packageService.listModulesByName(name),
|
||||||
packageService.listStarUserNames(name),
|
packageService.listStarUserNames(name),
|
||||||
packageService.listMaintainers(name),
|
packageService.listMaintainers(name),
|
||||||
];
|
];
|
||||||
var rows = r[0];
|
const rows = r[0];
|
||||||
var starUsers = r[1];
|
let starUsers = r[1];
|
||||||
var maintainers = r[2];
|
const maintainers = r[2];
|
||||||
|
|
||||||
debug('show %s got %d rows, %d tags, %d star users, maintainers: %j',
|
debug('show %s got %d rows, %d tags, %d star users, maintainers: %j',
|
||||||
name, rows.length, tags.length, starUsers.length, maintainers);
|
name, rows.length, tags.length, starUsers.length, maintainers);
|
||||||
|
|
||||||
var starUserMap = {};
|
const starUserMap = {};
|
||||||
for (var i = 0; i < starUsers.length; i++) {
|
for (const starUser of starUsers) {
|
||||||
starUserMap[starUsers[i]] = true;
|
if (starUser[0] !== '"' && starUser[0] !== "'") {
|
||||||
|
starUserMap[starUser] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
starUsers = starUserMap;
|
starUsers = starUserMap;
|
||||||
|
|
||||||
if (rows.length === 0) {
|
if (rows.length === 0) {
|
||||||
// check if unpublished
|
// check if unpublished
|
||||||
var unpublishedInfo = yield* packageService.getUnpublishedModule(name);
|
const unpublishedInfo = yield packageService.getUnpublishedModule(name);
|
||||||
debug('show unpublished %j', unpublishedInfo);
|
debug('show unpublished %j', unpublishedInfo);
|
||||||
if (unpublishedInfo) {
|
if (unpublishedInfo) {
|
||||||
this.status = 404;
|
this.status = 404;
|
||||||
@@ -89,7 +73,7 @@ module.exports = function* list() {
|
|||||||
modified: unpublishedInfo.package.time,
|
modified: unpublishedInfo.package.time,
|
||||||
unpublished: unpublishedInfo.package,
|
unpublished: unpublishedInfo.package,
|
||||||
},
|
},
|
||||||
_attachments: {}
|
_attachments: {},
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -102,56 +86,44 @@ module.exports = function* list() {
|
|||||||
this.status = 404;
|
this.status = 404;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'not_found',
|
error: 'not_found',
|
||||||
reason: 'document not found'
|
reason: 'document not found',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// start sync
|
// start sync
|
||||||
var logId = yield* SyncModuleWorker.sync(name, 'sync-by-install');
|
const logId = yield SyncModuleWorker.sync(name, 'sync-by-install');
|
||||||
debug('start sync %s, get log id %s', name, logId);
|
debug('start sync %s, get log id %s', name, logId);
|
||||||
|
|
||||||
// try to get package from official registry
|
return this.redirect(config.officialNpmRegistry + this.url);
|
||||||
var r = yield* npmService.request('/' + name, {
|
|
||||||
registry: config.officialNpmRegistry
|
|
||||||
});
|
|
||||||
|
|
||||||
debug('requet from officialNpmRegistry response %s', r.status);
|
|
||||||
if (r.status !== 200) {
|
|
||||||
this.status = 404;
|
|
||||||
this.body = {
|
|
||||||
error: 'not_found',
|
|
||||||
reason: 'document not found'
|
|
||||||
};
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.body = r.data;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var latestMod = null;
|
let latestMod = null;
|
||||||
var readme = null;
|
let readme = null;
|
||||||
// set tags
|
// set tags
|
||||||
var distTags = {};
|
const distTags = {};
|
||||||
for (var i = 0; i < tags.length; i++) {
|
for (const t of tags) {
|
||||||
var t = tags[i];
|
|
||||||
distTags[t.tag] = t.version;
|
distTags[t.tag] = t.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set versions and times
|
// set versions and times
|
||||||
var versions = {};
|
const versions = {};
|
||||||
var times = {};
|
let times = {};
|
||||||
var attachments = {};
|
const attachments = {};
|
||||||
var createdTime = null;
|
let createdTime = null;
|
||||||
for (var i = 0; i < rows.length; i++) {
|
for (const row of rows) {
|
||||||
var row = rows[i];
|
const pkg = row.package;
|
||||||
var pkg = row.package;
|
// pkg is string ... ignore it
|
||||||
setDownloadURL(pkg, this);
|
if (typeof pkg === 'string') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
common.setDownloadURL(pkg, this);
|
||||||
pkg._cnpm_publish_time = row.publish_time;
|
pkg._cnpm_publish_time = row.publish_time;
|
||||||
|
pkg.publish_time = pkg.publish_time || row.publish_time;
|
||||||
|
|
||||||
versions[pkg.version] = pkg;
|
versions[pkg.version] = pkg;
|
||||||
|
|
||||||
var t = times[pkg.version] = row.publish_time ? new Date(row.publish_time) : row.gmt_modified;
|
const t = times[pkg.version] = row.publish_time ? new Date(row.publish_time) : row.gmt_modified;
|
||||||
if ((!distTags.latest && !latestMod) || distTags.latest === pkg.version) {
|
if ((!distTags.latest && !latestMod) || distTags.latest === pkg.version) {
|
||||||
latestMod = row;
|
latestMod = row;
|
||||||
readme = pkg.readme;
|
readme = pkg.readme;
|
||||||
@@ -168,11 +140,11 @@ module.exports = function* list() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (modifiedTime && createdTime) {
|
if (modifiedTime && createdTime) {
|
||||||
var ts = {
|
const ts = {
|
||||||
modified: modifiedTime,
|
modified: modifiedTime,
|
||||||
created: createdTime,
|
created: createdTime,
|
||||||
};
|
};
|
||||||
for (var t in times) {
|
for (const t in times) {
|
||||||
ts[t] = times[t];
|
ts[t] = times[t];
|
||||||
}
|
}
|
||||||
times = ts;
|
times = ts;
|
||||||
@@ -182,8 +154,8 @@ module.exports = function* list() {
|
|||||||
latestMod = rows[0];
|
latestMod = rows[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
var rev = String(latestMod.id);
|
const rev = String(latestMod.id);
|
||||||
var pkg = latestMod.package;
|
const pkg = latestMod.package;
|
||||||
|
|
||||||
if (tags.length === 0) {
|
if (tags.length === 0) {
|
||||||
// some sync error reason, will cause tags missing
|
// some sync error reason, will cause tags missing
|
||||||
@@ -191,19 +163,19 @@ module.exports = function* list() {
|
|||||||
distTags.latest = pkg.version;
|
distTags.latest = pkg.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
var info = {
|
const info = {
|
||||||
_id: orginalName,
|
_id: orginalName,
|
||||||
_rev: rev,
|
_rev: rev,
|
||||||
name: orginalName,
|
name: orginalName,
|
||||||
description: pkg.description,
|
description: pkg.description,
|
||||||
"dist-tags": distTags,
|
'dist-tags': distTags,
|
||||||
maintainers: pkg.maintainers,
|
maintainers: pkg.maintainers,
|
||||||
time: times,
|
time: times,
|
||||||
users: starUsers,
|
users: starUsers,
|
||||||
author: pkg.author,
|
author: pkg.author,
|
||||||
repository: pkg.repository,
|
repository: pkg.repository,
|
||||||
versions: versions,
|
versions,
|
||||||
readme: readme,
|
readme,
|
||||||
_attachments: attachments,
|
_attachments: attachments,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -213,5 +185,5 @@ module.exports = function* list() {
|
|||||||
info.license = pkg.license;
|
info.license = pkg.license;
|
||||||
|
|
||||||
debug('show module %s: %s, latest: %s', orginalName, rev, latestMod.version);
|
debug('show module %s: %s, latest: %s', orginalName, rev, latestMod.version);
|
||||||
this.body = info;
|
this.jsonp = info;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,29 +1,15 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - controllers/registry/package/list_all.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const packageService = require('../../../services/package');
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var packageService = require('../../../services/package');
|
|
||||||
|
|
||||||
// GET /-/all
|
// GET /-/all
|
||||||
// List all packages names
|
// List all packages names
|
||||||
// https://github.com/npm/npm-registry-client/blob/master/lib/get.js#L86
|
// https://github.com/npm/npm-registry-client/blob/master/lib/get.js#L86
|
||||||
module.exports = function* () {
|
module.exports = function* () {
|
||||||
var updated = Date.now();
|
const updated = Date.now();
|
||||||
var names = yield* packageService.listAllPublicModuleNames();
|
const names = yield packageService.listAllPublicModuleNames();
|
||||||
var result = { _updated: updated };
|
const result = { _updated: updated };
|
||||||
names.forEach(function (name) {
|
names.forEach(function(name) {
|
||||||
result[name] = true;
|
result[name] = true;
|
||||||
});
|
});
|
||||||
this.body = result;
|
this.body = result;
|
||||||
|
|||||||
29
controllers/registry/package/list_by_user.js
Normal file
29
controllers/registry/package/list_by_user.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/**!
|
||||||
|
* list packages by username
|
||||||
|
*
|
||||||
|
* Copyright(c) cnpmjs.org and other contributors.
|
||||||
|
* MIT Licensed
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module dependencies.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const packageService = require('../../../services/package');
|
||||||
|
|
||||||
|
module.exports = function* () {
|
||||||
|
const username = this.params.user;
|
||||||
|
const packages = yield packageService.listModulesByUser(username);
|
||||||
|
|
||||||
|
this.body = {
|
||||||
|
user: {
|
||||||
|
name: username,
|
||||||
|
},
|
||||||
|
packages,
|
||||||
|
};
|
||||||
|
};
|
||||||
26
controllers/registry/package/list_dependents.js
Normal file
26
controllers/registry/package/list_dependents.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/**!
|
||||||
|
* list package's dependents
|
||||||
|
*
|
||||||
|
* Copyright(c) cnpmjs.org and other contributors.
|
||||||
|
* MIT Licensed
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module dependencies.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const packageService = require('../../../services/package');
|
||||||
|
|
||||||
|
module.exports = function* () {
|
||||||
|
const name = this.params.name || this.params[0];
|
||||||
|
const dependents = yield packageService.listDependents(name);
|
||||||
|
|
||||||
|
this.body = {
|
||||||
|
dependents,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
/**!
|
/**!
|
||||||
* cnpmjs.org - controllers/registry/package/list_shorts.js
|
* Copyright(c) cnpm and other contributors.
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
* MIT Licensed
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
@@ -14,10 +12,10 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var packageService = require('../../../services/package');
|
const packageService = require('../../../services/package');
|
||||||
|
|
||||||
// GET /-/short
|
// GET /-/short
|
||||||
// List all packages names only
|
// List all packages names only
|
||||||
module.exports = function* () {
|
module.exports = function* () {
|
||||||
this.body = yield* packageService.listAllPublicModuleNames();
|
this.body = yield packageService.listAllPublicModuleNames();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,57 +1,43 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - controllers/registry/package/list_since.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const packageService = require('../../../services/package');
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var packageService = require('../../../services/package');
|
const A_WEEK_MS = 3600000 * 24 * 7;
|
||||||
|
|
||||||
var A_WEEK_MS = 3600000 * 24 * 7;
|
|
||||||
|
|
||||||
// GET /-/all/since?stale=update_after&startkey={key}
|
// GET /-/all/since?stale=update_after&startkey={key}
|
||||||
// List packages names since startkey
|
// List packages names since startkey
|
||||||
// https://github.com/npm/npm-registry-client/blob/master/lib/get.js#L89
|
// https://github.com/npm/npm-registry-client/blob/master/lib/get.js#L89
|
||||||
module.exports = function* () {
|
module.exports = function* listSince() {
|
||||||
var query = this.query;
|
const query = this.query;
|
||||||
if (query.stale !== 'update_after') {
|
if (query.stale !== 'update_after') {
|
||||||
this.status = 400;
|
this.status = 400;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'query_parse_error',
|
error: 'query_parse_error',
|
||||||
reason: 'Invalid value for `stale`.'
|
reason: 'Invalid value for `stale`.',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var startkey = Number(query.startkey);
|
let startkey = Number(query.startkey);
|
||||||
if (!startkey) {
|
if (!startkey) {
|
||||||
this.status = 400;
|
this.status = 400;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'query_parse_error',
|
error: 'query_parse_error',
|
||||||
reason: 'Invalid value for `startkey`.'
|
reason: 'Invalid value for `startkey`.',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var updated = Date.now();
|
const updated = Date.now();
|
||||||
if (updated - startkey > A_WEEK_MS) {
|
if (updated - startkey > A_WEEK_MS) {
|
||||||
startkey = updated - A_WEEK_MS;
|
startkey = updated - A_WEEK_MS;
|
||||||
console.warn('[%s] list modules since time out of range: query: %j, ip: %s',
|
console.warn('[%s] list modules since time out of range: query: %j, ip: %s',
|
||||||
Date(), query, this.ip);
|
Date(), query, this.ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
var names = yield* packageService.listPublicModuleNamesSince(startkey);
|
const names = yield packageService.listPublicModuleNamesSince(startkey);
|
||||||
var result = { _updated: updated };
|
const result = { _updated: updated };
|
||||||
names.forEach(function (name) {
|
names.forEach(function(name) {
|
||||||
result[name] = true;
|
result[name] = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -14,25 +14,25 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var debug = require('debug')('cnpmjs.org:controllers:registry:package:remove');
|
const debug = require('debug')('cnpmjs.org:controllers:registry:package:remove');
|
||||||
var urlparse = require('url').parse;
|
const urlparse = require('url').parse;
|
||||||
var packageService = require('../../../services/package');
|
const packageService = require('../../../services/package');
|
||||||
var totalService = require('../../../services/total');
|
const totalService = require('../../../services/total');
|
||||||
var nfs = require('../../../common/nfs');
|
const nfs = require('../../../common/nfs');
|
||||||
var logger = require('../../../common/logger');
|
const logger = require('../../../common/logger');
|
||||||
|
|
||||||
// DELETE /:name/-rev/:rev
|
// DELETE /:name/-rev/:rev
|
||||||
// https://github.com/npm/npm-registry-client/blob/master/lib/unpublish.js#L25
|
// https://github.com/npm/npm-registry-client/blob/master/lib/unpublish.js#L25
|
||||||
module.exports = function* remove(next) {
|
module.exports = function* remove(next) {
|
||||||
var name = this.params.name || this.params[0];
|
const name = this.params.name || this.params[0];
|
||||||
var rev = this.params.rev || this.params[1];
|
const rev = this.params.rev || this.params[1];
|
||||||
debug('remove all the module with name: %s, id: %s', name, rev);
|
debug('remove all the module with name: %s, id: %s', name, rev);
|
||||||
|
|
||||||
var mods = yield* packageService.listModulesByName(name);
|
const mods = yield packageService.listModulesByName(name);
|
||||||
debug('removeAll module %s: %d', name, mods.length);
|
debug('removeAll module %s: %d', name, mods.length);
|
||||||
var mod = mods[0];
|
const mod = mods[0];
|
||||||
if (!mod) {
|
if (!mod) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield [
|
yield [
|
||||||
@@ -41,11 +41,11 @@ module.exports = function* remove(next) {
|
|||||||
totalService.plusDeleteModule(),
|
totalService.plusDeleteModule(),
|
||||||
];
|
];
|
||||||
|
|
||||||
var keys = [];
|
const keys = [];
|
||||||
for (var i = 0; i < mods.length; i++) {
|
for (let i = 0; i < mods.length; i++) {
|
||||||
var row = mods[i];
|
const row = mods[i];
|
||||||
var dist = row.package.dist;
|
const dist = row.package.dist;
|
||||||
var key = dist.key;
|
let key = dist.key;
|
||||||
if (!key) {
|
if (!key) {
|
||||||
key = urlparse(dist.tarball).pathname;
|
key = urlparse(dist.tarball).pathname;
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ module.exports = function* remove(next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
yield keys.map(function (key) {
|
yield keys.map(function(key) {
|
||||||
return nfs.remove(key);
|
return nfs.remove(key);
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -61,7 +61,7 @@ module.exports = function* remove(next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remove the maintainers
|
// remove the maintainers
|
||||||
yield* packageService.removeAllMaintainers(name);
|
yield packageService.removeAllMaintainers(name);
|
||||||
|
|
||||||
this.body = { ok: true };
|
this.body = { ok: true };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,45 +14,45 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var debug = require('debug')('cnpmjs.org:controllers:registry:package:remove_version');
|
const debug = require('debug')('cnpmjs.org:controllers:registry:package:remove_version');
|
||||||
var packageService = require('../../../services/package');
|
const packageService = require('../../../services/package');
|
||||||
var nfs = require('../../../common/nfs');
|
const nfs = require('../../../common/nfs');
|
||||||
var logger = require('../../../common/logger');
|
const logger = require('../../../common/logger');
|
||||||
var getCDNKey = require('../../../lib/common').getCDNKey;
|
const getCDNKey = require('../../../lib/common').getCDNKey;
|
||||||
|
|
||||||
// DELETE /:name/download/:filename/-rev/:rev
|
// DELETE /:name/download/:filename/-rev/:rev
|
||||||
// https://github.com/npm/npm-registry-client/blob/master/lib/unpublish.js#L97
|
// https://github.com/npm/npm-registry-client/blob/master/lib/unpublish.js#L97
|
||||||
module.exports = function* removeOneVersion(next) {
|
module.exports = function* removeOneVersion(next) {
|
||||||
var name = this.params.name || this.params[0];
|
const name = this.params.name || this.params[0];
|
||||||
var filename = this.params.filename || this.params[1];
|
const filename = this.params.filename || this.params[1];
|
||||||
var id = Number(this.params.rev || this.params[2]);
|
const id = Number(this.params.rev || this.params[2]);
|
||||||
// cnpmjs.org-2.0.0.tgz
|
// cnpmjs.org-2.0.0.tgz
|
||||||
var version = filename.split(name + '-')[1];
|
let version = filename.split(name + '-')[1];
|
||||||
if (version) {
|
if (version) {
|
||||||
// 2.0.0.tgz
|
// 2.0.0.tgz
|
||||||
version = version.substring(0, version.lastIndexOf('.tgz'));
|
version = version.substring(0, version.lastIndexOf('.tgz'));
|
||||||
}
|
}
|
||||||
if (!version) {
|
if (!version) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug('remove tarball with filename: %s, version: %s, revert to => rev id: %s', filename, version, id);
|
debug('remove tarball with filename: %s, version: %s, revert to => rev id: %s', filename, version, id);
|
||||||
|
|
||||||
if (isNaN(id)) {
|
if (isNaN(id)) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
|
|
||||||
var rs = yield [
|
const rs = yield [
|
||||||
packageService.getModuleById(id),
|
packageService.getModuleById(id),
|
||||||
packageService.getModule(name, version),
|
packageService.getModule(name, version),
|
||||||
];
|
];
|
||||||
var revertTo = rs[0];
|
const revertTo = rs[0];
|
||||||
var mod = rs[1]; // module need to delete
|
const mod = rs[1]; // module need to delete
|
||||||
if (!mod || mod.name !== name) {
|
if (!mod || mod.name !== name) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
|
|
||||||
var key = mod.package && mod.package.dist && mod.package.dist.key;
|
let key = mod.package && mod.package.dist && mod.package.dist.key;
|
||||||
if (!key) {
|
if (!key) {
|
||||||
key = getCDNKey(mod.name, filename);
|
key = getCDNKey(mod.name, filename);
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ module.exports = function* removeOneVersion(next) {
|
|||||||
logger.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
// remove version from table
|
// remove version from table
|
||||||
yield* packageService.removeModulesByNameAndVersions(name, [version]);
|
yield packageService.removeModulesByNameAndVersions(name, [ version ]);
|
||||||
debug('removed %s@%s', name, version);
|
debug('removed %s@%s', name, version);
|
||||||
this.body = { ok: true };
|
this.body = { ok: true };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,26 +1,12 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - controllers/registry/package/save.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const debug = require('debug')('cnpmjs.org:controllers:registry:package:save');
|
||||||
* Module dependencies.
|
const crypto = require('crypto');
|
||||||
*/
|
const deprecateVersions = require('./deprecate');
|
||||||
|
const packageService = require('../../../services/package');
|
||||||
var debug = require('debug')('cnpmjs.org:controllers:registry:package:save');
|
const common = require('../../../lib/common');
|
||||||
var crypto = require('crypto');
|
const nfs = require('../../../common/nfs');
|
||||||
var deprecateVersions = require('./deprecate');
|
const config = require('../../../config');
|
||||||
var packageService = require('../../../services/package');
|
|
||||||
var common = require('../../../lib/common');
|
|
||||||
var nfs = require('../../../common/nfs');
|
|
||||||
var config = require('../../../config');
|
|
||||||
|
|
||||||
// old flows:
|
// old flows:
|
||||||
// 1. add()
|
// 1. add()
|
||||||
@@ -37,63 +23,63 @@ module.exports = function* save(next) {
|
|||||||
// { content_type: 'application/octet-stream',
|
// { content_type: 'application/octet-stream',
|
||||||
// data: 'H4sIAAAAA
|
// data: 'H4sIAAAAA
|
||||||
// length: 9883
|
// length: 9883
|
||||||
var pkg = this.request.body;
|
const pkg = this.request.body;
|
||||||
var username = this.user.name;
|
const username = this.user.name;
|
||||||
var name = this.params.name || this.params[0];
|
const name = this.params.name || this.params[0];
|
||||||
var filename = Object.keys(pkg._attachments || {})[0];
|
const filename = Object.keys(pkg._attachments || {})[0];
|
||||||
var version = Object.keys(pkg.versions || {})[0];
|
const version = Object.keys(pkg.versions || {})[0];
|
||||||
if (!version) {
|
if (!version) {
|
||||||
this.status = 400;
|
this.status = 400;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'version_error',
|
error: 'version_error',
|
||||||
reason: 'package.versions is empty'
|
reason: 'package.versions is empty',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check maintainers
|
// check maintainers
|
||||||
var result = yield* packageService.authMaintainer(name, username);
|
const result = yield packageService.authMaintainer(name, username);
|
||||||
if (!result.isMaintainer) {
|
if (!result.isMaintainer) {
|
||||||
this.status = 403;
|
this.status = 403;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'forbidden user',
|
error: 'forbidden user',
|
||||||
reason: username + ' not authorized to modify ' + name +
|
reason: username + ' not authorized to modify ' + name +
|
||||||
', please contact maintainers: ' + result.maintainers.join(', ')
|
', please contact maintainers: ' + result.maintainers.join(', '),
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filename) {
|
if (!filename) {
|
||||||
var hasDeprecated = false;
|
let hasDeprecated = false;
|
||||||
for (var v in pkg.versions) {
|
for (const v in pkg.versions) {
|
||||||
var row = pkg.versions[v];
|
const row = pkg.versions[v];
|
||||||
if (typeof row.deprecated === 'string') {
|
if (typeof row.deprecated === 'string') {
|
||||||
hasDeprecated = true;
|
hasDeprecated = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasDeprecated) {
|
if (hasDeprecated) {
|
||||||
return yield* deprecateVersions.call(this, next);
|
return yield deprecateVersions.call(this, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.status = 400;
|
this.status = 400;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'attachment_error',
|
error: 'attachment_error',
|
||||||
reason: 'package._attachments is empty'
|
reason: 'package._attachments is empty',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var attachment = pkg._attachments[filename];
|
const attachment = pkg._attachments[filename];
|
||||||
var versionPackage = pkg.versions[version];
|
const versionPackage = pkg.versions[version];
|
||||||
var maintainers = versionPackage.maintainers;
|
const maintainers = versionPackage.maintainers;
|
||||||
|
|
||||||
// should never happened in normal request
|
// should never happened in normal request
|
||||||
if (!maintainers) {
|
if (!maintainers) {
|
||||||
this.status = 400;
|
this.status = 400;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'maintainers error',
|
error: 'maintainers error',
|
||||||
reason: 'request body need maintainers'
|
reason: 'request body need maintainers',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -103,31 +89,31 @@ module.exports = function* save(next) {
|
|||||||
|
|
||||||
// make sure user in auth is in maintainers
|
// make sure user in auth is in maintainers
|
||||||
// should never happened in normal request
|
// should never happened in normal request
|
||||||
var m = maintainers.filter(function (maintainer) {
|
const m = maintainers.filter(function(maintainer) {
|
||||||
return maintainer.name === username;
|
return maintainer.name === username;
|
||||||
});
|
});
|
||||||
if (m.length === 0) {
|
if (m.length === 0) {
|
||||||
this.status = 403;
|
this.status = 403;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'maintainers error',
|
error: 'maintainers error',
|
||||||
reason: username + ' does not in maintainer list'
|
reason: username + ' does not in maintainer list',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add this info into some table
|
// TODO: add this info into some table
|
||||||
versionPackage._publish_on_cnpm = true;
|
versionPackage._publish_on_cnpm = true;
|
||||||
var distTags = pkg['dist-tags'] || {};
|
const distTags = pkg['dist-tags'] || {};
|
||||||
var tags = []; // tag, version
|
const tags = []; // tag, version
|
||||||
for (var t in distTags) {
|
for (const t in distTags) {
|
||||||
tags.push([t, distTags[t]]);
|
tags.push([ t, distTags[t] ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tags.length === 0) {
|
if (tags.length === 0) {
|
||||||
this.status = 400;
|
this.status = 400;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'invalid',
|
error: 'invalid',
|
||||||
reason: 'dist-tags should not be empty'
|
reason: 'dist-tags should not be empty',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -135,20 +121,19 @@ module.exports = function* save(next) {
|
|||||||
debug('%s publish new %s:%s, attachment size: %s, maintainers: %j, distTags: %j',
|
debug('%s publish new %s:%s, attachment size: %s, maintainers: %j, distTags: %j',
|
||||||
username, name, version, attachment.length, versionPackage.maintainers, distTags);
|
username, name, version, attachment.length, versionPackage.maintainers, distTags);
|
||||||
|
|
||||||
var exists = yield* packageService.getModule(name, version);
|
const exists = yield packageService.getModule(name, version);
|
||||||
var shasum;
|
let shasum;
|
||||||
if (exists) {
|
if (exists) {
|
||||||
this.status = 403;
|
this.status = 403;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'forbidden',
|
error: 'forbidden',
|
||||||
reason: 'cannot modify pre-existing version: ' + version
|
reason: 'cannot modify pre-existing version: ' + version,
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// upload attachment
|
// upload attachment
|
||||||
var tarballBuffer;
|
const tarballBuffer = new Buffer(attachment.data, 'base64');
|
||||||
tarballBuffer = new Buffer(attachment.data, 'base64');
|
|
||||||
|
|
||||||
if (tarballBuffer.length !== attachment.length) {
|
if (tarballBuffer.length !== attachment.length) {
|
||||||
this.status = 403;
|
this.status = 403;
|
||||||
@@ -162,10 +147,10 @@ module.exports = function* save(next) {
|
|||||||
|
|
||||||
if (!distTags.latest) {
|
if (!distTags.latest) {
|
||||||
// need to check if latest tag exists or not
|
// need to check if latest tag exists or not
|
||||||
var latest = yield* packageService.getModuleByTag(name, 'latest');
|
const latest = yield packageService.getModuleByTag(name, 'latest');
|
||||||
if (!latest) {
|
if (!latest) {
|
||||||
// auto add latest
|
// auto add latest
|
||||||
tags.push(['latest', tags[0][1]]);
|
tags.push([ 'latest', tags[0][1] ]);
|
||||||
debug('auto add latest tag: %j', tags);
|
debug('auto add latest tag: %j', tags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,16 +159,16 @@ module.exports = function* save(next) {
|
|||||||
shasum.update(tarballBuffer);
|
shasum.update(tarballBuffer);
|
||||||
shasum = shasum.digest('hex');
|
shasum = shasum.digest('hex');
|
||||||
|
|
||||||
var options = {
|
const options = {
|
||||||
key: common.getCDNKey(name, filename),
|
key: common.getCDNKey(name, filename),
|
||||||
shasum: shasum
|
shasum,
|
||||||
};
|
};
|
||||||
var uploadResult = yield nfs.uploadBuffer(tarballBuffer, options);
|
const uploadResult = yield nfs.uploadBuffer(tarballBuffer, options);
|
||||||
debug('upload %j', uploadResult);
|
debug('upload %j', uploadResult);
|
||||||
|
|
||||||
var dist = {
|
const dist = {
|
||||||
shasum: shasum,
|
shasum,
|
||||||
size: attachment.length
|
size: attachment.length,
|
||||||
};
|
};
|
||||||
|
|
||||||
// if nfs upload return a key, record it
|
// if nfs upload return a key, record it
|
||||||
@@ -194,42 +179,42 @@ module.exports = function* save(next) {
|
|||||||
dist.tarball = uploadResult.key;
|
dist.tarball = uploadResult.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mod = {
|
const mod = {
|
||||||
name: name,
|
name,
|
||||||
version: version,
|
version,
|
||||||
author: username,
|
author: username,
|
||||||
package: versionPackage
|
package: versionPackage,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod.package.dist = dist;
|
mod.package.dist = dist;
|
||||||
yield* addDepsRelations(mod.package);
|
yield addDepsRelations(mod.package);
|
||||||
|
|
||||||
var addResult = yield* packageService.saveModule(mod);
|
const addResult = yield packageService.saveModule(mod);
|
||||||
debug('%s module: save file to %s, size: %d, sha1: %s, dist: %j, version: %s',
|
debug('%s module: save file to %s, size: %d, sha1: %s, dist: %j, version: %s',
|
||||||
addResult.id, dist.tarball, dist.size, shasum, dist, version);
|
addResult.id, dist.tarball, dist.size, shasum, dist, version);
|
||||||
|
|
||||||
if (tags.length) {
|
if (tags.length) {
|
||||||
yield tags.map(function (tag) {
|
yield tags.map(function(tag) {
|
||||||
// tag: [tagName, version]
|
// tag: [tagName, version]
|
||||||
return packageService.addModuleTag(name, tag[0], tag[1]);
|
return packageService.addModuleTag(name, tag[0], tag[1]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure maintainers exists
|
// ensure maintainers exists
|
||||||
var maintainerNames = maintainers.map(function (item) {
|
const maintainerNames = maintainers.map(function(item) {
|
||||||
return item.name;
|
return item.name;
|
||||||
});
|
});
|
||||||
yield* packageService.addPrivateModuleMaintainers(name, maintainerNames);
|
yield packageService.addPrivateModuleMaintainers(name, maintainerNames);
|
||||||
|
|
||||||
this.status = 201;
|
this.status = 201;
|
||||||
this.body = {
|
this.body = {
|
||||||
ok: true,
|
ok: true,
|
||||||
rev: String(addResult.id)
|
rev: String(addResult.id),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function* addDepsRelations(pkg) {
|
function* addDepsRelations(pkg) {
|
||||||
var dependencies = Object.keys(pkg.dependencies || {});
|
let dependencies = Object.keys(pkg.dependencies || {});
|
||||||
if (dependencies.length > config.maxDependencies) {
|
if (dependencies.length > config.maxDependencies) {
|
||||||
dependencies = dependencies.slice(0, config.maxDependencies);
|
dependencies = dependencies.slice(0, config.maxDependencies);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,11 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.js - controllers/registry/package/show.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const debug = require('debug')('cnpmjs.org:controllers:registry:package:show');
|
||||||
* Module dependencies.
|
const semver = require('semver');
|
||||||
*/
|
const packageService = require('../../../services/package');
|
||||||
|
const setDownloadURL = require('../../../lib/common').setDownloadURL;
|
||||||
var debug = require('debug')('cnpmjs.org:controllers:registry:package:show');
|
const SyncModuleWorker = require('../../sync_module_worker');
|
||||||
var semver = require('semver');
|
const config = require('../../../config');
|
||||||
var packageService = require('../../../services/package');
|
|
||||||
var npmService = require('../../../services/npm');
|
|
||||||
var setDownloadURL = require('../../../lib/common').setDownloadURL;
|
|
||||||
var SyncModuleWorker = require('../../sync_module_worker');
|
|
||||||
var config = require('../../../config');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [deprecate] api
|
* [deprecate] api
|
||||||
@@ -31,54 +16,59 @@ var config = require('../../../config');
|
|||||||
* GET /:name/:tag
|
* GET /:name/:tag
|
||||||
*/
|
*/
|
||||||
module.exports = function* show() {
|
module.exports = function* show() {
|
||||||
var name = this.params.name || this.params[0];
|
const name = this.params.name || this.params[0];
|
||||||
var tag = this.params.version || this.params[1];
|
let tag = this.params.version || this.params[1];
|
||||||
var version = semver.valid(tag);
|
if (tag === '*') {
|
||||||
var mod;
|
tag = 'latest';
|
||||||
if (version) {
|
|
||||||
mod = yield* packageService.getModule(name, version);
|
|
||||||
} else {
|
|
||||||
mod = yield* packageService.getModuleByTag(name, tag);
|
|
||||||
}
|
}
|
||||||
|
const version = semver.valid(tag);
|
||||||
|
const range = semver.validRange(tag);
|
||||||
|
let mod;
|
||||||
|
if (version) {
|
||||||
|
mod = yield packageService.getModule(name, version);
|
||||||
|
} else if (range) {
|
||||||
|
mod = yield packageService.getModuleByRange(name, range);
|
||||||
|
} else {
|
||||||
|
mod = yield packageService.getModuleByTag(name, tag);
|
||||||
|
}
|
||||||
|
|
||||||
if (mod) {
|
if (mod) {
|
||||||
setDownloadURL(mod.package, this);
|
setDownloadURL(mod.package, this);
|
||||||
mod.package._cnpm_publish_time = mod.publish_time;
|
mod.package._cnpm_publish_time = mod.publish_time;
|
||||||
var maintainers = yield* packageService.listMaintainers(name);
|
mod.package.publish_time = mod.package.publish_time || mod.publish_time;
|
||||||
|
const rs = yield [
|
||||||
|
packageService.listMaintainers(name),
|
||||||
|
packageService.listModuleTags(name),
|
||||||
|
];
|
||||||
|
const maintainers = rs[0];
|
||||||
if (maintainers.length > 0) {
|
if (maintainers.length > 0) {
|
||||||
mod.package.maintainers = maintainers;
|
mod.package.maintainers = maintainers;
|
||||||
}
|
}
|
||||||
this.body = mod.package;
|
const tags = rs[1];
|
||||||
|
const distTags = {};
|
||||||
|
for (let i = 0; i < tags.length; i++) {
|
||||||
|
const t = tags[i];
|
||||||
|
distTags[t.tag] = t.version;
|
||||||
|
}
|
||||||
|
// show tags for npminstall faster download
|
||||||
|
mod.package['dist-tags'] = distTags;
|
||||||
|
this.jsonp = mod.package;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if not fond, sync from source registry
|
// if not fond, sync from source registry
|
||||||
if (!this.allowSync) {
|
if (!this.allowSync) {
|
||||||
this.status = 404;
|
this.status = 404;
|
||||||
this.body = {
|
this.jsonp = {
|
||||||
error: 'not exist',
|
error: 'not exist',
|
||||||
reason: 'version not found: ' + version
|
reason: 'version not found: ' + version,
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// start sync
|
// start sync
|
||||||
var logId = yield* SyncModuleWorker.sync(name, 'sync-by-install');
|
const logId = yield SyncModuleWorker.sync(name, 'sync-by-install');
|
||||||
debug('start sync %s, get log id %s', name, logId);
|
debug('start sync %s, get log id %s', name, logId);
|
||||||
|
|
||||||
// rty to get package from official registry
|
this.redirect(config.officialNpmRegistry + this.url);
|
||||||
var r = yield npmService.request('/' + name + '/' + tag, {
|
|
||||||
registry: config.officialNpmRegistry
|
|
||||||
});
|
|
||||||
|
|
||||||
if (r.status !== 200) {
|
|
||||||
debug('requet from officialNpmRegistry response %s', r.status);
|
|
||||||
this.status = 404;
|
|
||||||
this.body = {
|
|
||||||
error: 'not exist',
|
|
||||||
reason: 'tag or version not found: ' + tag
|
|
||||||
};
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.body = r.data;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,69 +1,55 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - controllers/registry/package/tag.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const debug = require('debug')('cnpmjs.org:controllers:registry:package:tag');
|
||||||
* Module dependencies.
|
const semver = require('semver');
|
||||||
*/
|
const util = require('util');
|
||||||
|
const packageService = require('../../../services/package');
|
||||||
var debug = require('debug')('cnpmjs.org:controllers:registry:package:tag');
|
|
||||||
var semver = require('semver');
|
|
||||||
var util = require('util');
|
|
||||||
var packageService = require('../../../services/package');
|
|
||||||
|
|
||||||
// PUT /:name/:tag
|
// PUT /:name/:tag
|
||||||
// https://github.com/npm/npm-registry-client/blob/master/lib/tag.js#L4
|
// https://github.com/npm/npm-registry-client/blob/master/lib/tag.js#L4
|
||||||
// this.request("PUT", uri+"/"+tagName, { body : JSON.stringify(version) }, cb)
|
// this.request("PUT", uri+"/"+tagName, { body : JSON.stringify(version) }, cb)
|
||||||
module.exports = function* tag() {
|
module.exports = function* tag() {
|
||||||
var version = this.request.body;
|
const version = this.request.body;
|
||||||
var name = this.params.name || this.params[0];
|
const name = this.params.name || this.params[0];
|
||||||
var tag = this.params.tag || this.params[1];
|
const tag = this.params.tag || this.params[1];
|
||||||
debug('tag %j to %s/%s', version, name, tag);
|
debug('tag %j to %s/%s', version, name, tag);
|
||||||
|
|
||||||
if (!version) {
|
if (!version) {
|
||||||
this.status = 400;
|
this.status = 400;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'version_missed',
|
error: 'version_missed',
|
||||||
reason: 'version not found'
|
reason: 'version not found',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!semver.valid(version)) {
|
if (!semver.valid(version)) {
|
||||||
this.status = 403;
|
this.status = 403;
|
||||||
var reason = util.format('setting tag %s to invalid version: %s: %s/%s',
|
const reason = util.format('setting tag %s to invalid version: %s: %s/%s',
|
||||||
tag, version, name, tag);
|
tag, version, name, tag);
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'forbidden',
|
error: 'forbidden',
|
||||||
reason: reason
|
reason,
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mod = yield* packageService.getModule(name, version);
|
const mod = yield packageService.getModule(name, version);
|
||||||
if (!mod) {
|
if (!mod) {
|
||||||
this.status = 403;
|
this.status = 403;
|
||||||
var reason = util.format('setting tag %s to unknown version: %s: %s/%s',
|
const reason = util.format('setting tag %s to unknown version: %s: %s/%s',
|
||||||
tag, version, name, tag);
|
tag, version, name, tag);
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'forbidden',
|
error: 'forbidden',
|
||||||
reason: reason
|
reason,
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var row = yield* packageService.addModuleTag(name, tag, version);
|
const row = yield packageService.addModuleTag(name, tag, version);
|
||||||
this.status = 201;
|
this.status = 201;
|
||||||
this.body = {
|
this.body = {
|
||||||
ok: true,
|
ok: true,
|
||||||
modified: row.gmt_modified
|
modified: row.gmt_modified,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,65 +1,51 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - controllers/registry/package/update.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const debug = require('debug')('cnpmjs.org:controllers:registry:package:update');
|
||||||
* Module dependencies.
|
const packageService = require('../../../services/package');
|
||||||
*/
|
const userService = require('../../../services/user');
|
||||||
|
const config = require('../../../config');
|
||||||
var debug = require('debug')('cnpmjs.org:controllers:registry:package:update');
|
|
||||||
var packageService = require('../../../services/package');
|
|
||||||
var userService = require('../../../services/user');
|
|
||||||
var config = require('../../../config');
|
|
||||||
|
|
||||||
// PUT /:name/-rev/:rev
|
// PUT /:name/-rev/:rev
|
||||||
//
|
//
|
||||||
// * remove with versions, then will `DELETE /:name/download/:filename/-rev/:rev`
|
// * remove with versions, then will `DELETE /:name/download/:filename/-rev/:rev`
|
||||||
// * ...
|
// * ...
|
||||||
module.exports = function* update(next) {
|
module.exports = function* update(next) {
|
||||||
var name = this.params.name || this.params[0];
|
const name = this.params.name || this.params[0];
|
||||||
debug('update module %s, %s, %j', this.url, name, this.request.body);
|
debug('update module %s, %s, %j', this.url, name, this.request.body);
|
||||||
|
|
||||||
var body = this.request.body;
|
const body = this.request.body;
|
||||||
if (body.versions) {
|
if (body.versions) {
|
||||||
yield* updateVersions.call(this, next);
|
yield updateVersions.call(this, next);
|
||||||
} else if (body.maintainers) {
|
} else if (body.maintainers) {
|
||||||
yield* updateMaintainers.call(this, next);
|
yield updateMaintainers.call(this, next);
|
||||||
} else {
|
} else {
|
||||||
yield* next;
|
yield next;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// update with versions
|
// update with versions
|
||||||
// https://github.com/npm/npm-registry-client/blob/master/lib/unpublish.js#L63
|
// https://github.com/npm/npm-registry-client/blob/master/lib/unpublish.js#L63
|
||||||
function* updateVersions(next) {
|
function* updateVersions(next) {
|
||||||
var name = this.params.name || this.params[0];
|
const name = this.params.name || this.params[0];
|
||||||
// left versions
|
// left versions
|
||||||
var versions = this.request.body.versions;
|
const versions = this.request.body.versions;
|
||||||
|
|
||||||
// step1: list all the versions
|
// step1: list all the versions
|
||||||
var mods = yield* packageService.listModulesByName(name);
|
const mods = yield packageService.listModulesByName(name);
|
||||||
debug('removeWithVersions module %s, left versions %j, %s mods',
|
debug('removeWithVersions module %s, left versions %j, %s mods',
|
||||||
name, Object.keys(versions), mods && mods.length);
|
name, Object.keys(versions), mods && mods.length);
|
||||||
if (!mods || !mods.length) {
|
if (!mods || !mods.length) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// step3: calculate which versions need to remove and
|
// step3: calculate which versions need to remove and
|
||||||
// which versions need to remain
|
// which versions need to remain
|
||||||
var removeVersions = [];
|
const removeVersions = [];
|
||||||
var removeVersionMaps = {};
|
const removeVersionMaps = {};
|
||||||
var remainVersions = [];
|
const remainVersions = [];
|
||||||
|
|
||||||
for (var i = 0; i < mods.length; i++) {
|
for (let i = 0; i < mods.length; i++) {
|
||||||
var v = mods[i].version;
|
const v = mods[i].version;
|
||||||
if (!versions[v]) {
|
if (!versions[v]) {
|
||||||
removeVersions.push(v);
|
removeVersions.push(v);
|
||||||
removeVersionMaps[v] = true;
|
removeVersionMaps[v] = true;
|
||||||
@@ -78,11 +64,11 @@ function* updateVersions(next) {
|
|||||||
|
|
||||||
// step 4: remove all the versions which need to remove
|
// step 4: remove all the versions which need to remove
|
||||||
// let removeTar do remove versions from module table
|
// let removeTar do remove versions from module table
|
||||||
var tags = yield* packageService.listModuleTags(name);
|
const tags = yield packageService.listModuleTags(name);
|
||||||
|
|
||||||
var removeTags = [];
|
const removeTags = [];
|
||||||
var latestRemoved = false;
|
let latestRemoved = false;
|
||||||
tags.forEach(function (tag) {
|
tags.forEach(function(tag) {
|
||||||
// this tag need be removed
|
// this tag need be removed
|
||||||
if (removeVersionMaps[tag.version]) {
|
if (removeVersionMaps[tag.version]) {
|
||||||
removeTags.push(tag.id);
|
removeTags.push(tag.id);
|
||||||
@@ -95,28 +81,28 @@ function* updateVersions(next) {
|
|||||||
debug('remove tags: %j', removeTags);
|
debug('remove tags: %j', removeTags);
|
||||||
if (removeTags.length) {
|
if (removeTags.length) {
|
||||||
// step 5: remove all the tags
|
// step 5: remove all the tags
|
||||||
yield* packageService.removeModuleTagsByIds(removeTags);
|
yield packageService.removeModuleTagsByIds(removeTags);
|
||||||
if (latestRemoved && remainVersions[0]) {
|
if (latestRemoved && remainVersions[0]) {
|
||||||
debug('latest tags removed, generate a new latest tag with new version: %s',
|
debug('latest tags removed, generate a new latest tag with new version: %s',
|
||||||
remainVersions[0]);
|
remainVersions[0]);
|
||||||
// step 6: insert new latest tag
|
// step 6: insert new latest tag
|
||||||
yield* packageService.addModuleTag(name, 'latest', remainVersions[0]);
|
yield packageService.addModuleTag(name, 'latest', remainVersions[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// step 7: update last modified, make sure etag change
|
// step 7: update last modified, make sure etag change
|
||||||
yield* packageService.updateModuleLastModified(name);
|
yield packageService.updateModuleLastModified(name);
|
||||||
|
|
||||||
this.status = 201;
|
this.status = 201;
|
||||||
this.body = { ok: true };
|
this.body = { ok: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
function* updateMaintainers() {
|
function* updateMaintainers() {
|
||||||
var name = this.params.name || this.params[0];
|
const name = this.params.name || this.params[0];
|
||||||
var body = this.request.body;
|
const body = this.request.body;
|
||||||
debug('updateMaintainers module %s, %j', name, body);
|
debug('updateMaintainers module %s, %j', name, body);
|
||||||
|
|
||||||
var usernames = body.maintainers.map(function (user) {
|
const usernames = body.maintainers.map(function(user) {
|
||||||
return user.name;
|
return user.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -124,35 +110,32 @@ function* updateMaintainers() {
|
|||||||
this.status = 403;
|
this.status = 403;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'invalid operation',
|
error: 'invalid operation',
|
||||||
reason: 'Can not remove all maintainers'
|
reason: 'Can not remove all maintainers',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.customUserService) {
|
if (config.customUserService) {
|
||||||
// ensure new authors are vaild
|
// ensure new authors are vaild
|
||||||
var maintainers = yield* packageService.listMaintainerNamesOnly(name);
|
const maintainers = yield packageService.listMaintainerNamesOnly(name);
|
||||||
var map = {};
|
const map = {};
|
||||||
var newNames = [];
|
const newNames = [];
|
||||||
for (var i = 0; i < maintainers.length; i++) {
|
for (const maintainer of maintainers) {
|
||||||
map[maintainers[i]] = 1;
|
map[maintainer] = 1;
|
||||||
}
|
}
|
||||||
for (var i = 0; i < usernames.length; i++) {
|
for (const username of usernames) {
|
||||||
var username = usernames[i];
|
|
||||||
if (map[username] !== 1) {
|
if (map[username] !== 1) {
|
||||||
newNames.push(username);
|
newNames.push(username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (newNames.length > 0) {
|
if (newNames.length > 0) {
|
||||||
var users = yield* userService.list(newNames);
|
const users = yield userService.list(newNames);
|
||||||
var map = {};
|
const map = {};
|
||||||
for (var i = 0; i < users.length; i++) {
|
for (const user of users) {
|
||||||
var user = users[i];
|
|
||||||
map[user.login] = 1;
|
map[user.login] = 1;
|
||||||
}
|
}
|
||||||
var invailds = [];
|
const invailds = [];
|
||||||
for (var i = 0; i < newNames.length; i++) {
|
for (const username of newNames) {
|
||||||
var username = newNames[i];
|
|
||||||
if (map[username] !== 1) {
|
if (map[username] !== 1) {
|
||||||
invailds.push(username);
|
invailds.push(username);
|
||||||
}
|
}
|
||||||
@@ -161,14 +144,14 @@ function* updateMaintainers() {
|
|||||||
this.status = 403;
|
this.status = 403;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'invalid user name',
|
error: 'invalid user name',
|
||||||
reason: 'User: `' + invailds.join(', ') + '` not exists'
|
reason: 'User: `' + invailds.join(', ') + '` not exists',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var r = yield* packageService.updatePrivateModuleMaintainers(name, usernames);
|
const r = yield packageService.updatePrivateModuleMaintainers(name, usernames);
|
||||||
debug('result: %j', r);
|
debug('result: %j', r);
|
||||||
|
|
||||||
this.status = 201;
|
this.status = 201;
|
||||||
|
|||||||
@@ -15,9 +15,9 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var ensurePasswordSalt = require('./common').ensurePasswordSalt;
|
const ensurePasswordSalt = require('./common').ensurePasswordSalt;
|
||||||
var userService = require('../../../services/user');
|
const userService = require('../../../services/user');
|
||||||
var config = require('../../../config');
|
const config = require('../../../config');
|
||||||
|
|
||||||
// npm 1.4.4
|
// npm 1.4.4
|
||||||
// add new user first
|
// add new user first
|
||||||
@@ -53,9 +53,9 @@ var config = require('../../../config');
|
|||||||
// roles: [],
|
// roles: [],
|
||||||
// date: '2014-03-15T02:39:25.696Z' }
|
// date: '2014-03-15T02:39:25.696Z' }
|
||||||
module.exports = function* addUser() {
|
module.exports = function* addUser() {
|
||||||
var name = this.params.name;
|
const name = this.params.name;
|
||||||
var body = this.request.body || {};
|
const body = this.request.body || {};
|
||||||
var user = {
|
const user = {
|
||||||
name: body.name,
|
name: body.name,
|
||||||
// salt: body.salt,
|
// salt: body.salt,
|
||||||
// password_sha: body.password_sha,
|
// password_sha: body.password_sha,
|
||||||
@@ -70,19 +70,19 @@ module.exports = function* addUser() {
|
|||||||
this.status = 422;
|
this.status = 422;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'paramError',
|
error: 'paramError',
|
||||||
reason: 'params missing, name, email or password missing.'
|
reason: 'params missing, name, email or password missing.',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var loginedUser;
|
let loginedUser;
|
||||||
try {
|
try {
|
||||||
loginedUser = yield* userService.authAndSave(body.name, body.password);
|
loginedUser = yield userService.authAndSave(body.name, body.password);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.status = err.status || 500;
|
this.status = err.status || 500;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: err.name,
|
error: err.name,
|
||||||
reason: err.message
|
reason: err.message,
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ module.exports = function* addUser() {
|
|||||||
this.body = {
|
this.body = {
|
||||||
ok: true,
|
ok: true,
|
||||||
id: 'org.couchdb.user:' + loginedUser.login,
|
id: 'org.couchdb.user:' + loginedUser.login,
|
||||||
rev: Date.now() + '-' + loginedUser.login
|
rev: Date.now() + '-' + loginedUser.login,
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -101,28 +101,28 @@ module.exports = function* addUser() {
|
|||||||
this.status = 401;
|
this.status = 401;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'unauthorized',
|
error: 'unauthorized',
|
||||||
reason: 'Login fail, please check your login name and password'
|
reason: 'Login fail, please check your login name and password',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var existUser = yield* userService.get(name);
|
const existUser = yield userService.get(name);
|
||||||
if (existUser) {
|
if (existUser) {
|
||||||
this.status = 409;
|
this.status = 409;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'conflict',
|
error: 'conflict',
|
||||||
reason: 'User ' + name + ' already exists.'
|
reason: 'User ' + name + ' already exists.',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add new user
|
// add new user
|
||||||
var result = yield* userService.add(user);
|
const result = yield userService.add(user);
|
||||||
this.etag = '"' + result.rev + '"';
|
this.etag = '"' + result.rev + '"';
|
||||||
this.status = 201;
|
this.status = 201;
|
||||||
this.body = {
|
this.body = {
|
||||||
ok: true,
|
ok: true,
|
||||||
id: 'org.couchdb.user:' + name,
|
id: 'org.couchdb.user:' + name,
|
||||||
rev: result.rev
|
rev: result.rev,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,10 +14,10 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
var utility = require('utility');
|
const utility = require('utility');
|
||||||
|
|
||||||
exports.ensurePasswordSalt = function (user, body) {
|
exports.ensurePasswordSalt = function(user, body) {
|
||||||
if (!user.password_sha && body.password) {
|
if (!user.password_sha && body.password) {
|
||||||
// create password_sha on server
|
// create password_sha on server
|
||||||
user.salt = crypto.randomBytes(30).toString('hex');
|
user.salt = crypto.randomBytes(30).toString('hex');
|
||||||
|
|||||||
@@ -15,17 +15,17 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var userService = require('../../../services/user');
|
const userService = require('../../../services/user');
|
||||||
|
|
||||||
// GET /-/user/org.couchdb.user::name
|
// GET /-/user/org.couchdb.user::name
|
||||||
module.exports = function* show(next) {
|
module.exports = function* show(next) {
|
||||||
var name = this.params.name;
|
const name = this.params.name;
|
||||||
var user = yield* userService.getAndSave(name);
|
const user = yield userService.getAndSave(name);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = user.json;
|
let data = user.json;
|
||||||
if (!data) {
|
if (!data) {
|
||||||
data = {
|
data = {
|
||||||
_id: 'org.couchdb.user:' + user.name,
|
_id: 'org.couchdb.user:' + user.name,
|
||||||
@@ -53,7 +53,7 @@ module.exports = function* show(next) {
|
|||||||
fullname: data.name || data.login,
|
fullname: data.name || data.login,
|
||||||
homepage: data.html_url,
|
homepage: data.html_url,
|
||||||
scopes: data.scopes,
|
scopes: data.scopes,
|
||||||
site_admin: data.site_admin
|
site_admin: data.site_admin,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,9 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var debug = require('debug')('cnpmjs.org:controllers:registry:user:update');
|
const debug = require('debug')('cnpmjs.org:controllers:registry:user:update');
|
||||||
var ensurePasswordSalt = require('./common').ensurePasswordSalt;
|
const ensurePasswordSalt = require('./common').ensurePasswordSalt;
|
||||||
var userService = require('../../../services/user');
|
const userService = require('../../../services/user');
|
||||||
|
|
||||||
// logined before update, no need to auth user again
|
// logined before update, no need to auth user again
|
||||||
// { name: 'admin',
|
// { name: 'admin',
|
||||||
@@ -37,10 +37,10 @@ var userService = require('../../../services/user');
|
|||||||
// admin: true,
|
// admin: true,
|
||||||
// scopes: [ '@cnpm', '@cnpmtest' ] } }
|
// scopes: [ '@cnpm', '@cnpmtest' ] } }
|
||||||
module.exports = function* updateUser(next) {
|
module.exports = function* updateUser(next) {
|
||||||
var name = this.params.name;
|
const name = this.params.name;
|
||||||
var rev = this.params.rev;
|
const rev = this.params.rev;
|
||||||
if (!name || !rev) {
|
if (!name || !rev) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
debug('update: %s, rev: %s, user.name: %s', name, rev, this.user.name);
|
debug('update: %s, rev: %s, user.name: %s', name, rev, this.user.name);
|
||||||
|
|
||||||
@@ -49,13 +49,13 @@ module.exports = function* updateUser(next) {
|
|||||||
this.status = 401;
|
this.status = 401;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'unauthorized',
|
error: 'unauthorized',
|
||||||
reason: 'Name is incorrect.'
|
reason: 'Name is incorrect.',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var body = this.request.body || {};
|
const body = this.request.body || {};
|
||||||
var user = {
|
const user = {
|
||||||
name: body.name,
|
name: body.name,
|
||||||
// salt: body.salt,
|
// salt: body.salt,
|
||||||
// password_sha: body.password_sha,
|
// password_sha: body.password_sha,
|
||||||
@@ -73,17 +73,17 @@ module.exports = function* updateUser(next) {
|
|||||||
this.status = 422;
|
this.status = 422;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'paramError',
|
error: 'paramError',
|
||||||
reason: 'params missing, name, email or password missing.'
|
reason: 'params missing, name, email or password missing.',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = yield* userService.update(user);
|
const result = yield userService.update(user);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
this.status = 409;
|
this.status = 409;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'conflict',
|
error: 'conflict',
|
||||||
reason: 'Document update conflict.'
|
reason: 'Document update conflict.',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -92,6 +92,6 @@ module.exports = function* updateUser(next) {
|
|||||||
this.body = {
|
this.body = {
|
||||||
ok: true,
|
ok: true,
|
||||||
id: 'org.couchdb.user:' + user.name,
|
id: 'org.couchdb.user:' + user.name,
|
||||||
rev: result.rev
|
rev: result.rev,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,35 +14,35 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var packageService = require('../../services/package');
|
const packageService = require('../../services/package');
|
||||||
|
|
||||||
// GET /-/by-user/:user
|
// GET /-/by-user/:user
|
||||||
exports.list = function* () {
|
exports.list = function* () {
|
||||||
var users = this.params.user.split('|');
|
const users = this.params.user.split('|');
|
||||||
if (users.length > 20) {
|
if (users.length > 20) {
|
||||||
this.status = 400;
|
this.status = 400;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'bad_request',
|
error: 'bad_request',
|
||||||
reason: 'reach max user names limit, must <= 20 user names'
|
reason: 'reach max user names limit, must <= 20 user names',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var firstUser = users[0];
|
const firstUser = users[0];
|
||||||
if (!firstUser) {
|
if (!firstUser) {
|
||||||
// params.user = '|'
|
// params.user = '|'
|
||||||
this.body = {};
|
this.body = {};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tasks = {};
|
const tasks = {};
|
||||||
for (var i = 0; i < users.length; i++) {
|
for (let i = 0; i < users.length; i++) {
|
||||||
var username = users[i];
|
const username = users[i];
|
||||||
tasks[username] = packageService.listPublicModuleNamesByUser(username);
|
tasks[username] = packageService.listPublicModuleNamesByUser(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = yield tasks;
|
const data = yield tasks;
|
||||||
for (var k in data) {
|
for (const k in data) {
|
||||||
if (data[k].length === 0) {
|
if (data[k].length === 0) {
|
||||||
data[k] = undefined;
|
data[k] = undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,53 +14,67 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var debug = require('debug')('cnpmjs.org:controllers:sync');
|
const debug = require('debug')('cnpmjs.org:controllers:sync');
|
||||||
var Log = require('../services/module_log');
|
const Log = require('../services/module_log');
|
||||||
var SyncModuleWorker = require('./sync_module_worker');
|
const SyncModuleWorker = require('./sync_module_worker');
|
||||||
var config = require('../config');
|
const config = require('../config');
|
||||||
|
|
||||||
exports.sync = function* () {
|
exports.sync = function* () {
|
||||||
var username = this.user.name || 'anonymous';
|
const username = this.user.name || 'anonymous';
|
||||||
var name = this.params.name;
|
let name = this.params.name || this.params[0];
|
||||||
var publish = this.query.publish === 'true';
|
let type = 'package';
|
||||||
var noDep = this.query.nodeps === 'true';
|
if (name.indexOf(':') > 0) {
|
||||||
|
// user:fengmk2
|
||||||
|
// package:pedding
|
||||||
|
const splits = name.split(':');
|
||||||
|
type = splits[0];
|
||||||
|
name = splits[1];
|
||||||
|
}
|
||||||
|
const publish = this.query.publish === 'true';
|
||||||
|
const noDep = this.query.nodeps === 'true';
|
||||||
debug('sync %s with query: %j', name, this.query);
|
debug('sync %s with query: %j', name, this.query);
|
||||||
if (publish && !this.user.isAdmin) {
|
if (type === 'package' && publish && !this.user.isAdmin) {
|
||||||
this.status = 403;
|
this.status = 403;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'no_perms',
|
error: 'no_perms',
|
||||||
reason: 'Only admin can publish'
|
reason: 'Only admin can publish',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var options = {
|
const options = {
|
||||||
publish: publish,
|
type,
|
||||||
noDep: noDep,
|
publish,
|
||||||
|
noDep,
|
||||||
syncUpstreamFirst: config.sourceNpmRegistryIsCNpm,
|
syncUpstreamFirst: config.sourceNpmRegistryIsCNpm,
|
||||||
};
|
};
|
||||||
|
|
||||||
var logId = yield* SyncModuleWorker.sync(name, username, options);
|
const logId = yield SyncModuleWorker.sync(name, username, options);
|
||||||
debug('sync %s got log id %j', name, logId);
|
debug('sync %s got log id %j', name, logId);
|
||||||
|
|
||||||
this.status = 201;
|
this.status = 201;
|
||||||
this.body = {
|
this.body = {
|
||||||
ok: true,
|
ok: true,
|
||||||
logId: logId
|
logId,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getSyncLog = function* (next) {
|
exports.getSyncLog = function* (next) {
|
||||||
var logId = this.params.id;
|
const logId = Number(this.params.id || this.params[1]);
|
||||||
var offset = Number(this.query.offset) || 0;
|
const offset = Number(this.query.offset) || 0;
|
||||||
var row = yield* Log.get(logId);
|
|
||||||
|
if (!logId) { // NaN
|
||||||
|
this.status = 404;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const row = yield Log.get(logId);
|
||||||
if (!row) {
|
if (!row) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
|
|
||||||
var log = row.log.trim();
|
let log = row.log.trim();
|
||||||
if (offset > 0) {
|
if (offset > 0) {
|
||||||
log = log.split('\n').slice(offset).join('\n');
|
log = log.split('\n').slice(offset).join('\n');
|
||||||
}
|
}
|
||||||
this.body = {ok: true, log: log};
|
this.body = { ok: true, log };
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,31 +1,23 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - controllers/total.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const Total = require('../services/total');
|
||||||
* Module dependencies.
|
const version = require('../package.json').version;
|
||||||
*/
|
const config = require('../config');
|
||||||
|
const getDownloadTotal = require('./utils').getDownloadTotal;
|
||||||
|
|
||||||
var Total = require('../services/total');
|
const startTime = '' + Date.now();
|
||||||
var version = require('../package.json').version;
|
let cache = null;
|
||||||
var config = require('../config');
|
|
||||||
var getDownloadTotal = require('./utils').getDownloadTotal;
|
|
||||||
|
|
||||||
var startTime = '' + Date.now();
|
|
||||||
|
|
||||||
module.exports = function* showTotal() {
|
module.exports = function* showTotal() {
|
||||||
var r = yield [Total.get(), getDownloadTotal()];
|
if (cache && Date.now() - cache.cache_time < 10000) {
|
||||||
var total = r[0];
|
// cache 10 seconds
|
||||||
var download = r[1];
|
this.body = cache;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const r = yield [ Total.get(), getDownloadTotal() ];
|
||||||
|
const total = r[0];
|
||||||
|
const download = r[1];
|
||||||
|
|
||||||
total.download = download;
|
total.download = download;
|
||||||
total.db_name = 'registry';
|
total.db_name = 'registry';
|
||||||
@@ -35,5 +27,8 @@ module.exports = function* showTotal() {
|
|||||||
total.donate = 'https://www.gittip.com/fengmk2';
|
total.donate = 'https://www.gittip.com/fengmk2';
|
||||||
total.sync_model = config.syncModel;
|
total.sync_model = config.syncModel;
|
||||||
|
|
||||||
|
cache = total;
|
||||||
|
total.cache_time = Date.now();
|
||||||
|
|
||||||
this.body = total;
|
this.body = total;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,20 +14,25 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var debug = require('debug')('cnpmjs.org:controllers:utils');
|
const debug = require('debug')('cnpmjs.org:controllers:utils');
|
||||||
var path = require('path');
|
const path = require('path');
|
||||||
var fs = require('fs');
|
const fs = require('fs');
|
||||||
var utility = require('utility');
|
const utility = require('utility');
|
||||||
var ms = require('humanize-ms');
|
const ms = require('humanize-ms');
|
||||||
var moment = require('moment');
|
const moment = require('moment');
|
||||||
var downloadTotalService = require('../services/download_total');
|
const downloadTotalService = require('../services/download_total');
|
||||||
var nfs = require('../common/nfs');
|
const nfs = require('../common/nfs');
|
||||||
var config = require('../config');
|
const config = require('../config');
|
||||||
|
|
||||||
var DOWNLOAD_TIMEOUT = ms('10m');
|
const DOWNLOAD_TIMEOUT = ms('10m');
|
||||||
|
|
||||||
exports.downloadAsReadStream = function* (key) {
|
exports.downloadAsReadStream = function* (key) {
|
||||||
var tmpPath = path.join(config.uploadDir,
|
const options = { timeout: DOWNLOAD_TIMEOUT };
|
||||||
|
if (nfs.createDownloadStream) {
|
||||||
|
return yield nfs.createDownloadStream(key, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
const tmpPath = path.join(config.uploadDir,
|
||||||
utility.randomString() + key.replace(/\//g, '-'));
|
utility.randomString() + key.replace(/\//g, '-'));
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
debug('cleanup %s', tmpPath);
|
debug('cleanup %s', tmpPath);
|
||||||
@@ -35,38 +40,38 @@ exports.downloadAsReadStream = function* (key) {
|
|||||||
}
|
}
|
||||||
debug('downloadAsReadStream() %s to %s', key, tmpPath);
|
debug('downloadAsReadStream() %s to %s', key, tmpPath);
|
||||||
try {
|
try {
|
||||||
yield nfs.download(key, tmpPath, {timeout: DOWNLOAD_TIMEOUT});
|
yield nfs.download(key, tmpPath, options);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
debug('downloadAsReadStream() %s to %s error: %s', key, tmpPath, err.stack);
|
debug('downloadAsReadStream() %s to %s error: %s', key, tmpPath, err.stack);
|
||||||
cleanup();
|
cleanup();
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
var tarball = fs.createReadStream(tmpPath);
|
const tarball = fs.createReadStream(tmpPath);
|
||||||
tarball.once('error', cleanup);
|
tarball.once('error', cleanup);
|
||||||
tarball.once('end', cleanup);
|
tarball.once('end', cleanup);
|
||||||
return tarball;
|
return tarball;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getDownloadTotal = function* (name) {
|
exports.getDownloadTotal = function* (name) {
|
||||||
var end = moment();
|
let end = moment();
|
||||||
var start = end.clone().subtract(1, 'months').startOf('month');
|
let start = end.clone().subtract(1, 'months').startOf('month');
|
||||||
var lastday = end.clone().subtract(1, 'days').format('YYYY-MM-DD');
|
const lastday = end.clone().subtract(1, 'days').format('YYYY-MM-DD');
|
||||||
var lastweekStart = end.clone().subtract(1, 'weeks').startOf('week');
|
let lastweekStart = end.clone().subtract(1, 'weeks').startOf('isoweek');
|
||||||
var lastweekEnd = lastweekStart.clone().endOf('week').format('YYYY-MM-DD');
|
const lastweekEnd = lastweekStart.clone().endOf('isoweek').format('YYYY-MM-DD');
|
||||||
var lastmonthEnd = start.clone().endOf('month').format('YYYY-MM-DD');
|
const lastmonthEnd = start.clone().endOf('month').format('YYYY-MM-DD');
|
||||||
var thismonthStart = end.clone().startOf('month').format('YYYY-MM-DD');
|
const thismonthStart = end.clone().startOf('month').format('YYYY-MM-DD');
|
||||||
var thisweekStart = end.clone().startOf('week').format('YYYY-MM-DD');
|
const thisweekStart = end.clone().startOf('isoweek').format('YYYY-MM-DD');
|
||||||
start = start.format('YYYY-MM-DD');
|
start = start.format('YYYY-MM-DD');
|
||||||
end = end.format('YYYY-MM-DD');
|
end = end.format('YYYY-MM-DD');
|
||||||
lastweekStart = lastweekStart.format('YYYY-MM-DD');
|
lastweekStart = lastweekStart.format('YYYY-MM-DD');
|
||||||
var method = name ? 'getModuleTotal' : 'getTotal';
|
const method = name ? 'getModuleTotal' : 'getTotal';
|
||||||
var args = [start, end];
|
const args = [ start, end ];
|
||||||
if (name) {
|
if (name) {
|
||||||
args.unshift(name);
|
args.unshift(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
var rows = yield* downloadTotalService[method].apply(downloadTotalService, args);
|
const rows = yield downloadTotalService[method].apply(downloadTotalService, args);
|
||||||
var download = {
|
const download = {
|
||||||
today: 0,
|
today: 0,
|
||||||
thisweek: 0,
|
thisweek: 0,
|
||||||
thismonth: 0,
|
thismonth: 0,
|
||||||
@@ -75,8 +80,8 @@ exports.getDownloadTotal = function* (name) {
|
|||||||
lastmonth: 0,
|
lastmonth: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (var i = 0; i < rows.length; i++) {
|
for (let i = 0; i < rows.length; i++) {
|
||||||
var r = rows[i];
|
const r = rows[i];
|
||||||
if (r.date === end) {
|
if (r.date === end) {
|
||||||
download.today += r.count;
|
download.today += r.count;
|
||||||
}
|
}
|
||||||
@@ -100,11 +105,11 @@ exports.getDownloadTotal = function* (name) {
|
|||||||
return download;
|
return download;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.setLicense = function (pkg) {
|
exports.setLicense = function(pkg) {
|
||||||
var license;
|
let license;
|
||||||
license = pkg.license || pkg.licenses || pkg.licence || pkg.licences;
|
license = pkg.license || pkg.licenses || pkg.licence || pkg.licences;
|
||||||
if (!license) {
|
if (!license) {
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(license)) {
|
if (Array.isArray(license)) {
|
||||||
@@ -114,7 +119,7 @@ exports.setLicense = function (pkg) {
|
|||||||
if (typeof license === 'object') {
|
if (typeof license === 'object') {
|
||||||
pkg.license = {
|
pkg.license = {
|
||||||
name: license.name || license.type,
|
name: license.name || license.type,
|
||||||
url: license.url
|
url: license.url,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,38 +127,38 @@ exports.setLicense = function (pkg) {
|
|||||||
if (license.match(/(http|https)(:\/\/)/ig)) {
|
if (license.match(/(http|https)(:\/\/)/ig)) {
|
||||||
pkg.license = {
|
pkg.license = {
|
||||||
name: license,
|
name: license,
|
||||||
url: license
|
url: license,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
pkg.license = {
|
pkg.license = {
|
||||||
url: exports.getOssLicenseUrlFromName(license),
|
url: exports.getOssLicenseUrlFromName(license),
|
||||||
name: license
|
name: license,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getOssLicenseUrlFromName = function (name) {
|
exports.getOssLicenseUrlFromName = function(name) {
|
||||||
var base = 'http://opensource.org/licenses/';
|
const base = 'http://opensource.org/licenses/';
|
||||||
|
|
||||||
var licenseMap = {
|
const licenseMap = {
|
||||||
'bsd': 'BSD-2-Clause',
|
bsd: 'BSD-2-Clause',
|
||||||
'mit': 'MIT',
|
mit: 'MIT',
|
||||||
'x11': 'MIT',
|
x11: 'MIT',
|
||||||
'mit/x11': 'MIT',
|
'mit/x11': 'MIT',
|
||||||
'apache 2.0': 'Apache-2.0',
|
'apache 2.0': 'Apache-2.0',
|
||||||
'apache2': 'Apache-2.0',
|
apache2: 'Apache-2.0',
|
||||||
'apache 2': 'Apache-2.0',
|
'apache 2': 'Apache-2.0',
|
||||||
'apache-2': 'Apache-2.0',
|
'apache-2': 'Apache-2.0',
|
||||||
'apache': 'Apache-2.0',
|
apache: 'Apache-2.0',
|
||||||
'gpl': 'GPL-3.0',
|
gpl: 'GPL-3.0',
|
||||||
'gplv3': 'GPL-3.0',
|
gplv3: 'GPL-3.0',
|
||||||
'gplv2': 'GPL-2.0',
|
gplv2: 'GPL-2.0',
|
||||||
'gpl3': 'GPL-3.0',
|
gpl3: 'GPL-3.0',
|
||||||
'gpl2': 'GPL-2.0',
|
gpl2: 'GPL-2.0',
|
||||||
'lgpl': 'LGPL-2.1',
|
lgpl: 'LGPL-2.1',
|
||||||
'lgplv2.1': 'LGPL-2.1',
|
'lgplv2.1': 'LGPL-2.1',
|
||||||
'lgplv2': 'LGPL-2.1'
|
lgplv2: 'LGPL-2.1',
|
||||||
};
|
};
|
||||||
|
|
||||||
return licenseMap[name.toLowerCase()] ?
|
return licenseMap[name.toLowerCase()] ?
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* MIT Licensed
|
* MIT Licensed
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
@@ -14,17 +14,18 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var utility = require('utility');
|
const utility = require('utility');
|
||||||
var util = require('util');
|
const util = require('util');
|
||||||
var config = require('../../config');
|
const config = require('../../config');
|
||||||
var packageService = require('../../services/package');
|
const packageService = require('../../services/package');
|
||||||
|
const DownloadTotal = require('../../services/download_total');
|
||||||
|
|
||||||
exports.version = function* () {
|
exports.version = function* () {
|
||||||
var color = 'lightgrey';
|
let color = 'lightgrey';
|
||||||
var version = 'invalid';
|
let version = 'invalid';
|
||||||
var name = this.params[0];
|
const name = this.params[0];
|
||||||
var tag = this.query.tag || 'latest';
|
const tag = this.query.tag || 'latest';
|
||||||
var info = yield* packageService.getModuleByTag(name, tag);
|
const info = yield packageService.getModuleByTag(name, tag);
|
||||||
if (info) {
|
if (info) {
|
||||||
version = info.version;
|
version = info.version;
|
||||||
if (/^0\.0\./.test(version)) {
|
if (/^0\.0\./.test(version)) {
|
||||||
@@ -39,10 +40,23 @@ exports.version = function* () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var subject = config.badgeSubject.replace(/\-/g, '--');
|
let subject = config.badgeSubject.replace(/\-/g, '--');
|
||||||
|
if (this.query.subject) {
|
||||||
|
subject = this.query.subject.replace(/\-/g, '--');
|
||||||
|
}
|
||||||
version = version.replace(/\-/g, '--');
|
version = version.replace(/\-/g, '--');
|
||||||
var style = this.query.style || 'flat-square';
|
const style = this.query.style || 'flat-square';
|
||||||
var url = util.format('https://img.shields.io/badge/%s-%s-%s.svg?style=%s',
|
const url = util.format(config.badgePrefixURL + '/%s-%s-%s.svg?style=%s',
|
||||||
subject, version, color, utility.encodeURIComponent(style));
|
utility.encodeURIComponent(subject), version, color, utility.encodeURIComponent(style));
|
||||||
|
this.redirect(url);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.downloads = function* () {
|
||||||
|
// https://dn-img-shields-io.qbox.me/badge/downloads-100k/month-brightgreen.svg?style=flat-square
|
||||||
|
const name = this.params[0];
|
||||||
|
const count = yield DownloadTotal.getTotalByName(name);
|
||||||
|
const style = this.query.style || 'flat-square';
|
||||||
|
const url = util.format(config.badgePrefixURL + '/downloads-%s-brightgreen.svg?style=%s',
|
||||||
|
count, utility.encodeURIComponent(style));
|
||||||
this.redirect(url);
|
this.redirect(url);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,100 +0,0 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - controllers/web/dist.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var debug = require('debug')('cnpmjs.org:controllers:web:dist');
|
|
||||||
var mime = require('mime');
|
|
||||||
var urlparse = require('url').parse;
|
|
||||||
var distService = require('../../services/dist');
|
|
||||||
var config = require('../../config');
|
|
||||||
var downloadAsReadStream = require('../utils').downloadAsReadStream;
|
|
||||||
|
|
||||||
function padding(max, current, pad) {
|
|
||||||
pad = pad || ' ';
|
|
||||||
var left = max - current;
|
|
||||||
var str = '';
|
|
||||||
for (var i = 0; i < left; i++) {
|
|
||||||
str += pad;
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.list = function* (next) {
|
|
||||||
var params = this.params;
|
|
||||||
var url = params[0];
|
|
||||||
if (!url) {
|
|
||||||
// GET /dist => /dist/
|
|
||||||
return this.redirect('/dist/');
|
|
||||||
}
|
|
||||||
|
|
||||||
var isDir = url[url.length - 1] === '/';
|
|
||||||
if (!isDir) {
|
|
||||||
return yield* download.call(this, next);
|
|
||||||
}
|
|
||||||
|
|
||||||
var items = yield* distService.listdir(url);
|
|
||||||
if (url === '/') {
|
|
||||||
// phantomjs/
|
|
||||||
items.push({
|
|
||||||
name: 'phantomjs/',
|
|
||||||
date: '',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
yield this.render('dist', {
|
|
||||||
title: 'Mirror index of ' + config.disturl + url,
|
|
||||||
disturl: config.disturl,
|
|
||||||
dirname: url,
|
|
||||||
items: items,
|
|
||||||
padding: padding
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function* download(next) {
|
|
||||||
var fullname = this.params[0];
|
|
||||||
var info = yield* distService.getfile(fullname);
|
|
||||||
debug('download %s got %j', fullname, info);
|
|
||||||
if (!info || !info.url) {
|
|
||||||
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' && info.size > 0) {
|
|
||||||
this.length = info.size;
|
|
||||||
}
|
|
||||||
this.type = mime.lookup(info.url);
|
|
||||||
if (attachment) {
|
|
||||||
this.attachment(info.name);
|
|
||||||
}
|
|
||||||
if (info.sha1) {
|
|
||||||
this.etag = info.sha1;
|
|
||||||
}
|
|
||||||
this.body = yield* downloadAsReadStream(info.url);
|
|
||||||
}
|
|
||||||
@@ -15,13 +15,13 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var packageService = require('../../../services/package');
|
const packageService = require('../../../services/package');
|
||||||
var config = require('../../../config');
|
const config = require('../../../config');
|
||||||
|
|
||||||
module.exports = function* listPrivates() {
|
module.exports = function* listPrivates() {
|
||||||
var tasks = {};
|
const tasks = {};
|
||||||
for (var i = 0; i < config.scopes.length; i++) {
|
for (let i = 0; i < config.scopes.length; i++) {
|
||||||
var scope = config.scopes[i];
|
const scope = config.scopes[i];
|
||||||
tasks[scope] = packageService.listPrivateModulesByScope(scope);
|
tasks[scope] = packageService.listPrivateModulesByScope(scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,9 +29,9 @@ module.exports = function* listPrivates() {
|
|||||||
tasks['no scoped'] = packageService.listModules(config.privatePackages);
|
tasks['no scoped'] = packageService.listModules(config.privatePackages);
|
||||||
}
|
}
|
||||||
|
|
||||||
var scopes = yield tasks;
|
const scopes = yield tasks;
|
||||||
yield this.render('private', {
|
yield this.render('private', {
|
||||||
title: 'private packages',
|
title: 'private packages',
|
||||||
scopes: scopes
|
scopes,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
@@ -15,18 +15,26 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var debug = require('debug')('cnpmjs.org:controllers:web:package:search');
|
const debug = require('debug')('cnpmjs.org:controllers:web:package:search');
|
||||||
var packageService = require('../../../services/package');
|
const packageService = require('../../../services/package');
|
||||||
|
|
||||||
module.exports = function* search() {
|
module.exports = function* search() {
|
||||||
var params = this.params;
|
const params = this.params;
|
||||||
var word = params.word || params[0];
|
const word = params.word || params[0];
|
||||||
debug('search %j', word);
|
let limit = Number(this.query.limit) || 100;
|
||||||
var result = yield* packageService.search(word);
|
|
||||||
|
|
||||||
var match = null;
|
if (limit > 10000) {
|
||||||
for (var i = 0; i < result.searchMatchs.length; i++) {
|
limit = 10000;
|
||||||
var p = result.searchMatchs[i];
|
}
|
||||||
|
|
||||||
|
debug('search %j', word);
|
||||||
|
const result = yield packageService.search(word, {
|
||||||
|
limit,
|
||||||
|
});
|
||||||
|
|
||||||
|
let match = null;
|
||||||
|
for (let i = 0; i < result.searchMatchs.length; i++) {
|
||||||
|
const p = result.searchMatchs[i];
|
||||||
if (p.name === word) {
|
if (p.name === word) {
|
||||||
match = p;
|
match = p;
|
||||||
break;
|
break;
|
||||||
@@ -35,19 +43,18 @@ module.exports = function* search() {
|
|||||||
|
|
||||||
// return a json result
|
// return a json result
|
||||||
if (this.query && this.query.type === 'json') {
|
if (this.query && this.query.type === 'json') {
|
||||||
this.body = {
|
this.jsonp = {
|
||||||
keyword: word,
|
keyword: word,
|
||||||
match: match,
|
match,
|
||||||
packages: result.searchMatchs,
|
packages: result.searchMatchs,
|
||||||
keywords: result.keywordMatchs,
|
keywords: result.keywordMatchs,
|
||||||
};
|
};
|
||||||
this.type = 'application/json; charset=utf-8';
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
yield this.render('search', {
|
yield this.render('search', {
|
||||||
title: 'Keyword - ' + word,
|
title: 'Keyword - ' + word,
|
||||||
keyword: word,
|
keyword: word,
|
||||||
match: match,
|
match,
|
||||||
packages: result.searchMatchs,
|
packages: result.searchMatchs,
|
||||||
keywords: result.keywordMatchs,
|
keywords: result.keywordMatchs,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,35 +15,35 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var packageService = require('../../../services/package');
|
const packageService = require('../../../services/package');
|
||||||
|
|
||||||
module.exports = function* searchRange() {
|
module.exports = function* searchRange() {
|
||||||
var startKey = this.query.startkey || '';
|
let startKey = this.query.startkey || '';
|
||||||
if (startKey[0] === '"') {
|
if (startKey[0] === '"') {
|
||||||
startKey = startKey.substring(1);
|
startKey = startKey.substring(1);
|
||||||
}
|
}
|
||||||
if (startKey[startKey.length - 1] === '"') {
|
if (startKey[startKey.length - 1] === '"') {
|
||||||
startKey = startKey.substring(0, startKey.length - 1);
|
startKey = startKey.substring(0, startKey.length - 1);
|
||||||
}
|
}
|
||||||
var limit = Number(this.query.limit) || 20;
|
const limit = Number(this.query.limit) || 20;
|
||||||
var result = yield* packageService.search(startKey, {limit: limit});
|
const result = yield packageService.search(startKey, { limit });
|
||||||
|
|
||||||
var packages = result.searchMatchs.concat(result.keywordMatchs);
|
const packages = result.searchMatchs.concat(result.keywordMatchs);
|
||||||
|
|
||||||
var rows = [];
|
const rows = [];
|
||||||
for (var i = 0; i < packages.length; i++) {
|
for (let i = 0; i < packages.length; i++) {
|
||||||
var p = packages[i];
|
const p = packages[i];
|
||||||
var row = {
|
const row = {
|
||||||
key: p.name,
|
key: p.name,
|
||||||
count: 1,
|
count: 1,
|
||||||
value: {
|
value: {
|
||||||
name: p.name,
|
name: p.name,
|
||||||
description: p.description,
|
description: p.description,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
rows.push(row);
|
rows.push(row);
|
||||||
}
|
}
|
||||||
this.body = {
|
this.body = {
|
||||||
rows: rows
|
rows,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,96 +1,87 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - controllers/web/package/show.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const debug = require('debug')('cnpmjs.org:controllers:web:package:show');
|
||||||
* Module dependencies.
|
const bytes = require('bytes');
|
||||||
*/
|
const giturl = require('giturl');
|
||||||
|
const moment = require('moment');
|
||||||
var debug = require('debug')('cnpmjs.org:controllers:web:package:show');
|
const semver = require('semver');
|
||||||
var bytes = require('bytes');
|
const gravatar = require('gravatar');
|
||||||
var giturl = require('giturl');
|
const humanize = require('humanize-number');
|
||||||
var moment = require('moment');
|
const config = require('../../../config');
|
||||||
var semver = require('semver');
|
const utils = require('../../utils');
|
||||||
var marked = require('marked');
|
const setDownloadURL = require('../../../lib/common').setDownloadURL;
|
||||||
var gravatar = require('gravatar');
|
const renderMarkdown = require('../../../common/markdown').render;
|
||||||
var humanize = require('humanize-number');
|
const packageService = require('../../../services/package');
|
||||||
var config = require('../../../config');
|
|
||||||
var utils = require('../../utils');
|
|
||||||
var setDownloadURL = require('../../../lib/common').setDownloadURL;
|
|
||||||
var packageService = require('../../../services/package');
|
|
||||||
|
|
||||||
module.exports = function* show(next) {
|
module.exports = function* show(next) {
|
||||||
var params = this.params;
|
const params = this.params;
|
||||||
// normal: {name: $name, version: $version}
|
// normal: {name: $name, version: $version}
|
||||||
// scope: [$name, $version]
|
// scope: [$name, $version]
|
||||||
var orginalName = params.name || params[0];
|
const orginalName = params.name || params[0];
|
||||||
var name = orginalName;
|
const name = orginalName;
|
||||||
var tag = params.version || params[1];
|
const tag = params.version || params[1];
|
||||||
debug('display %s with %j', name, params);
|
debug('display %s with %j', name, params);
|
||||||
|
|
||||||
var getPackageMethod;
|
let getPackageMethod;
|
||||||
var getPackageArgs;
|
let getPackageArgs;
|
||||||
var version = semver.valid(tag || '');
|
const version = semver.valid(tag || '');
|
||||||
if (version) {
|
if (version) {
|
||||||
getPackageMethod = 'getModule';
|
getPackageMethod = 'getModule';
|
||||||
getPackageArgs = [name, version];
|
getPackageArgs = [ name, version ];
|
||||||
} else {
|
} else {
|
||||||
getPackageMethod = 'getModuleByTag';
|
getPackageMethod = 'getModuleByTag';
|
||||||
getPackageArgs = [name, tag || 'latest'];
|
getPackageArgs = [ name, tag || 'latest' ];
|
||||||
}
|
}
|
||||||
|
|
||||||
var pkg = yield packageService[getPackageMethod].apply(packageService, getPackageArgs);
|
let pkg = yield packageService[getPackageMethod].apply(packageService, getPackageArgs);
|
||||||
if (!pkg || !pkg.package) {
|
if (!pkg || !pkg.package) {
|
||||||
// check if unpublished
|
// check if unpublished
|
||||||
var unpublishedInfo = yield* packageService.getUnpublishedModule(name);
|
const unpublishedInfo = yield packageService.getUnpublishedModule(name);
|
||||||
debug('show unpublished %j', unpublishedInfo);
|
debug('show unpublished %j', unpublishedInfo);
|
||||||
if (unpublishedInfo) {
|
if (unpublishedInfo) {
|
||||||
var data = {
|
const data = {
|
||||||
name: name,
|
name,
|
||||||
unpublished: unpublishedInfo.package
|
unpublished: unpublishedInfo.package,
|
||||||
};
|
};
|
||||||
data.unpublished.time = new Date(data.unpublished.time);
|
data.unpublished.time = new Date(data.unpublished.time);
|
||||||
if (data.unpublished.maintainers) {
|
if (data.unpublished.maintainers) {
|
||||||
for (var i = 0; i < data.unpublished.maintainers.length; i++) {
|
for (let i = 0; i < data.unpublished.maintainers.length; i++) {
|
||||||
var maintainer = data.unpublished.maintainers[i];
|
const maintainer = data.unpublished.maintainers[i];
|
||||||
if (maintainer.email) {
|
if (maintainer.email) {
|
||||||
maintainer.gravatar = gravatar.url(maintainer.email, {s: '50', d: 'retro'}, true);
|
maintainer.gravatar = gravatar.url(maintainer.email, { s: '50', d: 'retro' }, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
yield this.render('package_unpublished', {
|
yield this.render('package_unpublished', {
|
||||||
package: data
|
package: data,
|
||||||
|
title: 'Package - ' + name,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
|
|
||||||
var r = yield [
|
const r = yield [
|
||||||
utils.getDownloadTotal(name),
|
utils.getDownloadTotal(name),
|
||||||
packageService.listDependents(name),
|
packageService.listDependents(name),
|
||||||
packageService.listStarUserNames(name),
|
packageService.listStarUserNames(name),
|
||||||
packageService.listMaintainers(name)
|
packageService.listMaintainers(name),
|
||||||
];
|
];
|
||||||
var download = r[0];
|
const download = r[0];
|
||||||
var dependents = r[1];
|
const dependents = r[1];
|
||||||
var users = r[2];
|
const users = r[2];
|
||||||
var maintainers = r[3];
|
const maintainers = r[3];
|
||||||
|
|
||||||
pkg.package.fromNow = moment(pkg.publish_time).fromNow();
|
pkg.package.fromNow = moment(pkg.publish_time).fromNow();
|
||||||
pkg = pkg.package;
|
pkg = pkg.package;
|
||||||
pkg.users = users;
|
pkg.users = users;
|
||||||
pkg.readme = marked(pkg.readme || '');
|
if (pkg.readme && typeof pkg.readme !== 'string') {
|
||||||
|
pkg.readme = 'readme is not string: ' + JSON.stringify(pkg.readme);
|
||||||
|
} else {
|
||||||
|
pkg.readme = renderMarkdown(pkg.readme || '');
|
||||||
|
}
|
||||||
|
|
||||||
if (!pkg.readme) {
|
if (!pkg.readme) {
|
||||||
pkg.readme = pkg.description || '';
|
pkg.readme = pkg.description || '';
|
||||||
}
|
}
|
||||||
@@ -100,10 +91,10 @@ module.exports = function* show(next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pkg.maintainers) {
|
if (pkg.maintainers) {
|
||||||
for (var i = 0; i < pkg.maintainers.length; i++) {
|
for (let i = 0; i < pkg.maintainers.length; i++) {
|
||||||
var maintainer = pkg.maintainers[i];
|
const maintainer = pkg.maintainers[i];
|
||||||
if (maintainer.email) {
|
if (maintainer.email) {
|
||||||
maintainer.gravatar = gravatar.url(maintainer.email, {s: '50', d: 'retro'}, true);
|
maintainer.gravatar = gravatar.url(maintainer.email, { s: '50', d: 'retro' }, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,23 +102,7 @@ module.exports = function* show(next) {
|
|||||||
if (pkg._npmUser) {
|
if (pkg._npmUser) {
|
||||||
pkg.lastPublishedUser = pkg._npmUser;
|
pkg.lastPublishedUser = pkg._npmUser;
|
||||||
if (pkg.lastPublishedUser.email) {
|
if (pkg.lastPublishedUser.email) {
|
||||||
pkg.lastPublishedUser.gravatar = gravatar.url(pkg.lastPublishedUser.email, {s: '50', d: 'retro'}, true);
|
pkg.lastPublishedUser.gravatar = gravatar.url(pkg.lastPublishedUser.email, { s: '50', d: 'retro' }, true);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pkg.contributors) {
|
|
||||||
// registry.cnpmjs.org/compressible
|
|
||||||
if (!Array.isArray(pkg.contributors)) {
|
|
||||||
pkg.contributors = [pkg.contributors];
|
|
||||||
}
|
|
||||||
for (var i = 0; i < pkg.contributors.length; i++) {
|
|
||||||
var contributor = pkg.contributors[i];
|
|
||||||
if (contributor.email) {
|
|
||||||
contributor.gravatar = gravatar.url(contributor.email, {s: '50', d: 'retro'}, true);
|
|
||||||
}
|
|
||||||
if (config.packagePageContributorSearch || !contributor.url) {
|
|
||||||
contributor.url = '/~' + encodeURIComponent(contributor.name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +110,7 @@ module.exports = function* show(next) {
|
|||||||
pkg.repository = null;
|
pkg.repository = null;
|
||||||
}
|
}
|
||||||
if (pkg.repository && pkg.repository.url) {
|
if (pkg.repository && pkg.repository.url) {
|
||||||
pkg.repository.weburl = giturl.parse(pkg.repository.url) || pkg.repository.url;
|
pkg.repository.weburl = /^https?:\/\//.test(pkg.repository.url) ? pkg.repository.url : (giturl.parse(pkg.repository.url) || pkg.repository.url);
|
||||||
}
|
}
|
||||||
if (!pkg.bugs) {
|
if (!pkg.bugs) {
|
||||||
pkg.bugs = {};
|
pkg.bugs = {};
|
||||||
@@ -143,7 +118,7 @@ module.exports = function* show(next) {
|
|||||||
|
|
||||||
utils.setLicense(pkg);
|
utils.setLicense(pkg);
|
||||||
|
|
||||||
for (var k in download) {
|
for (const k in download) {
|
||||||
download[k] = humanize(download[k]);
|
download[k] = humanize(download[k]);
|
||||||
}
|
}
|
||||||
setDownloadURL(pkg, this, config.registryHost);
|
setDownloadURL(pkg, this, config.registryHost);
|
||||||
@@ -168,12 +143,12 @@ module.exports = function* show(next) {
|
|||||||
// "node3": ">= 0.6.9",
|
// "node3": ">= 0.6.9",
|
||||||
// };
|
// };
|
||||||
if (pkg.engines) {
|
if (pkg.engines) {
|
||||||
for (var k in pkg.engines) {
|
for (const k in pkg.engines) {
|
||||||
var engine = String(pkg.engines[k] || '').trim();
|
const engine = String(pkg.engines[k] || '').trim();
|
||||||
var color = 'blue';
|
let color = 'blue';
|
||||||
if (k.indexOf('node') === 0) {
|
if (k.indexOf('node') === 0) {
|
||||||
color = 'yellowgreen';
|
color = 'yellowgreen';
|
||||||
var version = /(\d+\.\d+\.\d+)/.exec(engine);
|
let version = /(\d+\.\d+\.\d+)/.exec(engine);
|
||||||
if (version) {
|
if (version) {
|
||||||
version = version[0];
|
version = version[0];
|
||||||
if (/^0\.11\.\d+/.test(version)) {
|
if (/^0\.11\.\d+/.test(version)) {
|
||||||
@@ -189,15 +164,26 @@ module.exports = function* show(next) {
|
|||||||
pkg.engines[k] = {
|
pkg.engines[k] = {
|
||||||
version: engine,
|
version: engine,
|
||||||
title: k + ': ' + engine,
|
title: k + ': ' + engine,
|
||||||
badgeURL: 'https://img.shields.io/badge/' + encodeURIComponent(k) +
|
badgeURL: config.badgePrefixURL + '/' + encodeURIComponent(k) +
|
||||||
'-' + encodeURIComponent(engine) + '-' + color + '.svg?style=flat-square',
|
'-' + encodeURIComponent(engine) + '-' + color + '.svg?style=flat-square',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pkg._publish_on_cnpm) {
|
||||||
|
pkg.isPrivate = true;
|
||||||
|
} else {
|
||||||
|
pkg.isPrivate = false;
|
||||||
|
// add security check badge
|
||||||
|
pkg.snyk = {
|
||||||
|
badge: `${config.snykUrl}/test/npm/${pkg.name}/badge.svg?style=flat-square`,
|
||||||
|
url: `${config.snykUrl}/test/npm/${pkg.name}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
yield this.render('package', {
|
yield this.render('package', {
|
||||||
title: 'Package - ' + pkg.name,
|
title: 'Package - ' + pkg.name,
|
||||||
package: pkg,
|
package: pkg,
|
||||||
download: download
|
download,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**!
|
/**!
|
||||||
* cnpmjs.org - controllers/web/package/show_sync.js
|
* cnpmjs.org - controllers/web/show_sync.js
|
||||||
*
|
*
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
* Copyright(c) cnpmjs.org and other contributors.
|
||||||
* MIT Licensed
|
* MIT Licensed
|
||||||
@@ -16,12 +16,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function* showSync() {
|
module.exports = function* showSync() {
|
||||||
var name = this.params.name || this.params[0] || this.query.name;
|
let name = this.params.name || this.params[0] || this.query.name;
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return this.redirect('/');
|
return this.redirect('/');
|
||||||
}
|
}
|
||||||
|
let type = 'package';
|
||||||
|
if (name.indexOf(':') > 0) {
|
||||||
|
const splits = name.split(':');
|
||||||
|
name = splits[1];
|
||||||
|
type = splits[0];
|
||||||
|
}
|
||||||
yield this.render('sync', {
|
yield this.render('sync', {
|
||||||
name: name,
|
type,
|
||||||
title: 'Sync - ' + name,
|
name,
|
||||||
|
title: 'Sync ' + type + ' - ' + name,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -1,49 +1,34 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - controllers/web/user/show.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const config = require('../../../config');
|
||||||
* Module dependencies.
|
const packageService = require('../../../services/package');
|
||||||
*/
|
const userService = require('../../../services/user');
|
||||||
|
const common = require('../../../lib/common');
|
||||||
var config = require('../../../config');
|
|
||||||
var packageService = require('../../../services/package');
|
|
||||||
var userService = require('../../../services/user');
|
|
||||||
var common = require('../../../lib/common');
|
|
||||||
|
|
||||||
module.exports = function* showUser(next) {
|
module.exports = function* showUser(next) {
|
||||||
var name = this.params.name;
|
const name = this.params.name;
|
||||||
var isAdmin = common.isAdmin(name);
|
const isAdmin = common.isAdmin(name);
|
||||||
var scopes = config.scopes || [];
|
const scopes = config.scopes || [];
|
||||||
var user;
|
const r = yield [ packageService.listModulesByUser(name), userService.getAndSave(name) ];
|
||||||
var r = yield [packageService.listModulesByUser(name), userService.getAndSave(name)];
|
const packages = r[0];
|
||||||
var packages = r[0];
|
let user = r[1];
|
||||||
var user = r[1];
|
|
||||||
if (!user && !packages.length) {
|
if (!user && !packages.length) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
|
|
||||||
user = user || {};
|
user = user || {};
|
||||||
|
|
||||||
var data = {
|
const data = {
|
||||||
name: name,
|
name,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
json: user.json || {}
|
json: user.json || {},
|
||||||
|
isNpmUser: user.isNpmUser,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (data.json.login) {
|
if (data.json.login) {
|
||||||
// custom user format
|
// custom user format
|
||||||
// convert to npm user format
|
// convert to npm user format
|
||||||
var json = data.json;
|
const json = data.json;
|
||||||
data.json = {
|
data.json = {
|
||||||
_id: 'org.couchdb.user:' + user.name,
|
_id: 'org.couchdb.user:' + user.name,
|
||||||
_rev: user.rev,
|
_rev: user.rev,
|
||||||
@@ -55,16 +40,16 @@ module.exports = function* showUser(next) {
|
|||||||
avatar: json.avatar_url,
|
avatar: json.avatar_url,
|
||||||
fullname: json.name || json.login,
|
fullname: json.name || json.login,
|
||||||
homepage: json.html_url,
|
homepage: json.html_url,
|
||||||
im: json.im_url
|
im: json.im_url,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
yield this.render('profile', {
|
yield this.render('profile', {
|
||||||
title: 'User - ' + name,
|
title: 'User - ' + name,
|
||||||
packages: packages,
|
packages,
|
||||||
user: data,
|
user: data,
|
||||||
lastModified: user.gmt_modified,
|
lastModified: user.gmt_modified,
|
||||||
isAdmin: isAdmin,
|
isAdmin,
|
||||||
scopes: scopes
|
scopes,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
49
dispatch.js
49
dispatch.js
@@ -1,27 +1,15 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - dispatch.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* dead_horse <dead_horse@qq.com>
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const childProcess = require('child_process');
|
||||||
* Module dependencies.
|
const path = require('path');
|
||||||
*/
|
const util = require('util');
|
||||||
|
const cfork = require('cfork');
|
||||||
|
const config = require('./config');
|
||||||
|
const workerPath = path.join(__dirname, 'worker.js');
|
||||||
|
const syncPath = path.join(__dirname, 'sync');
|
||||||
|
|
||||||
var childProcess = require('child_process');
|
console.log('Starting cnpmjs.org ...\ncluster: %s\nadmins: %j\nscopes: %j\nsourceNpmRegistry: %s\nsyncModel: %s',
|
||||||
var path = require('path');
|
config.enableCluster, config.admins, config.scopes, config.sourceNpmRegistry, config.syncModel);
|
||||||
var util = require('util');
|
|
||||||
var cfork = require('cfork');
|
|
||||||
var config = require('./config');
|
|
||||||
var workerPath = path.join(__dirname, 'worker.js');
|
|
||||||
var syncPath = path.join(__dirname, 'sync');
|
|
||||||
|
|
||||||
if (config.enableCluster) {
|
if (config.enableCluster) {
|
||||||
forkWorker();
|
forkWorker();
|
||||||
@@ -39,14 +27,17 @@ function forkWorker() {
|
|||||||
cfork({
|
cfork({
|
||||||
exec: workerPath,
|
exec: workerPath,
|
||||||
count: config.numCPUs,
|
count: config.numCPUs,
|
||||||
}).on('fork', function (worker) {
|
})
|
||||||
|
.on('fork', worker => {
|
||||||
console.log('[%s] [worker:%d] new worker start', Date(), worker.process.pid);
|
console.log('[%s] [worker:%d] new worker start', Date(), worker.process.pid);
|
||||||
}).on('disconnect', function (worker) {
|
})
|
||||||
|
.on('disconnect', worker => {
|
||||||
console.error('[%s] [master:%s] wroker:%s disconnect, suicide: %s, state: %s.',
|
console.error('[%s] [master:%s] wroker:%s disconnect, suicide: %s, state: %s.',
|
||||||
Date(), process.pid, worker.process.pid, worker.suicide, worker.state);
|
Date(), process.pid, worker.process.pid, worker.suicide, worker.state);
|
||||||
}).on('exit', function (worker, code, signal) {
|
})
|
||||||
var exitCode = worker.process.exitCode;
|
.on('exit', (worker, code, signal) => {
|
||||||
var err = new Error(util.format('worker %s died (code: %s, signal: %s, suicide: %s, state: %s)',
|
const exitCode = worker.process.exitCode;
|
||||||
|
const 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));
|
worker.process.pid, exitCode, signal, worker.suicide, worker.state));
|
||||||
err.name = 'WorkerDiedError';
|
err.name = 'WorkerDiedError';
|
||||||
console.error('[%s] [master:%s] wroker exit: %s', Date(), process.pid, err.stack);
|
console.error('[%s] [master:%s] wroker exit: %s', Date(), process.pid, err.stack);
|
||||||
@@ -54,9 +45,9 @@ function forkWorker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function forkSyncer() {
|
function forkSyncer() {
|
||||||
var syncer = childProcess.fork(syncPath);
|
const syncer = childProcess.fork(syncPath);
|
||||||
syncer.on('exit', function (code, signal) {
|
syncer.on('exit', (code, signal) => {
|
||||||
var err = new Error(util.format('syncer %s died (code: %s, signal: %s, stdout: %s, stderr: %s)',
|
const err = new Error(util.format('syncer %s died (code: %s, signal: %s, stdout: %s, stderr: %s)',
|
||||||
syncer.pid, code, signal, syncer.stdout, syncer.stderr));
|
syncer.pid, code, signal, syncer.stdout, syncer.stderr));
|
||||||
err.name = 'SyncerWorkerDiedError';
|
err.name = 'SyncerWorkerDiedError';
|
||||||
console.error('[%s] [master:%s] syncer exit: %s: %s',
|
console.error('[%s] [master:%s] syncer exit: %s: %s',
|
||||||
|
|||||||
143
docs/Migrating-from-1.x-to-2.x.md
Normal file
143
docs/Migrating-from-1.x-to-2.x.md
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
# Migrating from 1.x to 2.x
|
||||||
|
|
||||||
|
2.x using [Sequelize] ORM to supports MySQL, MariaDB, SQLite or PostgreSQL databases.
|
||||||
|
|
||||||
|
## New download total table structure
|
||||||
|
|
||||||
|
### Create `downloads` table SQL
|
||||||
|
|
||||||
|
You should create `downloads` table first:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
CREATE TABLE IF NOT EXISTS `downloads` (
|
||||||
|
`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',
|
||||||
|
`name` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'module name',
|
||||||
|
`date` int unsigned NOT NULL COMMENT 'YYYYMM format',
|
||||||
|
`d01` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '01 download count',
|
||||||
|
`d02` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '02 download count',
|
||||||
|
`d03` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '03 download count',
|
||||||
|
`d04` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '04 download count',
|
||||||
|
`d05` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '05 download count',
|
||||||
|
`d06` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '06 download count',
|
||||||
|
`d07` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '07 download count',
|
||||||
|
`d08` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '08 download count',
|
||||||
|
`d09` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '09 download count',
|
||||||
|
`d10` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '10 download count',
|
||||||
|
`d11` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '11 download count',
|
||||||
|
`d12` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '12 download count',
|
||||||
|
`d13` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '13 download count',
|
||||||
|
`d14` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '14 download count',
|
||||||
|
`d15` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '15 download count',
|
||||||
|
`d16` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '16 download count',
|
||||||
|
`d17` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '17 download count',
|
||||||
|
`d18` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '18 download count',
|
||||||
|
`d19` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '19 download count',
|
||||||
|
`d20` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '20 download count',
|
||||||
|
`d21` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '21 download count',
|
||||||
|
`d22` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '22 download count',
|
||||||
|
`d23` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '23 download count',
|
||||||
|
`d24` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '24 download count',
|
||||||
|
`d25` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '25 download count',
|
||||||
|
`d26` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '26 download count',
|
||||||
|
`d27` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '27 download count',
|
||||||
|
`d28` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '28 download count',
|
||||||
|
`d29` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '29 download count',
|
||||||
|
`d30` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '30 download count',
|
||||||
|
`d31` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '31 download count',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `name_date` (`name`, `date`),
|
||||||
|
KEY `date` (`date`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module download total info';
|
||||||
|
```
|
||||||
|
|
||||||
|
### Sync `download_total` to `downloads`
|
||||||
|
|
||||||
|
Then use [sync_download_total.js](../tools/sync_download_total.js) scrpt to sync datas from `download_total`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ node --harmony tools/sync_download_total.js
|
||||||
|
```
|
||||||
|
|
||||||
|
# `config.js` changes in 2.x
|
||||||
|
|
||||||
|
## New database config
|
||||||
|
|
||||||
|
```js
|
||||||
|
/**
|
||||||
|
* database config
|
||||||
|
*/
|
||||||
|
|
||||||
|
database: {
|
||||||
|
db: 'cnpmjs_test',
|
||||||
|
username: 'root',
|
||||||
|
password: '',
|
||||||
|
|
||||||
|
// the sql dialect of the database
|
||||||
|
// - currently supported: 'mysql', 'sqlite', 'postgres', 'mariadb'
|
||||||
|
dialect: 'sqlite',
|
||||||
|
|
||||||
|
// custom host; default: 127.0.0.1
|
||||||
|
host: '127.0.0.1',
|
||||||
|
|
||||||
|
// custom port; default: 3306
|
||||||
|
port: 3306,
|
||||||
|
|
||||||
|
// use pooling in order to reduce db connection overload and to increase speed
|
||||||
|
// currently only for mysql and postgresql (since v1.5.0)
|
||||||
|
pool: {
|
||||||
|
maxConnections: 10,
|
||||||
|
minConnections: 0,
|
||||||
|
maxIdleTime: 30000
|
||||||
|
},
|
||||||
|
|
||||||
|
// the storage engine for 'sqlite'
|
||||||
|
// default store into ~/cnpmjs.org.sqlite
|
||||||
|
storage: path.join(process.env.HOME || root, 'cnpmjs.org.sqlite'),
|
||||||
|
|
||||||
|
logging: !!process.env.SQL_DEBUG,
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
If you're still using MySQL and old config.js `mysqlServers: []` from 1.x:
|
||||||
|
|
||||||
|
```js
|
||||||
|
mysqlServers: [
|
||||||
|
{
|
||||||
|
host: '127.0.0.1',
|
||||||
|
port: 3306,
|
||||||
|
user: 'root',
|
||||||
|
password: ''
|
||||||
|
}
|
||||||
|
],
|
||||||
|
mysqlDatabase: 'cnpmjs_test',
|
||||||
|
mysqlMaxConnections: 4,
|
||||||
|
mysqlQueryTimeout: 5000,
|
||||||
|
```
|
||||||
|
|
||||||
|
We will do forward compat, and auto change old style config.js to:
|
||||||
|
|
||||||
|
```js
|
||||||
|
database: {
|
||||||
|
db: 'cnpmjs_test',
|
||||||
|
username: 'root',
|
||||||
|
password: '',
|
||||||
|
dialect: 'mysql',
|
||||||
|
host: '127.0.0.1',
|
||||||
|
port: 3306,
|
||||||
|
pool: {
|
||||||
|
maxConnections: 10,
|
||||||
|
minConnections: 0,
|
||||||
|
maxIdleTime: 30000
|
||||||
|
},
|
||||||
|
logging: !!process.env.SQL_DEBUG,
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
## remove `adaptScope`
|
||||||
|
|
||||||
|
`adaptScope: true | false` feature was removed.
|
||||||
|
|
||||||
|
|
||||||
|
[Sequelize]: http://sequelizejs.com/
|
||||||
63
docs/db.sql
63
docs/db.sql
@@ -151,17 +151,60 @@ 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 `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';
|
-- ALTER TABLE `total` ADD `last_sync_module` varchar(100) NOT NULL COMMENT 'last sync success module name';
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `download_total` (
|
-- CREATE TABLE IF NOT EXISTS `download_total` (
|
||||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
|
-- `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
|
||||||
`gmt_create` datetime NOT NULL COMMENT 'create time',
|
-- `gmt_create` datetime NOT NULL COMMENT 'create time',
|
||||||
`gmt_modified` datetime NOT NULL COMMENT 'modified time',
|
-- `gmt_modified` datetime NOT NULL COMMENT 'modified time',
|
||||||
`date` varchar(10) NOT NULL COMMENT 'YYYY-MM-DD format',
|
-- `date` datetime NOT NULL COMMENT 'YYYY-MM-DD format',
|
||||||
`name` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'module name',
|
-- `name` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'module name',
|
||||||
`count` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT 'download count',
|
-- `count` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT 'download count',
|
||||||
PRIMARY KEY (`id`),
|
-- PRIMARY KEY (`id`),
|
||||||
UNIQUE KEY `date_name` (`date`, `name`)
|
-- UNIQUE KEY `date_name` (`date`, `name`)
|
||||||
|
-- ) 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';
|
||||||
|
-- ALTER TABLE `download_total` CHANGE `date` `date` datetime NOT NULL COMMENT 'YYYY-MM-DD format';
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `downloads` (
|
||||||
|
`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',
|
||||||
|
`name` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'module name',
|
||||||
|
`date` int unsigned NOT NULL COMMENT 'YYYYMM format',
|
||||||
|
`d01` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '01 download count',
|
||||||
|
`d02` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '02 download count',
|
||||||
|
`d03` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '03 download count',
|
||||||
|
`d04` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '04 download count',
|
||||||
|
`d05` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '05 download count',
|
||||||
|
`d06` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '06 download count',
|
||||||
|
`d07` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '07 download count',
|
||||||
|
`d08` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '08 download count',
|
||||||
|
`d09` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '09 download count',
|
||||||
|
`d10` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '10 download count',
|
||||||
|
`d11` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '11 download count',
|
||||||
|
`d12` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '12 download count',
|
||||||
|
`d13` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '13 download count',
|
||||||
|
`d14` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '14 download count',
|
||||||
|
`d15` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '15 download count',
|
||||||
|
`d16` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '16 download count',
|
||||||
|
`d17` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '17 download count',
|
||||||
|
`d18` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '18 download count',
|
||||||
|
`d19` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '19 download count',
|
||||||
|
`d20` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '20 download count',
|
||||||
|
`d21` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '21 download count',
|
||||||
|
`d22` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '22 download count',
|
||||||
|
`d23` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '23 download count',
|
||||||
|
`d24` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '24 download count',
|
||||||
|
`d25` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '25 download count',
|
||||||
|
`d26` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '26 download count',
|
||||||
|
`d27` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '27 download count',
|
||||||
|
`d28` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '28 download count',
|
||||||
|
`d29` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '29 download count',
|
||||||
|
`d30` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '30 download count',
|
||||||
|
`d31` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '31 download count',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `name_date` (`name`, `date`),
|
||||||
|
KEY `date` (`date`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module download total info';
|
) 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 IF NOT EXISTS `module_deps` (
|
CREATE TABLE IF NOT EXISTS `module_deps` (
|
||||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
|
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
|
||||||
|
|||||||
BIN
docs/network.png
Normal file
BIN
docs/network.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 123 KiB |
98
docs/network.puml
Normal file
98
docs/network.puml
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
@startuml
|
||||||
|
|
||||||
|
title cnpmjs.org, npm.taobao.org Network
|
||||||
|
|
||||||
|
node "China User" {
|
||||||
|
[cnpm cli]
|
||||||
|
}
|
||||||
|
|
||||||
|
node "OSS: aliyuncs.com" {
|
||||||
|
[tnpm-hz.oss-cn-hangzhou]
|
||||||
|
}
|
||||||
|
|
||||||
|
node "SLB: 114.55.80.225 Hangzhou" {
|
||||||
|
[npm.taobao.org]
|
||||||
|
[registry.npm.taobao.org]
|
||||||
|
}
|
||||||
|
|
||||||
|
node "npmtaobao3: 121.41.*" {
|
||||||
|
[nginx 5]
|
||||||
|
[registry 5]
|
||||||
|
[web 5]
|
||||||
|
[syncer 5]
|
||||||
|
}
|
||||||
|
|
||||||
|
node "npmtaobao4: 120.26.*" {
|
||||||
|
[nginx 6]
|
||||||
|
[registry 6]
|
||||||
|
[web 6]
|
||||||
|
}
|
||||||
|
|
||||||
|
node "cnpm6: 47.88.189.193 Singapore" {
|
||||||
|
[cnpmjs.org]
|
||||||
|
[r.cnpmjs.org]
|
||||||
|
[nginx 7]
|
||||||
|
[registry 7]
|
||||||
|
[web 7]
|
||||||
|
[syncer 7]
|
||||||
|
}
|
||||||
|
|
||||||
|
node "Aliyun CDN" {
|
||||||
|
[cdn.npm.taobao.org]
|
||||||
|
}
|
||||||
|
|
||||||
|
node "qiniu CDN" {
|
||||||
|
[cnpmjs.up.qiniu.com]
|
||||||
|
[dn-cnpm.qbox.me]
|
||||||
|
}
|
||||||
|
|
||||||
|
database "taobaonpm DB" {
|
||||||
|
[rds2860*.mysql.rds.aliyuncs.com]
|
||||||
|
}
|
||||||
|
|
||||||
|
database "cnpm DB" {
|
||||||
|
[rdsqiz*.mysql.rds.aliyuncs.com]
|
||||||
|
}
|
||||||
|
|
||||||
|
node "npmjs.com" {
|
||||||
|
[registry.npmjs.com]
|
||||||
|
[www.npmjs.com]
|
||||||
|
}
|
||||||
|
|
||||||
|
[cnpm cli] -down-> [registry.npm.taobao.org]: Read, Write
|
||||||
|
[cnpm cli] -down-> [cdn.npm.taobao.org]: Read tgz
|
||||||
|
[cnpm cli] -down-> [npm.taobao.org]: "Read /mirrors"
|
||||||
|
|
||||||
|
[registry.npm.taobao.org] -down-> [nginx 5]
|
||||||
|
[nginx 5] -down-> [registry 5]
|
||||||
|
[npm.taobao.org] -down-> [nginx 5]
|
||||||
|
[nginx 5] -down-> [web 5]
|
||||||
|
[registry.npm.taobao.org] -down-> [nginx 6]
|
||||||
|
[nginx 6] -down-> [registry 6]
|
||||||
|
[npm.taobao.org] -down-> [nginx 6]
|
||||||
|
[nginx 6] -down-> [web 6]
|
||||||
|
|
||||||
|
[registry 5] -down-> [rds2860*.mysql.rds.aliyuncs.com]: Read, Write
|
||||||
|
[web 5] -down-> [rds2860*.mysql.rds.aliyuncs.com]: Read
|
||||||
|
[syncer 5] -down-> [rds2860*.mysql.rds.aliyuncs.com]: Read, Write
|
||||||
|
[syncer 5] -down-> [tnpm-hz.oss-cn-hangzhou]: Write
|
||||||
|
[syncer 5] -> [r.cnpmjs.org]: Read
|
||||||
|
[syncer 5] -> [dn-cnpm.qbox.me]: Read tgz
|
||||||
|
[registry 6] -down-> [rds2860*.mysql.rds.aliyuncs.com]: Read, Write
|
||||||
|
[web 6] -down-> [rds2860*.mysql.rds.aliyuncs.com]: Read
|
||||||
|
|
||||||
|
[cnpmjs.org] -down-> [nginx 7]
|
||||||
|
[nginx 7] -down-> [registry 7]
|
||||||
|
[r.cnpmjs.org] -down-> [nginx 7]
|
||||||
|
[nginx 7] -down-> [web 7]
|
||||||
|
|
||||||
|
[registry 7] -down-> [rdsqiz*.mysql.rds.aliyuncs.com]: Read, Write
|
||||||
|
[web 7] -down-> [rdsqiz*.mysql.rds.aliyuncs.com]: Read
|
||||||
|
[syncer 7] -down-> [rdsqiz*.mysql.rds.aliyuncs.com]: Read, Write
|
||||||
|
[syncer 7] -down-> [cnpmjs.up.qiniu.com]: Write
|
||||||
|
[syncer 7] -down-> [registry.npmjs.com]: Read
|
||||||
|
|
||||||
|
[cdn.npm.taobao.org] -down-> [tnpm-hz.oss-cn-hangzhou]: Read
|
||||||
|
[dn-cnpm.qbox.me] -down-> [cnpmjs.up.qiniu.com]: Read
|
||||||
|
|
||||||
|
@enduml
|
||||||
@@ -9,6 +9,8 @@
|
|||||||
* [User](/docs/registry-api.md#user)
|
* [User](/docs/registry-api.md#user)
|
||||||
* [Search](/docs/registry-api.md#search)
|
* [Search](/docs/registry-api.md#search)
|
||||||
|
|
||||||
|
[](https://app.getpostman.com/run-collection/f6c8cb46358039bcd689#?env%5BRegistry%5D=W3sia2V5IjoicmVnaXN0cnkiLCJ0eXBlIjoidGV4dCIsInZhbHVlIjoiaHR0cHM6Ly9yZWdpc3RyeS5ucG0udGFvYmFvLm9yZyIsImVuYWJsZWQiOnRydWV9LHsia2V5IjoicGFja2FnZSIsInZhbHVlIjoiY25wbSIsInR5cGUiOiJ0ZXh0IiwiZW5hYmxlZCI6dHJ1ZX1d)
|
||||||
|
|
||||||
## Schema
|
## Schema
|
||||||
|
|
||||||
All API access is over HTTPS or HTTP,
|
All API access is over HTTPS or HTTP,
|
||||||
@@ -19,22 +21,20 @@ All data is sent and received as JSON.
|
|||||||
$ curl -i https://registry.npmjs.org
|
$ curl -i https://registry.npmjs.org
|
||||||
|
|
||||||
HTTP/1.1 200 OK
|
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,
|
"db_name": "registry",
|
||||||
"instance_start_time":"1405721973718703","disk_format_version":6,"committed_update_seq":137250}
|
"doc_count": 123772,
|
||||||
|
"doc_del_count": 377,
|
||||||
|
"update_seq": 685591,
|
||||||
|
"purge_seq": 0,
|
||||||
|
"compact_running": false,
|
||||||
|
"disk_size": 634187899,
|
||||||
|
"data_size": 445454185,
|
||||||
|
"instance_start_time": "1420670152481614",
|
||||||
|
"disk_format_version": 6,
|
||||||
|
"committed_update_seq": 685591
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Client Errors
|
## Client Errors
|
||||||
@@ -61,22 +61,10 @@ $ curl -u "username:password" https://registry.npmjs.org
|
|||||||
## Failed login limit
|
## Failed login limit
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ curl -i -X PUT -u foo:pwd \
|
$ curl -i -X "GET" -u "foo:pwd" \
|
||||||
-d '{"name":"foo","email":"foo@bar.com","type":"user","roles":[]}' \
|
"https://registry.npmjs.com/-/user/org.couchdb.user:npm-user-service-testuser?write=true"
|
||||||
https://registry.npmjs.org/-/user/org.couchdb.user:foo/-rev/11-d226c6afa9286ab5b9eb858c429bdabf
|
|
||||||
|
|
||||||
HTTP/1.1 401 Unauthorized
|
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."}
|
{"error":"unauthorized","reason":"Name or password is incorrect."}
|
||||||
```
|
```
|
||||||
@@ -101,14 +89,11 @@ X-Timer: S1407252805.261390,VS0,VE434
|
|||||||
GET /:package
|
GET /:package
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Response
|
#### Response 200
|
||||||
|
|
||||||
```json
|
```json
|
||||||
HTTP/1.1 200 OK
|
HTTP/1.1 200 OK
|
||||||
Etag: "8UDCP753LFXOG42NMX88JAN40"
|
Etag: "8UDCP753LFXOG42NMX88JAN40"
|
||||||
Content-Type: application/json
|
|
||||||
Cache-Control: max-age=60
|
|
||||||
Content-Length: 2243
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"_id": "pedding",
|
"_id": "pedding",
|
||||||
@@ -246,6 +231,17 @@ Content-Length: 2243
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Response 404
|
||||||
|
|
||||||
|
```json
|
||||||
|
HTTP/1.1 404 Object Not Found
|
||||||
|
|
||||||
|
{
|
||||||
|
"error": "not_found",
|
||||||
|
"reason": "document not found"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### ~~Get a special version or tag package~~
|
### ~~Get a special version or tag package~~
|
||||||
|
|
||||||
__deprecated__
|
__deprecated__
|
||||||
@@ -254,7 +250,7 @@ __deprecated__
|
|||||||
GET /:package/:tag_or_version
|
GET /:package/:tag_or_version
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Reponse
|
#### Reponse 200
|
||||||
|
|
||||||
```json
|
```json
|
||||||
HTTP/1.1 200 OK
|
HTTP/1.1 200 OK
|
||||||
@@ -745,9 +741,52 @@ HTTP/1.1 200 OK
|
|||||||
|
|
||||||
## User
|
## User
|
||||||
|
|
||||||
* [Get a single user](/docs/registry-api.md#get-a-single-user)
|
- [Auth user](/docs/registry-api.md#auth-user)
|
||||||
* [Add a new user](/docs/registry-api.md#add-a-new-user)
|
- [Get a single user](/docs/registry-api.md#get-a-single-user)
|
||||||
* [Update a exists user](/docs/registry-api.md#update-a-exists-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)
|
||||||
|
|
||||||
|
### Auth user
|
||||||
|
|
||||||
|
* Authentication required.
|
||||||
|
|
||||||
|
```
|
||||||
|
GET /-/user/org.couchdb.user::username?write=true
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Response 200
|
||||||
|
|
||||||
|
```json
|
||||||
|
HTTP/1.1 200 OK
|
||||||
|
ETag: "5-a31b61ba3c50b50f7fcaf185e079e17a"
|
||||||
|
|
||||||
|
{
|
||||||
|
"_id": "org.couchdb.user:npm-user-service-testuser",
|
||||||
|
"_rev": "5-a31b61ba3c50b50f7fcaf185e079e17a",
|
||||||
|
"password_scheme": "pbkdf2",
|
||||||
|
"iterations": 10,
|
||||||
|
"name": "npm-user-service-testuser",
|
||||||
|
"email": "fengmk2@gmail.com",
|
||||||
|
"type": "user",
|
||||||
|
"roles": [],
|
||||||
|
"date": "2015-01-04T08:28:51.378Z",
|
||||||
|
"password_scheme": "pbkdf2",
|
||||||
|
"iterations": 10,
|
||||||
|
"derived_key": "644157c126b93356e6eba2c59fdf1b7ec644ebf2",
|
||||||
|
"salt": "5d13874c0aa10751e35743bacd6eedd5"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Response 401
|
||||||
|
|
||||||
|
```json
|
||||||
|
HTTP/1.1 401 Unauthorized
|
||||||
|
|
||||||
|
{
|
||||||
|
"error": "unauthorized",
|
||||||
|
"reason": "Name or password is incorrect."
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Get a single user
|
### Get a single user
|
||||||
|
|
||||||
@@ -755,7 +794,7 @@ HTTP/1.1 200 OK
|
|||||||
GET /-/user/org.couchdb.user::username
|
GET /-/user/org.couchdb.user::username
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Response
|
#### Response 200
|
||||||
|
|
||||||
```json
|
```json
|
||||||
HTTP/1.1 200 OK
|
HTTP/1.1 200 OK
|
||||||
@@ -825,6 +864,17 @@ ETag: "32-984ee97e01aea166dcab6d1517c730e3"
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Response 404
|
||||||
|
|
||||||
|
```json
|
||||||
|
HTTP/1.1 404 Object Not Found
|
||||||
|
|
||||||
|
{
|
||||||
|
"error": "not_found",
|
||||||
|
"reason": "missing"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Add a new user
|
### Add a new user
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -845,7 +895,7 @@ PUT /-/user/org.couchdb.user::username
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Response
|
#### Response 201
|
||||||
|
|
||||||
```json
|
```json
|
||||||
Status: 201 Created
|
Status: 201 Created
|
||||||
@@ -857,6 +907,19 @@ Status: 201 Created
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Response 409
|
||||||
|
|
||||||
|
User already exists
|
||||||
|
|
||||||
|
```json
|
||||||
|
HTTP/1.1 409 Conflict
|
||||||
|
|
||||||
|
{
|
||||||
|
"error": "conflict",
|
||||||
|
"reason": "Document update conflict."
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Update a exists user
|
### Update a exists user
|
||||||
|
|
||||||
* Authentication required.
|
* Authentication required.
|
||||||
|
|||||||
@@ -1,115 +0,0 @@
|
|||||||
# Install & Get Started
|
|
||||||
|
|
||||||
## Deps
|
|
||||||
|
|
||||||
* MySQL Server: http://db4free.net/
|
|
||||||
* qiniu CDN: http://www.qiniu.com/
|
|
||||||
* redis session: https://garantiadata.com Support 24MB free spaces.
|
|
||||||
* node: >=0.10.21
|
|
||||||
|
|
||||||
## Clone
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ git clone git://github.com/fengmk2/cnpmjs.org.git $HOME/cnpmjs.org
|
|
||||||
$ cd $HOME/cnpmjs.org
|
|
||||||
```
|
|
||||||
|
|
||||||
## Create your `config.js`
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ vim config/config.js
|
|
||||||
```
|
|
||||||
|
|
||||||
`config.js` content sample:
|
|
||||||
|
|
||||||
```js
|
|
||||||
module.exports = {
|
|
||||||
debug: false,
|
|
||||||
enableCluster: true, // enable cluster mode
|
|
||||||
logdir: 'your application log dir',
|
|
||||||
mysqlServers: [
|
|
||||||
{
|
|
||||||
host: 'your mysql host',
|
|
||||||
port: 3306,
|
|
||||||
user: 'yourname',
|
|
||||||
password: 'your password'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
mysqlDatabase: 'cnpmjs',
|
|
||||||
redis: {
|
|
||||||
host: 'your redist host',
|
|
||||||
port: 6379,
|
|
||||||
},
|
|
||||||
qn: {
|
|
||||||
accessKey: "your qiniu appkey",
|
|
||||||
secretKey: "your secret key",
|
|
||||||
bucket: "foobucket",
|
|
||||||
domain: "http://foobucket.u.qiniudn.com"
|
|
||||||
},
|
|
||||||
nfs: null, // you can set a nfs to replace qiniu cdn
|
|
||||||
enablePrivate: true, // enable private mode, only admin can publish, other use just can sync package from source npm
|
|
||||||
admins: {
|
|
||||||
admin: 'admin@cnpmjs.org',
|
|
||||||
},
|
|
||||||
syncModel: 'exist', //`all` sync all packages, `exist` only update exist packages, `none` do nothing
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
## Create MySQL Database and Tables
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ mysql -u yourname -p
|
|
||||||
|
|
||||||
mysql> use cnpmjs;
|
|
||||||
mysql> source docs/db.sql
|
|
||||||
```
|
|
||||||
|
|
||||||
## Use your own CDN
|
|
||||||
If you wan to use your own CDN instead of qiniu. Just look at `common/qnfs.js` and implement the interface like it, then pass it by set `config.nfs`.
|
|
||||||
|
|
||||||
## npm install
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ npm install
|
|
||||||
```
|
|
||||||
|
|
||||||
## start
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ ./bin/nodejsctl start
|
|
||||||
|
|
||||||
Starting cnpmjs.org ...
|
|
||||||
Start nodejs success. PID=27175
|
|
||||||
```
|
|
||||||
|
|
||||||
## open registry and web
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# registry
|
|
||||||
$ open http://localhost:7001
|
|
||||||
# web
|
|
||||||
$ open http://localhost:7002
|
|
||||||
```
|
|
||||||
|
|
||||||
## use cnpm cli with your own registry
|
|
||||||
You do not need to write another command line tool with your own registry,
|
|
||||||
just alias [cnpm](http://github.com/fengmk2/cnpm), then you can get a npm client for you own registry.
|
|
||||||
|
|
||||||
```
|
|
||||||
# install cnpm first
|
|
||||||
npm install -g cnpm
|
|
||||||
|
|
||||||
# then alias lnpm to cnpm, but change config to your own registry
|
|
||||||
alias lnpm='cnpm --registry=http://localhost:7001\
|
|
||||||
--registryweb=http://localhost:7002\
|
|
||||||
--cache=$HOME/.npm/.cache/lnpm\
|
|
||||||
--disturl=http://cnpmjs.org/dist\
|
|
||||||
--userconfig=$HOME/.lnpmrc'
|
|
||||||
|
|
||||||
#or put this in .zshrc or .bashrc
|
|
||||||
echo "#lnpm alias\nalias lnpm='cnpm --registry=http://localhost:7001\
|
|
||||||
--registryweb=http://localhost:7002\
|
|
||||||
--cache=$HOME/.npm/.cache/lnpm\
|
|
||||||
--disturl=http://cnpmjs.org/dist\
|
|
||||||
--userconfig=$HOME/.lnpmrc'" >> $HOME/.zshrc && source $HOME/.zshrc
|
|
||||||
```
|
|
||||||
@@ -4,12 +4,12 @@ So `cnpm` is meaning: **Company npm**.
|
|||||||
|
|
||||||
## Registry
|
## Registry
|
||||||
|
|
||||||
* Our public registry: [r.cnpmjs.org](http://r.cnpmjs.org), syncing from [registry.npmjs.org](http://registry.npmjs.org)
|
- Our public registry: [r.cnpmjs.org](https://r.cnpmjs.org), syncing from [registry.npmjs.com](https://registry.npmjs.com)
|
||||||
* Current [cnpmjs.org](/) version: <span id="app-version"></span>
|
- [cnpmjs.org](/) version: <span id="app-version"></span>
|
||||||
* Mirror of [Node.js Manual & Documentation](/dist/latest/docs/api/index.html)
|
- [Node.js](https://nodejs.org) version: <span id="node-version"></span>
|
||||||
* Mirror of [nodejs.org/dist](http://nodejs.org/dist): [/dist mirror](/dist)
|
- For developers in China, please visit [the China mirror](https://npm.taobao.org). 中国用户请访问[国内镜像站点](https://npm.taobao.org)。
|
||||||
* Mirror of [phantomjs downloads](https://bitbucket.org/ariya/phantomjs/downloads): [phantomjs mirror](/dist/phantomjs/)
|
|
||||||
|
|
||||||
|
<div class="ant-table">
|
||||||
<table class="downloads">
|
<table class="downloads">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -29,12 +29,17 @@ So `cnpm` is meaning: **Company npm**.
|
|||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="sync" style="display:none;">
|
<div class="sync" style="display:none;">
|
||||||
<h3>Sync Status</h3>
|
<h3>Sync Status</h3>
|
||||||
<p id="sync-model"></p>
|
<p id="sync-model"></p>
|
||||||
<p>Last sync time is <span id="last-sync-time"></span>. </p>
|
<p>Last sync time is <span id="last-sync-time"></span>. </p>
|
||||||
<p class="syncing alert alert-info">The sync worker is working in the backend now. </p>
|
<div class="ant-alert ant-alert-info syncing">
|
||||||
|
<span class="anticon ant-alert-icon anticon-info-circle"></span>
|
||||||
|
<span class="ant-alert-description">The sync worker is working in the backend now. </span>
|
||||||
|
</div>
|
||||||
|
<div class="ant-table">
|
||||||
<table class="sync-status">
|
<table class="sync-status">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -49,50 +54,55 @@ So `cnpm` is meaning: **Company npm**.
|
|||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
Running on [Node.js](http://nodejs.org), version <span id="node-version"></span>.
|
|
||||||
|
|
||||||
<script src="/js/readme.js"></script>
|
<script src="/js/readme.js"></script>
|
||||||
|
|
||||||
## Version Badge
|
## Badges
|
||||||
|
|
||||||
Default style is `flat-square`.
|
Default style is `flat-square`.
|
||||||
|
|
||||||
Badge URL: `http://cnpmjs.org/badge/v/cnpmjs.org.svg` 
|
### Version
|
||||||
|
|
||||||
|
Badge URL: `https://cnpmjs.org/badge/v/cnpmjs.org.svg` 
|
||||||
|
|
||||||
* `<0.1.0 & >=0.0.0`: 
|
* `<0.1.0 & >=0.0.0`: 
|
||||||
* `<1.0.0 & >=0.1.0`: 
|
* `<1.0.0 & >=0.1.0`: 
|
||||||
* `>=1.0.0`: 
|
* `>=1.0.0`: 
|
||||||
|
|
||||||
|
### Downloads
|
||||||
|
|
||||||
|
Badge URL: `https://cnpmjs.org/badge/d/cnpmjs.org.svg` 
|
||||||
|
|
||||||
## Usage
|
## 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:
|
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:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
npm install -g cnpm --registry=http://r.cnpmjs.org
|
$ npm install -g cnpm --registry=https://registry.npm.taobao.org
|
||||||
```
|
```
|
||||||
|
|
||||||
Or you can alias NPM to use it:
|
Or you can alias NPM to use it:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
alias cnpm="npm --registry=http://r.cnpmjs.org \
|
alias cnpm="npm --registry=https://registry.npm.taobao.org \
|
||||||
--cache=$HOME/.npm/.cache/cnpm \
|
--cache=$HOME/.npm/.cache/cnpm \
|
||||||
--disturl=http://cnpmjs.org/dist \
|
--disturl=https://npm.taobao.org/mirrors/node \
|
||||||
--userconfig=$HOME/.cnpmrc"
|
--userconfig=$HOME/.cnpmrc"
|
||||||
|
|
||||||
#Or alias it in .bashrc or .zshrc
|
#Or alias it in .bashrc or .zshrc
|
||||||
$ echo '\n#alias for cnpm\nalias cnpm="npm --registry=http://r.cnpmjs.org \
|
$ echo '\n#alias for cnpm\nalias cnpm="npm --registry=https://registry.npm.taobao.org \
|
||||||
--cache=$HOME/.npm/.cache/cnpm \
|
--cache=$HOME/.npm/.cache/cnpm \
|
||||||
--disturl=http://cnpmjs.org/dist \
|
--disturl=https://npm.taobao.org/mirrors/node \
|
||||||
--userconfig=$HOME/.cnpmrc"' >> ~/.zshrc && source ~/.zshrc
|
--userconfig=$HOME/.cnpmrc"' >> ~/.zshrc && source ~/.zshrc
|
||||||
```
|
```
|
||||||
|
|
||||||
### install
|
### install
|
||||||
|
|
||||||
Install package from [r.cnpmjs.org](http://r.cnpmjs.org). When installing a package or version does not exist, it will try to install from the official registry([registry.npmjs.org](http://registry.npmjs.org)), and sync this package to cnpm in the backend.
|
Install package from [r.cnpmjs.org](//r.cnpmjs.org). When installing a package or version does not exist, it will try to install from the official registry([registry.npmjs.org](https://registry.npmjs.org)), and sync this package to cnpm in the backend.
|
||||||
|
|
||||||
```
|
```bash
|
||||||
$ cnpm install [name]
|
$ cnpm install [name]
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -104,10 +114,10 @@ Only `cnpm` cli has this command. Meaning sync package from source npm.
|
|||||||
$ cnpm sync connect
|
$ cnpm sync connect
|
||||||
```
|
```
|
||||||
|
|
||||||
sync package on web: [cnpmjs.org/sync/connect](http://cnpmjs.org/sync/connect)
|
sync package on web: [sync/connect](/sync/connect)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ open http://cnpmjs.org/sync/connect
|
$ open http://registry.npm.taobao.org/sync/connect
|
||||||
```
|
```
|
||||||
|
|
||||||
### publish / unpublish
|
### publish / unpublish
|
||||||
@@ -135,6 +145,11 @@ $ cnpm info cnpm
|
|||||||
|
|
||||||
Release [History](/history).
|
Release [History](/history).
|
||||||
|
|
||||||
## npm and cnpm relation
|
## npmjs.org, cnpmjs.org and npm.taobao.org relation
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
## Sponsors
|
||||||
|
|
||||||
|
- [](http://click.aliyun.com/m/4288/) (2016.2 - now)
|
||||||
|
- [](http://www.ucloud.cn?sem=sdk-CNPMJS) (2015.3 - 2016.3)
|
||||||
|
|||||||
20
index.js
20
index.js
@@ -1,30 +1,16 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - index.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const config = require('./config');
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var config = require('./config');
|
|
||||||
|
|
||||||
exports.loadConfig = config.loadConfig;
|
exports.loadConfig = config.loadConfig;
|
||||||
exports.config = config;
|
exports.config = config;
|
||||||
|
|
||||||
exports.startWorker = function (customConfig) {
|
exports.startWorker = function(customConfig) {
|
||||||
config.loadConfig(customConfig);
|
config.loadConfig(customConfig);
|
||||||
require('./worker');
|
require('./worker');
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.startSync = function (customConfig) {
|
exports.startSync = function(customConfig) {
|
||||||
config.loadConfig(customConfig);
|
config.loadConfig(customConfig);
|
||||||
require('./sync');
|
require('./sync');
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,58 +1,66 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - lib/common.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const crypto = require('crypto');
|
||||||
* Module dependencies.
|
const path = require('path');
|
||||||
*/
|
const config = require('../config');
|
||||||
|
const util = require('util');
|
||||||
|
|
||||||
var crypto = require('crypto');
|
exports.getTarballFilepath = function(filename) {
|
||||||
var path = require('path');
|
|
||||||
var config = require('../config');
|
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
exports.getTarballFilepath = function (filename) {
|
|
||||||
// ensure download file path unique
|
// ensure download file path unique
|
||||||
// TODO: not only .tgz, and also other extname
|
// TODO: not only .tgz, and also other extname
|
||||||
var name = filename.replace(/\.tgz$/, '.' + crypto.randomBytes(16).toString('hex') + '.tgz');
|
const name = filename.replace(/\.tgz$/, '.' + crypto.randomBytes(16).toString('hex') + '.tgz');
|
||||||
return path.join(config.uploadDir, name);
|
return path.join(config.uploadDir, name);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getCDNKey = function (name, filename) {
|
exports.getCDNKey = function(name, filename) {
|
||||||
|
// if name is scope package name, need to auto fix filename as a scope package file name
|
||||||
|
// e.g.: @scope/foo, filename: foo-1.0.0.tgz => filename: @scope/foo-1.0.0.tgz
|
||||||
|
if (name[0] === '@' && filename[0] !== '@') {
|
||||||
|
filename = name.split('/')[0] + '/' + filename;
|
||||||
|
}
|
||||||
return '/' + name + '/-/' + filename;
|
return '/' + name + '/-/' + filename;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.setDownloadURL = function (pkg, ctx, host) {
|
exports.setDownloadURL = function(pkg, ctx, host) {
|
||||||
if (pkg.dist) {
|
if (pkg.dist) {
|
||||||
host = host || ctx.host;
|
host = host || config.registryHost || ctx.host;
|
||||||
pkg.dist.tarball = util.format('%s://%s/%s/download/%s-%s.tgz',
|
pkg.dist.tarball = util.format('%s://%s/%s/download/%s-%s.tgz',
|
||||||
ctx.protocol,
|
ctx.protocol,
|
||||||
host, pkg.name, pkg.name, pkg.version);
|
host, pkg.name, pkg.name, pkg.version);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.isAdmin = function (username) {
|
exports.isAdmin = function(username) {
|
||||||
return typeof config.admins[username] === 'string';
|
return typeof config.admins[username] === 'string';
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.isMaintainer = function (user, maintainers) {
|
exports.isMaintainer = function(user, maintainers) {
|
||||||
if (user.isAdmin) {
|
if (user.isAdmin) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var username = user.name;
|
const username = user.name;
|
||||||
maintainers = maintainers || [];
|
maintainers = maintainers || [];
|
||||||
var match = maintainers.filter(function (item) {
|
const match = maintainers.filter(function(item) {
|
||||||
return item.name === username;
|
return item.name === username;
|
||||||
});
|
});
|
||||||
|
|
||||||
return match.length > 0;
|
return match.length > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.isLocalModule = function(mods) {
|
||||||
|
for (let i = 0; i < mods.length; i++) {
|
||||||
|
const r = mods[i];
|
||||||
|
if (r.package && r.package._publish_on_cnpm) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.isPrivateScopedPackage = function(name) {
|
||||||
|
if (name[0] !== '@') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return config.scopes.indexOf(name.split('/')[0]) >= 0;
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,49 +1,37 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - middleware/auth.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const debug = require('debug')('cnpmjs.org:middleware:auth');
|
||||||
* Module dependencies.
|
const UserService = require('../services/user');
|
||||||
*/
|
const config = require('../config');
|
||||||
|
|
||||||
var debug = require('debug')('cnpmjs.org:middleware:auth');
|
|
||||||
var UserService = require('../services/user');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the request authorization
|
* Parse the request authorization
|
||||||
* get the real user
|
* get the real user
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function() {
|
||||||
return function* auth(next) {
|
return function* auth(next) {
|
||||||
this.user = {};
|
this.user = {};
|
||||||
|
|
||||||
var authorization = (this.get('authorization') || '').split(' ')[1] || '';
|
let authorization = (this.get('authorization') || '').split(' ')[1] || '';
|
||||||
authorization = authorization.trim();
|
authorization = authorization.trim();
|
||||||
debug('%s %s with %j', this.method, this.url, authorization);
|
debug('%s %s with %j', this.method, this.url, authorization);
|
||||||
if (!authorization) {
|
if (!authorization) {
|
||||||
return yield* next;
|
return yield unauthorized.call(this, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
authorization = new Buffer(authorization, 'base64').toString().split(':');
|
authorization = new Buffer(authorization, 'base64').toString();
|
||||||
if (authorization.length !== 2) {
|
const pos = authorization.indexOf(':');
|
||||||
return yield* next;
|
if (pos === -1) {
|
||||||
|
return yield unauthorized.call(this, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
var username = authorization[0];
|
const username = authorization.slice(0, pos);
|
||||||
var password = authorization[1];
|
const password = authorization.slice(pos + 1);
|
||||||
|
|
||||||
var row;
|
let row;
|
||||||
try {
|
try {
|
||||||
row = yield* UserService.auth(username, password);
|
row = yield UserService.auth(username, password);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// do not response error here
|
// do not response error here
|
||||||
// many request do not need login
|
// many request do not need login
|
||||||
@@ -52,13 +40,29 @@ module.exports = function () {
|
|||||||
|
|
||||||
if (!row) {
|
if (!row) {
|
||||||
debug('auth fail user: %j, headers: %j', row, this.header);
|
debug('auth fail user: %j, headers: %j', row, this.header);
|
||||||
return yield* next;
|
return yield unauthorized.call(this, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.user.name = row.login;
|
this.user.name = row.login;
|
||||||
this.user.isAdmin = row.site_admin;
|
this.user.isAdmin = row.site_admin;
|
||||||
this.user.scopes = row.scopes;
|
this.user.scopes = row.scopes;
|
||||||
debug('auth pass user: %j, headers: %j', this.user, this.header);
|
debug('auth pass user: %j, headers: %j', this.user, this.header);
|
||||||
yield* next;
|
yield next;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function* unauthorized(next) {
|
||||||
|
if (!config.alwaysAuth || this.method !== 'GET') {
|
||||||
|
return yield next;
|
||||||
|
}
|
||||||
|
this.status = 401;
|
||||||
|
this.set('WWW-Authenticate', 'Basic realm="sample"');
|
||||||
|
if (this.accepts([ 'html', 'json' ]) === 'json') {
|
||||||
|
this.body = {
|
||||||
|
error: 'unauthorized',
|
||||||
|
reason: 'login first',
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
this.body = 'login first';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,28 +1,15 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - middleware/block.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
module.exports = () => {
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = function () {
|
|
||||||
return function* block(next) {
|
return function* block(next) {
|
||||||
var ua = String(this.get('user-agent')).toLowerCase();
|
const ua = String(this.get('user-agent')).toLowerCase();
|
||||||
if (ua === 'ruby') {
|
if (ua === 'ruby') {
|
||||||
this.status = 403;
|
this.status = 403;
|
||||||
return this.body = {
|
this.body = {
|
||||||
message: 'forbidden Ruby user-agent, ip: ' + this.ip
|
message: 'forbidden Ruby user-agent, ip: ' + this.ip,
|
||||||
};
|
};
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
yield* next;
|
yield next;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,42 +1,28 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - middleware/editable.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const packageService = require('../services/package');
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var packageService = require('../services/package');
|
|
||||||
|
|
||||||
// admin or module's maintainer can modified the module
|
// admin or module's maintainer can modified the module
|
||||||
module.exports = function* editable(next) {
|
module.exports = function* editable(next) {
|
||||||
var username = this.user && this.user.name;
|
const username = this.user && this.user.name;
|
||||||
var moduleName = this.params.name || this.params[0];
|
const moduleName = this.params.name || this.params[0];
|
||||||
if (username && moduleName) {
|
if (username && moduleName) {
|
||||||
if (this.user.isAdmin) {
|
if (this.user.isAdmin) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
var isMaintainer = yield* packageService.isMaintainer(moduleName, username);
|
const isMaintainer = yield packageService.isMaintainer(moduleName, username);
|
||||||
if (isMaintainer) {
|
if (isMaintainer) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.status = 403;
|
this.status = 403;
|
||||||
var message = 'not authorized to modify ' + moduleName;
|
let message = 'not authorized to modify ' + moduleName;
|
||||||
if (username) {
|
if (username) {
|
||||||
message = username + ' ' + message;
|
message = username + ' ' + message;
|
||||||
}
|
}
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'forbidden user',
|
error: 'forbidden user',
|
||||||
reason: message
|
reason: message,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
16
middleware/exists_package.js
Normal file
16
middleware/exists_package.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const packageService = require('../services/package');
|
||||||
|
|
||||||
|
module.exports = function* (next) {
|
||||||
|
const name = this.params.name || this.params[0];
|
||||||
|
const pkg = yield packageService.getLatestModule(name);
|
||||||
|
if (pkg) {
|
||||||
|
return yield next;
|
||||||
|
}
|
||||||
|
this.status = 404;
|
||||||
|
this.body = {
|
||||||
|
error: 'not_found',
|
||||||
|
reason: 'document not found',
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,34 +1,14 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - middleware/limit.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const config = require('../config');
|
||||||
* Module dependencies.
|
const limit = require('koa-limit');
|
||||||
*/
|
|
||||||
|
|
||||||
var config = require('../config');
|
const limitConfig = config.limit;
|
||||||
var limit = require('koa-limit');
|
|
||||||
var store = require('../common/redis');
|
|
||||||
|
|
||||||
var limitConfig = config.limit;
|
|
||||||
|
|
||||||
if (!limitConfig.enable) {
|
if (!limitConfig.enable) {
|
||||||
module.exports = function *ignoreLimit(next) {
|
module.exports = function* ignoreLimit(next) {
|
||||||
yield *next;
|
yield next;
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (!config.debug) {
|
|
||||||
limitConfig.store = store;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = limit(limitConfig);
|
module.exports = limit(limitConfig);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,17 @@
|
|||||||
/*!
|
|
||||||
* cnpmjs.org - middleware/login.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const http = require('http');
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var http = require('http');
|
module.exports = function* login(next) {
|
||||||
|
|
||||||
module.exports = function *login(next) {
|
|
||||||
if (this.user.error) {
|
if (this.user.error) {
|
||||||
var status = this.user.error.status;
|
const status = this.user.error.status;
|
||||||
this.status = http.STATUS_CODES[status]
|
this.status = http.STATUS_CODES[status]
|
||||||
? status
|
? status
|
||||||
: 500;
|
: 500;
|
||||||
|
|
||||||
this.body = {
|
this.body = {
|
||||||
error: this.user.error.name,
|
error: this.user.error.name,
|
||||||
reason: this.user.error.message
|
reason: this.user.error.message,
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -34,9 +20,9 @@ module.exports = function *login(next) {
|
|||||||
this.status = 401;
|
this.status = 401;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'unauthorized',
|
error: 'unauthorized',
|
||||||
reason: 'Login first.'
|
reason: 'Login first',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
yield *next;
|
yield next;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,32 +1,19 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - middleware/opensearch.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const template = `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
* Module dependencies.
|
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
||||||
*/
|
<ShortName>CNPM</ShortName>
|
||||||
|
<Description>Search packages in CNPM.</Description>
|
||||||
|
<Tags>CNPM</Tags>
|
||||||
|
<Url method="get" type="text/html" template="http://{{host}}/browse/keyword/{searchTerms}"/>
|
||||||
|
</OpenSearchDescription>`;
|
||||||
|
|
||||||
var template = '<?xml version="1.0" encoding="UTF-8"?>\
|
module.exports = function* opensearch(next) {
|
||||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">\
|
|
||||||
<ShortName>CNPM</ShortName>\
|
|
||||||
<Description>Search packages in CNPM.</Description>\
|
|
||||||
<Tags>CNPM</Tags>\
|
|
||||||
<Url method="get" type="text/html" template="http://${host}/browse/keyword/{searchTerms}"/>\
|
|
||||||
</OpenSearchDescription>';
|
|
||||||
|
|
||||||
module.exports = function *publishable(next) {
|
|
||||||
if (this.path === '/opensearch.xml') {
|
if (this.path === '/opensearch.xml') {
|
||||||
this.type = 'text/xml';
|
this.type = 'text/xml';
|
||||||
this.charset = 'utf-8';
|
this.charset = 'utf-8';
|
||||||
this.body = template.replace('${host}', this.host);
|
this.body = template.replace('{{host}}', this.host);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
yield *next;
|
yield next;
|
||||||
};
|
};
|
||||||
|
|||||||
46
middleware/proxy_to_npm.js
Normal file
46
middleware/proxy_to_npm.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const debug = require('debug')('cnpmjs.org:middleware:proxy_to_npm');
|
||||||
|
const config = require('../config');
|
||||||
|
|
||||||
|
module.exports = function(options) {
|
||||||
|
let redirectUrl = config.sourceNpmRegistry;
|
||||||
|
let proxyUrls = [
|
||||||
|
// /:pkg, dont contains scoped package
|
||||||
|
/^\/[\w\-\.]+$/,
|
||||||
|
// /-/package/:pkg/dist-tags
|
||||||
|
/^\/\-\/package\/[\w\-\.]+\/dist-tags/,
|
||||||
|
];
|
||||||
|
if (options && options.isWeb) {
|
||||||
|
redirectUrl = redirectUrl.replace('//registry.', '//');
|
||||||
|
proxyUrls = [
|
||||||
|
// /package/:pkg
|
||||||
|
/^\/package\/[\w\-\.]+$/,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return function* proxyToNpm(next) {
|
||||||
|
if (config.syncModel !== 'none') {
|
||||||
|
return yield next;
|
||||||
|
}
|
||||||
|
// only proxy read requests
|
||||||
|
if (this.method !== 'GET' && this.method !== 'HEAD') {
|
||||||
|
return yield next;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pathname = this.path;
|
||||||
|
let match;
|
||||||
|
for (let i = 0; i < proxyUrls.length; i++) {
|
||||||
|
match = proxyUrls[i].test(pathname);
|
||||||
|
if (match) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!match) {
|
||||||
|
return yield next;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = redirectUrl + this.url;
|
||||||
|
debug('proxy to %s', url);
|
||||||
|
this.redirect(url);
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,57 +1,45 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - middleware/publishable.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const util = require('util');
|
||||||
* Module dependencies.
|
const config = require('../config');
|
||||||
*/
|
const debug = require('debug')('cnpmjs.org:middlewares/publishable');
|
||||||
|
|
||||||
var util = require('util');
|
module.exports = function* publishable(next) {
|
||||||
var config = require('../config');
|
// admins always can publish and unpublish
|
||||||
var debug = require('debug')('cnpmjs.org:middlewares/publishable');
|
if (this.user.isAdmin) {
|
||||||
|
return yield next;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = function *publishable(next) {
|
// private mode, normal user can't publish and unpublish
|
||||||
// private mode, only admin user can publish
|
if (config.enablePrivate) {
|
||||||
if (config.enablePrivate && !this.user.isAdmin) {
|
|
||||||
this.status = 403;
|
this.status = 403;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'no_perms',
|
error: 'no_perms',
|
||||||
reason: 'Private mode enable, only admin can publish this module'
|
reason: 'Private mode enable, only admin can publish this module',
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public mode, all user have permission to publish
|
// public mode, normal user have permission to publish `scoped package`
|
||||||
// but if `config.scopes` exist, only can publish with scopes in `config.scope`
|
// and only can publish with scopes in `ctx.user.scopes`, default is `config.scopes`
|
||||||
// if `config.forcePublishWithScope` set to true, only admins can publish without scope
|
|
||||||
|
|
||||||
var name = this.params.name || this.params[0];
|
const name = this.params.name || this.params[0];
|
||||||
|
|
||||||
// check if is private package list in config
|
// check if is private package list in config
|
||||||
if (config.privatePackages && config.privatePackages.indexOf(name) !== -1) {
|
if (config.privatePackages && config.privatePackages.indexOf(name) !== -1) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// scope
|
// scoped module
|
||||||
if (name[0] === '@') {
|
if (name[0] === '@') {
|
||||||
if (checkScope(name, this)) {
|
if (checkScope(name, this)) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// none-scope
|
// none-scope
|
||||||
if (checkNoneScope(this)) {
|
assertNoneScope(name, this);
|
||||||
return yield* next;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,13 +52,13 @@ function checkScope(name, ctx) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var scope = name.split('/')[0];
|
const scope = name.split('/')[0];
|
||||||
if (ctx.user.scopes.indexOf(scope) === -1) {
|
if (ctx.user.scopes.indexOf(scope) === -1) {
|
||||||
debug('assert scope %s error', name);
|
debug('assert scope %s error', name);
|
||||||
ctx.status = 400;
|
ctx.status = 400;
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
error: 'invalid scope',
|
error: 'invalid scope',
|
||||||
reason: util.format('scope %s not match legal scopes: %s', scope, ctx.user.scopes.join(', '))
|
reason: util.format('scope %s not match legal scopes: %s', scope, ctx.user.scopes.join(', ')),
|
||||||
};
|
};
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -82,21 +70,18 @@ function checkScope(name, ctx) {
|
|||||||
* check if user have permission to publish without scope
|
* check if user have permission to publish without scope
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function checkNoneScope(ctx) {
|
function assertNoneScope(name, ctx) {
|
||||||
if (!config.scopes
|
|
||||||
|| !config.scopes.length
|
|
||||||
|| !config.forcePublishWithScope) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// only admins can publish or unpublish non-scope modules
|
|
||||||
if (ctx.user.isAdmin) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.status = 403;
|
ctx.status = 403;
|
||||||
|
if (ctx.user.scopes.length === 0) {
|
||||||
|
ctx.body = {
|
||||||
|
error: 'no_perms',
|
||||||
|
reason: 'can\'t publish non-scoped package, please set `config.scopes`',
|
||||||
|
};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
error: 'no_perms',
|
error: 'no_perms',
|
||||||
reason: 'only allow publish with ' + ctx.user.scopes.join(', ') + ' scope(s)'
|
reason: 'only allow publish with ' + ctx.user.scopes.join(', ') + ' scope(s)',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function* notFound(next) {
|
module.exports = function* notFound(next) {
|
||||||
yield* next;
|
yield next;
|
||||||
|
|
||||||
if (this.status && this.status !== 404) {
|
if (this.status && this.status !== 404) {
|
||||||
return;
|
return;
|
||||||
@@ -27,6 +27,6 @@ module.exports = function* notFound(next) {
|
|||||||
this.status = 404;
|
this.status = 404;
|
||||||
this.body = {
|
this.body = {
|
||||||
error: 'not_found',
|
error: 'not_found',
|
||||||
reason: 'document not found'
|
reason: 'document not found',
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,29 +1,16 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - middleware/static.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const path = require('path');
|
||||||
* Module dependencies.
|
const middlewares = require('koa-middlewares');
|
||||||
*/
|
const config = require('../config');
|
||||||
|
|
||||||
var path = require('path');
|
const staticDir = path.join(path.dirname(__dirname), 'public');
|
||||||
var middlewares = require('koa-middlewares');
|
|
||||||
var config = require('../config');
|
|
||||||
|
|
||||||
var staticDir = path.join(path.dirname(__dirname), 'public');
|
|
||||||
|
|
||||||
module.exports = middlewares.staticCache(staticDir, {
|
module.exports = middlewares.staticCache(staticDir, {
|
||||||
buffer: config.debug ? false : true,
|
buffer: !config.debug,
|
||||||
maxAge: config.debug ? 0 : 60 * 60 * 24 * 7,
|
maxAge: config.debug ? 0 : 60 * 60 * 24 * 7,
|
||||||
alas: {
|
alias: {
|
||||||
'/favicon.ico': '/favicon.png'
|
'/favicon.ico': '/favicon.png',
|
||||||
}
|
},
|
||||||
|
gzip: config.enableCompress,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,49 +1,38 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - middleware/sync_by_install.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const config = require('../config');
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var config = require('../config');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this.allowSync - allow sync triggle by cnpm install
|
* {Boolean} this.allowSync - allow sync triggle by cnpm install
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function* syncByInstall(next) {
|
module.exports = function* syncByInstall(next) {
|
||||||
this.allowSync = false;
|
this.allowSync = false;
|
||||||
if (!config.syncByInstall || !config.enablePrivate) {
|
if (!config.syncByInstall) {
|
||||||
// only config.enablePrivate should enable sync on install
|
// only config.enablePrivate should enable sync on install
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
// request not by node, consider it request from web
|
// request not by node, consider it request from web, don't sync
|
||||||
var ua = this.get('user-agent');
|
const ua = this.get('user-agent');
|
||||||
if (!ua || ua.indexOf('node') < 0) {
|
if (!ua || ua.indexOf('node') < 0) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if request with `/xxx?write=true`, meaning the read request using for write
|
// if request with `/xxx?write=true`, meaning the read request using for write, don't sync
|
||||||
if (this.query.write) {
|
if (this.query.write) {
|
||||||
return yield* next;
|
return yield next;
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = this.params.name || this.params[0];
|
const name = this.params.name || this.params[0];
|
||||||
|
|
||||||
// scoped package dont sync
|
// private scoped package don't sync
|
||||||
if (name && name[0] === '@') {
|
if (name && name[0] === '@') {
|
||||||
return yield* next;
|
const scope = name.split('/')[0];
|
||||||
|
if (config.scopes.indexOf(scope) >= 0) {
|
||||||
|
return yield next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.allowSync = true;
|
this.allowSync = true;
|
||||||
yield* next;
|
yield next;
|
||||||
};
|
};
|
||||||
|
|||||||
14
middleware/unpublishable.js
Normal file
14
middleware/unpublishable.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = function* unpublishable(next) {
|
||||||
|
// only admin user can unpublish
|
||||||
|
if (!this.user.isAdmin) {
|
||||||
|
this.status = 403;
|
||||||
|
this.body = {
|
||||||
|
error: 'no_perms',
|
||||||
|
reason: 'Only administrators can unpublish module',
|
||||||
|
};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
yield next;
|
||||||
|
};
|
||||||
@@ -1,23 +1,9 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - middleware/web_not_found.js
|
|
||||||
*
|
|
||||||
* Copyright(c) cnpmjs.org and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
const debug = require('debug')('cnpmjs.org:middleware:web_not_found');
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var debug = require('debug')('cnpmjs.org:middleware:web_not_found');
|
|
||||||
|
|
||||||
module.exports = function* notFound(next) {
|
module.exports = function* notFound(next) {
|
||||||
yield* next;
|
yield next;
|
||||||
|
|
||||||
if (this.status && this.status !== 404) {
|
if (this.status && this.status !== 404) {
|
||||||
return;
|
return;
|
||||||
@@ -26,7 +12,7 @@ module.exports = function* notFound(next) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var m = /^\/([\w\-\.]+)\/?$/.exec(this.path);
|
let m = /^\/([\w\-\.]+)\/?$/.exec(this.path);
|
||||||
if (!m) {
|
if (!m) {
|
||||||
// scoped packages
|
// scoped packages
|
||||||
m = /^\/(@[\w\-\.]+\/[\w\-\.]+)$/.exec(this.path);
|
m = /^\/(@[\w\-\.]+\/[\w\-\.]+)$/.exec(this.path);
|
||||||
@@ -38,16 +24,16 @@ module.exports = function* notFound(next) {
|
|||||||
|
|
||||||
// package not found
|
// package not found
|
||||||
m = /\/package\/([\w\-\_\.]+)\/?$/.exec(this.url);
|
m = /\/package\/([\w\-\_\.]+)\/?$/.exec(this.url);
|
||||||
var name = null;
|
let name = null;
|
||||||
var title = '404: Page Not Found';
|
let title = '404: Page Not Found';
|
||||||
if (m) {
|
if (m) {
|
||||||
name = m[1];
|
name = m[1];
|
||||||
title = name + ' Not Found';
|
title = name + ' Not Found';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.status = 404;
|
this.status = 404;
|
||||||
yield* this.render('404', {
|
yield this.render('404', {
|
||||||
title: title,
|
title,
|
||||||
name: name
|
name,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,32 +1,18 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - models/_module_maintainer_class_methods.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list all module names by user
|
* list all module names by user
|
||||||
* @param {String} user
|
* @param {String} user
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.listModuleNamesByUser = function* (user) {
|
exports.listModuleNamesByUser = function* (user) {
|
||||||
var rows = yield this.findAll({
|
const rows = yield this.findAll({
|
||||||
attributrs: ['name'],
|
attributrs: [ 'name' ],
|
||||||
where: {
|
where: {
|
||||||
user: user
|
user,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
return rows.map(function (row) {
|
return rows.map(function(row) {
|
||||||
return row.name;
|
return row.name;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -37,13 +23,13 @@ exports.listModuleNamesByUser = function* (user) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
exports.listMaintainers = function* (name) {
|
exports.listMaintainers = function* (name) {
|
||||||
var rows = yield this.findAll({
|
const rows = yield this.findAll({
|
||||||
attributrs: ['user'],
|
attributrs: [ 'user' ],
|
||||||
where: {
|
where: {
|
||||||
name: name
|
name,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
return rows.map(function (row) {
|
return rows.map(function(row) {
|
||||||
return row.user;
|
return row.user;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -55,16 +41,16 @@ exports.listMaintainers = function* (name) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
exports.addMaintainer = function* (name, user) {
|
exports.addMaintainer = function* (name, user) {
|
||||||
var row = yield this.find({
|
let row = yield this.find({
|
||||||
where: {
|
where: {
|
||||||
user: user,
|
user,
|
||||||
name: name
|
name,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
if (!row) {
|
if (!row) {
|
||||||
row = yield this.build({
|
row = yield this.build({
|
||||||
user: user,
|
user,
|
||||||
name: name
|
name,
|
||||||
}).save();
|
}).save();
|
||||||
}
|
}
|
||||||
return row;
|
return row;
|
||||||
@@ -77,7 +63,7 @@ exports.addMaintainer = function* (name, user) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
exports.addMaintainers = function* (name, users) {
|
exports.addMaintainers = function* (name, users) {
|
||||||
return yield users.map(function (user) {
|
return yield users.map(function(user) {
|
||||||
return this.addMaintainer(name, user);
|
return this.addMaintainer(name, user);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
};
|
};
|
||||||
@@ -91,16 +77,16 @@ exports.addMaintainers = function* (name, users) {
|
|||||||
exports.removeMaintainers = function* (name, users) {
|
exports.removeMaintainers = function* (name, users) {
|
||||||
// removeMaintainers(name, oneUserName)
|
// removeMaintainers(name, oneUserName)
|
||||||
if (typeof users === 'string') {
|
if (typeof users === 'string') {
|
||||||
users = [users];
|
users = [ users ];
|
||||||
}
|
}
|
||||||
if (users.length === 0) {
|
if (users.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
yield this.destroy({
|
yield this.destroy({
|
||||||
where: {
|
where: {
|
||||||
name: name,
|
name,
|
||||||
user: users,
|
user: users,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -112,8 +98,8 @@ exports.removeMaintainers = function* (name, users) {
|
|||||||
exports.removeAllMaintainers = function* (name) {
|
exports.removeAllMaintainers = function* (name) {
|
||||||
yield this.destroy({
|
yield this.destroy({
|
||||||
where: {
|
where: {
|
||||||
name: name
|
name,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -131,17 +117,17 @@ exports.updateMaintainers = function* (name, users) {
|
|||||||
if (users.length === 0) {
|
if (users.length === 0) {
|
||||||
return {
|
return {
|
||||||
add: [],
|
add: [],
|
||||||
remove: []
|
remove: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
var exists = yield* this.listMaintainers(name);
|
const exists = yield this.listMaintainers(name);
|
||||||
|
|
||||||
var addUsers = users.filter(function (username) {
|
const addUsers = users.filter(function(username) {
|
||||||
// add user which in `users` but do not in `exists`
|
// add user which in `users` but do not in `exists`
|
||||||
return exists.indexOf(username) === -1;
|
return exists.indexOf(username) === -1;
|
||||||
});
|
});
|
||||||
|
|
||||||
var removeUsers = exists.filter(function (username) {
|
const removeUsers = exists.filter(function(username) {
|
||||||
// remove user which in `exists` by not in `users`
|
// remove user which in `exists` by not in `users`
|
||||||
return users.indexOf(username) === -1;
|
return users.indexOf(username) === -1;
|
||||||
});
|
});
|
||||||
@@ -153,7 +139,6 @@ exports.updateMaintainers = function* (name, users) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
add: addUsers,
|
add: addUsers,
|
||||||
remove: removeUsers
|
remove: removeUsers,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - models/dist_dir.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
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',
|
|
||||||
`name` varchar(200) NOT NULL COMMENT 'dir name',
|
|
||||||
`parent` varchar(200) NOT NULL COMMENT 'parent dir' DEFAULT '/',
|
|
||||||
`date` varchar(20) COMMENT '02-May-2014 01:06',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `dist_dir_parent_name` (`parent`, `name`),
|
|
||||||
KEY `dist_dir_gmt_modified` (`gmt_modified`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='dist dir info';
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
|
||||||
return sequelize.define('DistDir', {
|
|
||||||
name: {
|
|
||||||
type: DataTypes.STRING(200),
|
|
||||||
allowNull: false,
|
|
||||||
comment: 'dir name',
|
|
||||||
},
|
|
||||||
parent: {
|
|
||||||
type: DataTypes.STRING(200),
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: '/',
|
|
||||||
comment: 'parent dir',
|
|
||||||
},
|
|
||||||
date: {
|
|
||||||
type: DataTypes.STRING(20),
|
|
||||||
allowNull: false,
|
|
||||||
comment: '02-May-2014 01:06'
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
tableName: 'dist_dir',
|
|
||||||
comment: 'dist dir info',
|
|
||||||
indexes: [
|
|
||||||
{
|
|
||||||
unique: true,
|
|
||||||
fields: ['parent', 'name']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fields: ['gmt_modified']
|
|
||||||
}
|
|
||||||
],
|
|
||||||
classMethods: {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - models/dist_file.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
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',
|
|
||||||
`name` varchar(100) NOT NULL COMMENT 'file name',
|
|
||||||
`parent` varchar(200) NOT NULL COMMENT 'parent dir' DEFAULT '/',
|
|
||||||
`date` varchar(20) COMMENT '02-May-2014 01:06',
|
|
||||||
`size` int(10) unsigned NOT NULL COMMENT 'file size' DEFAULT '0',
|
|
||||||
`sha1` varchar(40) COMMENT 'sha1 hex value',
|
|
||||||
`url` varchar(2048),
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `dist_file_parent_name` (`parent`, `name`),
|
|
||||||
KEY `dist_file_gmt_modified` (`gmt_modified`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='dist file info';
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
|
||||||
return sequelize.define('DistFile', {
|
|
||||||
name: {
|
|
||||||
type: DataTypes.STRING(200),
|
|
||||||
allowNull: false,
|
|
||||||
comment: 'dir name',
|
|
||||||
},
|
|
||||||
parent: {
|
|
||||||
type: DataTypes.STRING(200),
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: '/',
|
|
||||||
comment: 'parent dir',
|
|
||||||
},
|
|
||||||
date: {
|
|
||||||
type: DataTypes.STRING(20),
|
|
||||||
allowNull: false,
|
|
||||||
comment: '02-May-2014 01:06'
|
|
||||||
},
|
|
||||||
size: {
|
|
||||||
type: DataTypes.INTEGER(10).UNSIGNED,
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: 0,
|
|
||||||
comment: 'file size'
|
|
||||||
},
|
|
||||||
sha1: {
|
|
||||||
type: DataTypes.STRING(40),
|
|
||||||
allowNull: false,
|
|
||||||
comment: 'sha1 hex value'
|
|
||||||
},
|
|
||||||
url: {
|
|
||||||
type: DataTypes.STRING(2048),
|
|
||||||
allowNull: false
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
tableName: 'dist_file',
|
|
||||||
comment: 'dist file info',
|
|
||||||
indexes: [
|
|
||||||
{
|
|
||||||
unique: true,
|
|
||||||
fields: ['parent', 'name']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fields: ['gmt_modified']
|
|
||||||
}
|
|
||||||
],
|
|
||||||
classMethods: {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@@ -1,59 +1,263 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - models/download_total.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// CREATE TABLE IF NOT EXISTS `download_total` (
|
// CREATE TABLE IF NOT EXISTS `downloads` (
|
||||||
// `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
|
// `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
|
||||||
// `gmt_create` datetime NOT NULL COMMENT 'create time',
|
// `gmt_create` datetime NOT NULL COMMENT 'create time',
|
||||||
// `gmt_modified` datetime NOT NULL COMMENT 'modified time',
|
// `gmt_modified` datetime NOT NULL COMMENT 'modified time',
|
||||||
// `date` varchar(10) NOT NULL COMMENT 'YYYY-MM-DD format',
|
|
||||||
// `name` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'module name',
|
// `name` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'module name',
|
||||||
// `count` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT 'download count',
|
// `date` int unsigned NOT NULL COMMENT 'YYYYMM format',
|
||||||
|
// `d01` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '01 download count',
|
||||||
|
// `d02` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '02 download count',
|
||||||
|
// `d03` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '03 download count',
|
||||||
|
// `d04` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '04 download count',
|
||||||
|
// `d05` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '05 download count',
|
||||||
|
// `d06` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '06 download count',
|
||||||
|
// `d07` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '07 download count',
|
||||||
|
// `d08` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '08 download count',
|
||||||
|
// `d09` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '09 download count',
|
||||||
|
// `d10` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '10 download count',
|
||||||
|
// `d11` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '11 download count',
|
||||||
|
// `d12` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '12 download count',
|
||||||
|
// `d13` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '13 download count',
|
||||||
|
// `d14` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '14 download count',
|
||||||
|
// `d15` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '15 download count',
|
||||||
|
// `d16` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '16 download count',
|
||||||
|
// `d17` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '17 download count',
|
||||||
|
// `d18` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '18 download count',
|
||||||
|
// `d19` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '19 download count',
|
||||||
|
// `d20` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '20 download count',
|
||||||
|
// `d21` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '21 download count',
|
||||||
|
// `d22` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '22 download count',
|
||||||
|
// `d23` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '23 download count',
|
||||||
|
// `d24` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '24 download count',
|
||||||
|
// `d25` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '25 download count',
|
||||||
|
// `d26` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '26 download count',
|
||||||
|
// `d27` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '27 download count',
|
||||||
|
// `d28` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '28 download count',
|
||||||
|
// `d29` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '29 download count',
|
||||||
|
// `d30` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '30 download count',
|
||||||
|
// `d31` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '31 download count',
|
||||||
// PRIMARY KEY (`id`),
|
// PRIMARY KEY (`id`),
|
||||||
// UNIQUE KEY `download_total_date_name` (`date`, `name`)
|
// UNIQUE KEY `name_date` (`name`, `date`)
|
||||||
|
// KEY `date` (`date`)
|
||||||
// ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module download total info';
|
// ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module download total info';
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function(sequelize, DataTypes) {
|
||||||
return sequelize.define('DownloadTotal', {
|
return sequelize.define('DownloadTotal', {
|
||||||
date: {
|
|
||||||
type: DataTypes.STRING(10),
|
|
||||||
allowNull: false,
|
|
||||||
comment: 'YYYY-MM-DD format',
|
|
||||||
},
|
|
||||||
name: {
|
name: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
comment: 'module name',
|
comment: 'module name',
|
||||||
},
|
},
|
||||||
count: {
|
date: {
|
||||||
type: DataTypes.BIGINT(20).UNSIGNED,
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
comment: 'YYYYMM format',
|
||||||
|
},
|
||||||
|
d01: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: 0,
|
defaultValue: 0,
|
||||||
comment: 'download count',
|
comment: '01 download count',
|
||||||
}
|
},
|
||||||
|
d02: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '02 download count',
|
||||||
|
},
|
||||||
|
d03: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '03 download count',
|
||||||
|
},
|
||||||
|
d04: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '04 download count',
|
||||||
|
},
|
||||||
|
d05: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '05 download count',
|
||||||
|
},
|
||||||
|
d06: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '06 download count',
|
||||||
|
},
|
||||||
|
d07: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '07 download count',
|
||||||
|
},
|
||||||
|
d08: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '08 download count',
|
||||||
|
},
|
||||||
|
d09: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '09 download count',
|
||||||
|
},
|
||||||
|
d10: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '10 download count',
|
||||||
|
},
|
||||||
|
d11: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '11 download count',
|
||||||
|
},
|
||||||
|
d12: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '12 download count',
|
||||||
|
},
|
||||||
|
d13: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '13 download count',
|
||||||
|
},
|
||||||
|
d14: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '14 download count',
|
||||||
|
},
|
||||||
|
d15: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '15 download count',
|
||||||
|
},
|
||||||
|
d16: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '16 download count',
|
||||||
|
},
|
||||||
|
d17: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '17 download count',
|
||||||
|
},
|
||||||
|
d18: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '18 download count',
|
||||||
|
},
|
||||||
|
d19: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '19 download count',
|
||||||
|
},
|
||||||
|
d20: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '20 download count',
|
||||||
|
},
|
||||||
|
d21: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '21 download count',
|
||||||
|
},
|
||||||
|
d22: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '22 download count',
|
||||||
|
},
|
||||||
|
d23: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '23 download count',
|
||||||
|
},
|
||||||
|
d24: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '24 download count',
|
||||||
|
},
|
||||||
|
d25: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '25 download count',
|
||||||
|
},
|
||||||
|
d26: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '26 download count',
|
||||||
|
},
|
||||||
|
d27: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '27 download count',
|
||||||
|
},
|
||||||
|
d28: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '28 download count',
|
||||||
|
},
|
||||||
|
d29: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '29 download count',
|
||||||
|
},
|
||||||
|
d30: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '30 download count',
|
||||||
|
},
|
||||||
|
d31: {
|
||||||
|
type: DataTypes.BIGINT(20),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: '31 download count',
|
||||||
|
},
|
||||||
}, {
|
}, {
|
||||||
tableName: 'download_total',
|
tableName: 'downloads',
|
||||||
comment: 'module download total info',
|
comment: 'module download total info',
|
||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
unique: true,
|
unique: true,
|
||||||
fields: ['date', 'name']
|
fields: [ 'name', 'date' ],
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
fields: [ 'date' ],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
classMethods: {
|
classMethods: {
|
||||||
|
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
/**!
|
/**!
|
||||||
* cnpmjs.org - models/index.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
* Copyright(c) fengmk2 and other contributors.
|
||||||
* MIT Licensed
|
* MIT Licensed
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
@@ -14,15 +12,15 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var path = require('path');
|
const path = require('path');
|
||||||
var sequelize = require('../common/sequelize');
|
const sequelize = require('../common/sequelize');
|
||||||
|
|
||||||
function load(name) {
|
function load(name) {
|
||||||
return sequelize.import(path.join(__dirname, name));
|
return sequelize.import(path.join(__dirname, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sequelize: sequelize,
|
sequelize,
|
||||||
Module: load('module'),
|
Module: load('module'),
|
||||||
ModuleLog: load('module_log'),
|
ModuleLog: load('module_log'),
|
||||||
ModuleStar: load('module_star'),
|
ModuleStar: load('module_star'),
|
||||||
@@ -36,14 +34,17 @@ module.exports = {
|
|||||||
User: load('user'),
|
User: load('user'),
|
||||||
Total: load('total'),
|
Total: load('total'),
|
||||||
DownloadTotal: load('download_total'),
|
DownloadTotal: load('download_total'),
|
||||||
DistFile: load('dist_file'),
|
|
||||||
DistDir: load('dist_dir'),
|
|
||||||
|
|
||||||
query: function* (sql, args) {
|
* query(sql, args) {
|
||||||
return yield this.sequelize.query(sql, null, {raw: true}, args);
|
const options = { replacements: args };
|
||||||
|
const data = yield this.sequelize.query(sql, options);
|
||||||
|
if (/select /i.test(sql)) {
|
||||||
|
return data[0];
|
||||||
|
}
|
||||||
|
return data[1];
|
||||||
},
|
},
|
||||||
queryOne: function* (sql, args) {
|
* queryOne(sql, args) {
|
||||||
var rows = yield* this.query(sql, args);
|
const rows = yield this.query(sql, args);
|
||||||
return rows && rows[0];
|
return rows && rows[0];
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,22 +14,33 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var config = require('../config');
|
const config = require('../config');
|
||||||
|
|
||||||
config.database.logging = console.log;
|
config.database.logging = console.log;
|
||||||
|
|
||||||
// $ node --harmony models/init_script.js <force> <dialect>
|
// $ node --harmony models/init_script.js <force> <dialect> <port> <username>
|
||||||
var force = process.argv[2] === 'true';
|
const force = process.argv[2] === 'true';
|
||||||
var dialect = process.argv[3];
|
const dialect = process.argv[3];
|
||||||
if (dialect) {
|
if (dialect) {
|
||||||
config.database.dialect = dialect;
|
config.database.dialect = dialect;
|
||||||
}
|
}
|
||||||
|
const port = process.argv[4];
|
||||||
|
if (port) {
|
||||||
|
config.database.port = parseInt(port);
|
||||||
|
}
|
||||||
|
const username = process.argv[5];
|
||||||
|
if (username) {
|
||||||
|
config.database.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
var models = require('./');
|
const models = require('./');
|
||||||
|
|
||||||
models.sequelize.sync({ force: force })
|
models.sequelize.sync({
|
||||||
.then(function () {
|
force,
|
||||||
models.Total.init(function (err) {
|
logging: console.log,
|
||||||
|
})
|
||||||
|
.then(function() {
|
||||||
|
models.Total.init(function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('[models/init_script.js] sequelize init fail');
|
console.error('[models/init_script.js] sequelize init fail');
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@@ -41,8 +52,8 @@ models.sequelize.sync({ force: force })
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function(err) {
|
||||||
console.error('[models/init_script.js] sequelize sync fail');
|
console.error('[models/init_script.js] sequelize sync fail');
|
||||||
console.error(err);
|
console.error(err);
|
||||||
throw err;
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,21 +1,5 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - models/module.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var utils = require('./utils');
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
CREATE TABLE IF NOT EXISTS `module` (
|
CREATE TABLE IF NOT EXISTS `module` (
|
||||||
`id` INTEGER NOT NULL auto_increment ,
|
`id` INTEGER NOT NULL auto_increment ,
|
||||||
@@ -40,22 +24,22 @@ CREATE INDEX `module_publish_time` ON `module` (`publish_time`);
|
|||||||
CREATE INDEX `module_author` ON `module` (`author`);
|
CREATE INDEX `module_author` ON `module` (`author`);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function(sequelize, DataTypes) {
|
||||||
return sequelize.define('Module', {
|
return sequelize.define('Module', {
|
||||||
author: {
|
author: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
comment: 'first maintainer name'
|
comment: 'first maintainer name',
|
||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
comment: 'module name'
|
comment: 'module name',
|
||||||
},
|
},
|
||||||
version: {
|
version: {
|
||||||
type: DataTypes.STRING(30),
|
type: DataTypes.STRING(30),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
comment: 'module version'
|
comment: 'module version',
|
||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
type: DataTypes.LONGTEXT,
|
type: DataTypes.LONGTEXT,
|
||||||
@@ -73,38 +57,38 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
allowNull: true,
|
allowNull: true,
|
||||||
},
|
},
|
||||||
dist_size: {
|
dist_size: {
|
||||||
type: DataTypes.INTEGER.UNSIGNED,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: 0,
|
defaultValue: 0,
|
||||||
},
|
},
|
||||||
publish_time: {
|
publish_time: {
|
||||||
type: DataTypes.BIGINT(20).UNSIGNED,
|
type: DataTypes.BIGINT(20),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
}
|
},
|
||||||
}, {
|
}, {
|
||||||
tableName: 'module',
|
tableName: 'module',
|
||||||
comment: 'module info',
|
comment: 'module info',
|
||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
unique: true,
|
unique: true,
|
||||||
fields: ['name', 'version']
|
fields: [ 'name', 'version' ],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fields: ['gmt_modified']
|
fields: [ 'gmt_modified' ],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fields: ['publish_time']
|
fields: [ 'publish_time' ],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fields: ['author']
|
fields: [ 'author' ],
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
classMethods: {
|
classMethods: {
|
||||||
findByNameAndVersion: function* (name, version) {
|
* findByNameAndVersion(name, version) {
|
||||||
return yield this.find({
|
return yield this.find({
|
||||||
where: { name: name, version: version }
|
where: { name, version },
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ CREATE TABLE IF NOT EXISTS `module_deps` (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module deps';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module deps';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function(sequelize, DataTypes) {
|
||||||
return sequelize.define('ModuleDependency', {
|
return sequelize.define('ModuleDependency', {
|
||||||
name: {
|
name: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
@@ -36,8 +36,8 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
dependent: {
|
dependent: {
|
||||||
field: 'deps',
|
field: 'deps',
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
comment: '`name` is depended by `deps`. `deps` == depend => `name`'
|
comment: '`name` is depended by `deps`. `deps` == depend => `name`',
|
||||||
}
|
},
|
||||||
}, {
|
}, {
|
||||||
tableName: 'module_deps',
|
tableName: 'module_deps',
|
||||||
comment: 'module deps',
|
comment: 'module deps',
|
||||||
@@ -46,13 +46,13 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
unique: true,
|
unique: true,
|
||||||
fields: ['name', 'deps']
|
fields: [ 'name', 'deps' ],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fields: ['deps']
|
fields: [ 'deps' ],
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
classMethods: {
|
classMethods: {
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS `module_keyword` (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module keyword';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module keyword';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function(sequelize, DataTypes) {
|
||||||
return sequelize.define('ModuleKeyword', {
|
return sequelize.define('ModuleKeyword', {
|
||||||
keyword: {
|
keyword: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
@@ -41,7 +41,7 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
description: {
|
description: {
|
||||||
type: DataTypes.LONGTEXT,
|
type: DataTypes.LONGTEXT,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
}
|
},
|
||||||
}, {
|
}, {
|
||||||
tableName: 'module_keyword',
|
tableName: 'module_keyword',
|
||||||
comment: 'module keyword',
|
comment: 'module keyword',
|
||||||
@@ -49,21 +49,21 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
unique: true,
|
unique: true,
|
||||||
fields: ['keyword', 'name']
|
fields: [ 'keyword', 'name' ],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fields: ['name']
|
fields: [ 'name' ],
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
classMethods: {
|
classMethods: {
|
||||||
findByKeywordAndName: function* (keyword, name) {
|
* findByKeywordAndName(keyword, name) {
|
||||||
return yield this.find({
|
return yield this.find({
|
||||||
where: {
|
where: {
|
||||||
keyword: keyword,
|
keyword,
|
||||||
name: name
|
name,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ CREATE TABLE IF NOT EXISTS `module_log` (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module sync log';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module sync log';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function(sequelize, DataTypes) {
|
||||||
return sequelize.define('ModuleLog', {
|
return sequelize.define('ModuleLog', {
|
||||||
username: {
|
username: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
comment: 'user name'
|
comment: 'user name',
|
||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
@@ -40,17 +40,17 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
comment: 'module name',
|
comment: 'module name',
|
||||||
},
|
},
|
||||||
log: {
|
log: {
|
||||||
type: DataTypes.LONGTEXT
|
type: DataTypes.LONGTEXT,
|
||||||
}
|
},
|
||||||
}, {
|
}, {
|
||||||
tableName: 'module_log',
|
tableName: 'module_log',
|
||||||
comment: 'module sync log',
|
comment: 'module sync log',
|
||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
fields: ['name']
|
fields: [ 'name' ],
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
classMethods: {
|
classMethods: {
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,18 +26,18 @@ CREATE TABLE IF NOT EXISTS `module_maintainer` (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='private module maintainers';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='private module maintainers';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function(sequelize, DataTypes) {
|
||||||
return sequelize.define('ModuleMaintainer', {
|
return sequelize.define('ModuleMaintainer', {
|
||||||
user: {
|
user: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
comment: 'user name'
|
comment: 'user name',
|
||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
comment: 'module name',
|
comment: 'module name',
|
||||||
}
|
},
|
||||||
}, {
|
}, {
|
||||||
tableName: 'module_maintainer',
|
tableName: 'module_maintainer',
|
||||||
comment: 'private module maintainers',
|
comment: 'private module maintainers',
|
||||||
@@ -45,11 +45,11 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
unique: true,
|
unique: true,
|
||||||
fields: ['user', 'name']
|
fields: [ 'user', 'name' ],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fields: ['name']
|
fields: [ 'name' ],
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
classMethods: require('./_module_maintainer_class_methods'),
|
classMethods: require('./_module_maintainer_class_methods'),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,18 +26,18 @@ CREATE TABLE IF NOT EXISTS `module_star` (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module star';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module star';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function(sequelize, DataTypes) {
|
||||||
return sequelize.define('ModuleStar', {
|
return sequelize.define('ModuleStar', {
|
||||||
user: {
|
user: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
comment: 'user name'
|
comment: 'user name',
|
||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
comment: 'module name',
|
comment: 'module name',
|
||||||
}
|
},
|
||||||
}, {
|
}, {
|
||||||
tableName: 'module_star',
|
tableName: 'module_star',
|
||||||
comment: 'module star',
|
comment: 'module star',
|
||||||
@@ -45,13 +45,13 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
unique: true,
|
unique: true,
|
||||||
fields: ['user', 'name']
|
fields: [ 'user', 'name' ],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fields: ['name']
|
fields: [ 'name' ],
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
classMethods: {
|
classMethods: {
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var utils = require('./utils');
|
const utils = require('./utils');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
CREATE TABLE IF NOT EXISTS `module_unpublished` (
|
CREATE TABLE IF NOT EXISTS `module_unpublished` (
|
||||||
@@ -29,7 +29,7 @@ CREATE TABLE IF NOT EXISTS `module_unpublished` (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module unpublished info';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module unpublished info';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function(sequelize, DataTypes) {
|
||||||
return sequelize.define('ModuleUnpublished', {
|
return sequelize.define('ModuleUnpublished', {
|
||||||
name: {
|
name: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
@@ -41,44 +41,47 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
comment: 'base info: tags, time, maintainers, description, versions',
|
comment: 'base info: tags, time, maintainers, description, versions',
|
||||||
get: utils.JSONGetter('package'),
|
get: utils.JSONGetter('package'),
|
||||||
set: utils.JSONSetter('package'),
|
set: utils.JSONSetter('package'),
|
||||||
}
|
},
|
||||||
}, {
|
}, {
|
||||||
tableName: 'module_unpublished',
|
tableName: 'module_unpublished',
|
||||||
comment: 'module unpublished info',
|
comment: 'module unpublished info',
|
||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
unique: true,
|
unique: true,
|
||||||
fields: ['name']
|
fields: [ 'name' ],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fields: ['gmt_modified']
|
fields: [ 'gmt_modified' ],
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
classMethods: {
|
classMethods: {
|
||||||
findByName: function* (name) {
|
* findByName(name) {
|
||||||
return yield this.find({
|
return yield this.find({
|
||||||
where: {
|
where: {
|
||||||
name: name
|
name,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
save: function* (name, pkg) {
|
* save(name, pkg) {
|
||||||
var row = yield this.find({
|
let row = yield this.find({
|
||||||
where: {
|
where: {
|
||||||
name: name
|
name,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
if (row) {
|
if (row) {
|
||||||
row.package = pkg;
|
row.package = pkg;
|
||||||
return yield row.save(['package']);
|
if (row.changed()) {
|
||||||
|
row = yield row.save([ 'package' ]);
|
||||||
|
}
|
||||||
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
row = this.build({
|
row = this.build({
|
||||||
name: name,
|
name,
|
||||||
package: pkg,
|
package: pkg,
|
||||||
});
|
});
|
||||||
return yield row.save();
|
return yield row.save();
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,18 +26,18 @@ CREATE TABLE IF NOT EXISTS `npm_module_maintainer` (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='npm original module maintainers';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='npm original module maintainers';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function(sequelize, DataTypes) {
|
||||||
return sequelize.define('NpmModuleMaintainer', {
|
return sequelize.define('NpmModuleMaintainer', {
|
||||||
user: {
|
user: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
comment: 'user name'
|
comment: 'user name',
|
||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
comment: 'module name',
|
comment: 'module name',
|
||||||
}
|
},
|
||||||
}, {
|
}, {
|
||||||
tableName: 'npm_module_maintainer',
|
tableName: 'npm_module_maintainer',
|
||||||
comment: 'npm original module maintainers',
|
comment: 'npm original module maintainers',
|
||||||
@@ -45,11 +45,11 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
unique: true,
|
unique: true,
|
||||||
fields: ['user', 'name']
|
fields: [ 'user', 'name' ],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fields: ['name']
|
fields: [ 'name' ],
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
classMethods: require('./_module_maintainer_class_methods'),
|
classMethods: require('./_module_maintainer_class_methods'),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ CREATE TABLE IF NOT EXISTS `tag` (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module tag';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module tag';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function(sequelize, DataTypes) {
|
||||||
return sequelize.define('Tag', {
|
return sequelize.define('Tag', {
|
||||||
name: {
|
name: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
@@ -47,26 +47,26 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
comment: 'module version',
|
comment: 'module version',
|
||||||
},
|
},
|
||||||
module_id: {
|
module_id: {
|
||||||
type: DataTypes.BIGINT(20).UNSIGNED,
|
type: DataTypes.BIGINT(20),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
comment: 'module id'
|
comment: 'module id',
|
||||||
}
|
},
|
||||||
}, {
|
}, {
|
||||||
tableName: 'tag',
|
tableName: 'tag',
|
||||||
comment: 'module tag',
|
comment: 'module tag',
|
||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
unique: true,
|
unique: true,
|
||||||
fields: ['name', 'tag']
|
fields: [ 'name', 'tag' ],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fields: ['gmt_modified']
|
fields: [ 'gmt_modified' ],
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
classMethods: {
|
classMethods: {
|
||||||
findByNameAndTag: function* (name, tag) {
|
* findByNameAndTag(name, tag) {
|
||||||
return yield this.find({ where: { name: name, tag: tag } });
|
return yield this.find({ where: { name, tag } });
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,19 +1,5 @@
|
|||||||
/**!
|
|
||||||
* cnpmjs.org - models/total.js
|
|
||||||
*
|
|
||||||
* Copyright(c) fengmk2 and other contributors.
|
|
||||||
* MIT Licensed
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// CREATE TABLE IF NOT EXISTS `total` (
|
// CREATE TABLE IF NOT EXISTS `total` (
|
||||||
// `name` varchar(100) NOT NULL COMMENT 'total name',
|
// `name` varchar(100) NOT NULL COMMENT 'total name',
|
||||||
// `gmt_modified` datetime NOT NULL COMMENT 'modified time',
|
// `gmt_modified` datetime NOT NULL COMMENT 'modified time',
|
||||||
@@ -32,57 +18,57 @@
|
|||||||
// INSERT INTO total(name, gmt_modified) VALUES('total', now())
|
// INSERT INTO total(name, gmt_modified) VALUES('total', now())
|
||||||
// ON DUPLICATE KEY UPDATE gmt_modified=now();
|
// ON DUPLICATE KEY UPDATE gmt_modified=now();
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function(sequelize, DataTypes) {
|
||||||
return sequelize.define('Total', {
|
return sequelize.define('Total', {
|
||||||
name: {
|
name: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
comment: 'total name'
|
comment: 'total name',
|
||||||
},
|
},
|
||||||
module_delete: {
|
module_delete: {
|
||||||
type: DataTypes.BIGINT(20).UNSIGNED,
|
type: DataTypes.BIGINT(20),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: 0,
|
defaultValue: 0,
|
||||||
comment: 'module delete count',
|
comment: 'module delete count',
|
||||||
},
|
},
|
||||||
last_sync_time: {
|
last_sync_time: {
|
||||||
type: DataTypes.BIGINT(20).UNSIGNED,
|
type: DataTypes.BIGINT(20),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: 0,
|
defaultValue: 0,
|
||||||
comment: 'last timestamp sync from official registry',
|
comment: 'last timestamp sync from official registry',
|
||||||
},
|
},
|
||||||
last_exist_sync_time: {
|
last_exist_sync_time: {
|
||||||
type: DataTypes.BIGINT(20).UNSIGNED,
|
type: DataTypes.BIGINT(20),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: 0,
|
defaultValue: 0,
|
||||||
comment: 'last timestamp sync exist packages from official registry',
|
comment: 'last timestamp sync exist packages from official registry',
|
||||||
},
|
},
|
||||||
sync_status: {
|
sync_status: {
|
||||||
type: 'TINYINT',
|
type: DataTypes.INTEGER,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: 0,
|
defaultValue: 0,
|
||||||
comment: 'system sync from official registry status',
|
comment: 'system sync from official registry status',
|
||||||
},
|
},
|
||||||
need_sync_num: {
|
need_sync_num: {
|
||||||
type: DataTypes.INTEGER.UNSIGNED,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: 0,
|
defaultValue: 0,
|
||||||
comment: 'how many packages need to be sync',
|
comment: 'how many packages need to be sync',
|
||||||
},
|
},
|
||||||
success_sync_num: {
|
success_sync_num: {
|
||||||
type: DataTypes.INTEGER.UNSIGNED,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: 0,
|
defaultValue: 0,
|
||||||
comment: 'how many packages sync success at this time',
|
comment: 'how many packages sync success at this time',
|
||||||
},
|
},
|
||||||
fail_sync_num: {
|
fail_sync_num: {
|
||||||
type: DataTypes.INTEGER.UNSIGNED,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: 0,
|
defaultValue: 0,
|
||||||
comment: 'how many packages sync fail at this time',
|
comment: 'how many packages sync fail at this time',
|
||||||
},
|
},
|
||||||
left_sync_num: {
|
left_sync_num: {
|
||||||
type: DataTypes.INTEGER.UNSIGNED,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: 0,
|
defaultValue: 0,
|
||||||
comment: 'how many packages left to be sync',
|
comment: 'how many packages left to be sync',
|
||||||
@@ -97,14 +83,14 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
comment: 'total info',
|
comment: 'total info',
|
||||||
createdAt: false,
|
createdAt: false,
|
||||||
classMethods: {
|
classMethods: {
|
||||||
init: function (callback) {
|
init(callback) {
|
||||||
var that = this;
|
const that = this;
|
||||||
that.find({
|
that.find({
|
||||||
where: { name: 'total' }
|
where: { name: 'total' },
|
||||||
}).then(function (row) {
|
}).then(function(row) {
|
||||||
if (!row) {
|
if (!row) {
|
||||||
that.build({name: 'total'}).save()
|
that.build({ name: 'total' }).save()
|
||||||
.then(function () {
|
.then(function() {
|
||||||
callback();
|
callback();
|
||||||
})
|
})
|
||||||
.catch(callback);
|
.catch(callback);
|
||||||
@@ -112,7 +98,7 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
}
|
}
|
||||||
callback();
|
callback();
|
||||||
}).catch(callback);
|
}).catch(callback);
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
109
models/user.js
109
models/user.js
@@ -14,8 +14,8 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var utility = require('utility');
|
const utility = require('utility');
|
||||||
var utils = require('./utils');
|
const utils = require('./utils');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
CREATE TABLE IF NOT EXISTS `user` (
|
CREATE TABLE IF NOT EXISTS `user` (
|
||||||
@@ -37,7 +37,7 @@ CREATE TABLE IF NOT EXISTS `user` (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='user base info';
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='user base info';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function(sequelize, DataTypes) {
|
||||||
return sequelize.define('User', {
|
return sequelize.define('User', {
|
||||||
name: {
|
name: {
|
||||||
type: DataTypes.STRING(100),
|
type: DataTypes.STRING(100),
|
||||||
@@ -83,62 +83,65 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
allowNull: false,
|
allowNull: false,
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
comment: 'user sync from npm or not, 1: true, other: false',
|
comment: 'user sync from npm or not, 1: true, other: false',
|
||||||
}
|
},
|
||||||
}, {
|
}, {
|
||||||
tableName: 'user',
|
tableName: 'user',
|
||||||
comment: 'user base info',
|
comment: 'user base info',
|
||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
unique: true,
|
unique: true,
|
||||||
fields: ['name']
|
fields: [ 'name' ],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fields: ['gmt_modified']
|
fields: [ 'gmt_modified' ],
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
classMethods: {
|
classMethods: {
|
||||||
// utils
|
// utils
|
||||||
createPasswordSha: function (password, salt) {
|
createPasswordSha(password, salt) {
|
||||||
return utility.sha1(password + salt);
|
return utility.sha1(password + salt);
|
||||||
},
|
},
|
||||||
|
|
||||||
// read
|
// read
|
||||||
auth: function* (name, password) {
|
* auth(name, password) {
|
||||||
var user = yield* this.findByName(name);
|
let user = yield this.findByName(name);
|
||||||
if (user) {
|
if (user) {
|
||||||
var sha = this.createPasswordSha(password, user.salt);
|
const sha = this.createPasswordSha(password, user.salt);
|
||||||
if (user.password_sha !== sha) {
|
if (user.password_sha !== sha) {
|
||||||
user = null;
|
user = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return user;
|
return user;
|
||||||
},
|
},
|
||||||
findByName: function* (name) {
|
* findByName(name) {
|
||||||
return yield this.find({ where: { name: name } });
|
return yield this.find({ where: { name } });
|
||||||
},
|
},
|
||||||
listByNames: function* (names) {
|
* listByNames(names) {
|
||||||
|
if (!names || names.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
return yield this.findAll({
|
return yield this.findAll({
|
||||||
where: {
|
where: {
|
||||||
name: {
|
name: {
|
||||||
in: names
|
in: names,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
search: function* (query, options) {
|
* search(query, options) {
|
||||||
return yield this.findAll({
|
return yield this.findAll({
|
||||||
where: {
|
where: {
|
||||||
name: {
|
name: {
|
||||||
like: query + '%'
|
like: query + '%',
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
limit: options.limit
|
limit: options.limit,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// write
|
// write
|
||||||
saveNpmUser: function* (data) {
|
* saveNpmUser(data) {
|
||||||
var user = yield* this.findByName(data.name);
|
let user = yield this.findByName(data.name);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
user = this.build({
|
user = this.build({
|
||||||
isNpmUser: true,
|
isNpmUser: true,
|
||||||
@@ -152,22 +155,25 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
user.json = data;
|
user.json = data;
|
||||||
user.email = data.email || '';
|
user.email = data.email || '';
|
||||||
user.rev = data._rev || '';
|
user.rev = data._rev || '';
|
||||||
return yield user.save();
|
if (user.changed()) {
|
||||||
|
user = yield user.save();
|
||||||
|
}
|
||||||
|
return user;
|
||||||
},
|
},
|
||||||
saveCustomUser: function* (data) {
|
* saveCustomUser(data) {
|
||||||
var name = data.user.login;
|
const name = data.user.login;
|
||||||
var user = yield* this.findByName(name);
|
let user = yield this.findByName(name);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
user = this.build({
|
user = this.build({
|
||||||
isNpmUser: false,
|
isNpmUser: false,
|
||||||
name: name,
|
name,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var rev = '1-' + data.user.login;
|
const rev = '1-' + data.user.login;
|
||||||
var salt = data.salt || '0';
|
const salt = data.salt || '0';
|
||||||
var passwordSha = data.password_sha || '0';
|
const passwordSha = data.password_sha || '0';
|
||||||
var ip = data.ip || '0';
|
const ip = data.ip || '0';
|
||||||
|
|
||||||
user.isNpmUser = false;
|
user.isNpmUser = false;
|
||||||
user.email = data.user.email;
|
user.email = data.user.email;
|
||||||
@@ -176,52 +182,55 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
user.rev = rev;
|
user.rev = rev;
|
||||||
user.salt = salt;
|
user.salt = salt;
|
||||||
user.password_sha = passwordSha;
|
user.password_sha = passwordSha;
|
||||||
return yield user.save();
|
if (user.changed()) {
|
||||||
|
user = yield user.save();
|
||||||
|
}
|
||||||
|
return user;
|
||||||
},
|
},
|
||||||
|
|
||||||
// add cnpm user
|
// add cnpm user
|
||||||
add: function* (user) {
|
* add(user) {
|
||||||
var roles = user.roles || [];
|
let roles = user.roles || [];
|
||||||
try {
|
try {
|
||||||
roles = JSON.stringify(roles);
|
roles = JSON.stringify(roles);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
roles = '[]';
|
roles = '[]';
|
||||||
}
|
}
|
||||||
var rev = '1-' + utility.md5(JSON.stringify(user));
|
const rev = '1-' + utility.md5(JSON.stringify(user));
|
||||||
|
|
||||||
var row = this.build({
|
const row = this.build({
|
||||||
rev: rev,
|
rev,
|
||||||
name: user.name,
|
name: user.name,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
salt: user.salt,
|
salt: user.salt,
|
||||||
password_sha: user.password_sha,
|
password_sha: user.password_sha,
|
||||||
ip: user.ip,
|
ip: user.ip,
|
||||||
roles: roles,
|
roles,
|
||||||
isNpmUser: false,
|
isNpmUser: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
return yield row.save();
|
return yield row.save();
|
||||||
},
|
},
|
||||||
|
|
||||||
update: function* (user) {
|
* update(user) {
|
||||||
var rev = user.rev || user._rev;
|
const rev = user.rev || user._rev;
|
||||||
var revNo = Number(rev.split('-', 1));
|
let revNo = Number(rev.split('-', 1));
|
||||||
if (!revNo) {
|
if (!revNo) {
|
||||||
var err = new Error(rev + ' format error');
|
const err = new Error(rev + ' format error');
|
||||||
err.name = 'RevFormatError';
|
err.name = 'RevFormatError';
|
||||||
err.data = {user: user};
|
err.data = { user };
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
revNo++;
|
revNo++;
|
||||||
var newRev = revNo + '-' + utility.md5(JSON.stringify(user));
|
const newRev = revNo + '-' + utility.md5(JSON.stringify(user));
|
||||||
var roles = user.roles || [];
|
let roles = user.roles || [];
|
||||||
try {
|
try {
|
||||||
roles = JSON.stringify(roles);
|
roles = JSON.stringify(roles);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
roles = '[]';
|
roles = '[]';
|
||||||
}
|
}
|
||||||
|
|
||||||
var row = yield* this.findByName(user.name);
|
const row = yield this.findByName(user.name);
|
||||||
if (!row) {
|
if (!row) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -234,8 +243,8 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
row.roles = roles;
|
row.roles = roles;
|
||||||
row.isNpmUser = false;
|
row.isNpmUser = false;
|
||||||
|
|
||||||
return yield row.save(['rev', 'email', 'salt', 'password_sha', 'ip', 'roles', 'isNpmUser']);
|
return yield row.save([ 'rev', 'email', 'salt', 'password_sha', 'ip', 'roles', 'isNpmUser' ]);
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user