Compare commits

...

29 Commits

Author SHA1 Message Date
fengmk2
8b29cd8b04 Release 3.0.0-rc.66 2023-03-25 21:41:57 +08:00
elrrrrrrr
6769a46d71 fix: download row create error (#1749)
> 包名超长时,更新下载记录接口会无限重试
* 更新下载记录前,先判断当前包名是否存在

-------------

> When the package name is too long, the update download record
interface will retry indefinitely.

* Check pkg exists, before updating the download record.
2023-03-25 21:40:50 +08:00
fengmk2
cd60a7aa82 Release 3.0.0-rc.65 2023-02-06 14:09:25 +08:00
elrrrrrrr
a289d7dd5e feat: ignore sync private pkg (#1747)
> Ignore sync requests for private pacakges.
* update isLocalModule Logic, follow the #privatePackages field in
config.
2023-02-06 14:08:42 +08:00
fengmk2
922aa8ff1b Release 3.0.0-rc.64 2022-10-31 23:17:24 +08:00
elrrrrrrr
af9f5f7499 feat: add changes delay (#1739)
* 新增 changesDelay 配置,调用 /-/all/changes 接口时默认返回 delay 之前的 changes
* 防止出现 since 和当前时间接近时,changes 异步插入,导致 changes 计算失败的问题
2022-10-31 23:15:56 +08:00
killagu
bc0d1db782 Release 3.0.0-rc.63 2022-08-31 16:01:03 +08:00
elrrrrrrr
1964d66abf feat: remove block version changes (#1737) 2022-08-31 15:41:23 +08:00
killagu
8ac988ae88 Release 3.0.0-rc.62 2022-07-28 16:51:56 +08:00
elrrrrrrr
d8b5c9f7a9 feat: add changes api (#1734) 2022-07-28 16:28:47 +08:00
Ke Wu
4d534cad02 fix: listModulesByUser map error (#1731)
Co-authored-by: 天玎 <tianding.wk@antgroup.com>
2022-06-15 22:05:42 +08:00
fengmk2
53af65c0e9 Release 3.0.0-rc.60 2022-04-28 09:49:00 +08:00
fengmk2
f8bcca1ea0 🐛 FIX: path url maybe encode (#1729) 2022-04-28 09:48:27 +08:00
fengmk2
6c12a040a5 Release 3.0.0-rc.59 2022-04-28 09:26:48 +08:00
fengmk2
8663e215f0 🐛 FIX: Should show sync button on scoped package not exists (#1728)
closes https://github.com/cnpm/cnpmcore/issues/218#issuecomment-1110955986
2022-04-28 09:13:43 +08:00
fengmk2
8573c4a600 📖 DOC: DEPRECATED, please use https://github.com/cnpm/cnpmcore instead 2022-03-27 09:48:55 +08:00
fengmk2
51d1276d2e Release 3.0.0-rc.58 2022-03-20 09:51:14 +08:00
fengmk2
83497f2052 👌 IMPROVE: Return libc field on abbreviated manifests (#1721)
pick from https://github.com/cnpm/cnpmcore/pull/188
2022-03-20 09:49:19 +08:00
AN
1e0f7e06bb 📖 DOC: Modify comments (#1710)
Co-authored-by: Zian502 <yuanzhian@cai-inc.com>
2022-02-16 23:01:46 +08:00
fengmk2
e682e7a0a3 📖 DOC: Update contributors 2022-02-14 00:17:29 +08:00
XXBeii
f52e9c3382 feat: support sync private package from define registry (#1701)
Co-authored-by: wangjx2018 <wangjx2018@chinaunicom.cn>
2022-02-14 00:16:00 +08:00
fossabot
19e5c3def2 chore: Add license scan report and status (#1708)
Signed off by: fossabot <badges@fossa.com>
2022-02-12 01:11:01 +08:00
fengmk2
9f8dca4ac0 refactor: Sync exists package from cnpmcore changes stream (#1707)
closes https://github.com/cnpm/cnpmjs.org/issues/1704
2022-02-12 01:06:45 +08:00
fengmk2
f2c4b9f1c8 📖 DOC: Use git-contributor instead 2022-02-09 22:33:36 +08:00
fengmk2
1b09b2c0db Release 3.0.0-rc.57 2022-02-08 23:18:14 +08:00
fengmk2
ac07b215a7 🐛 FIX: Support new bson logId 2022-02-08 23:17:45 +08:00
fengmk2
52475aab2b Release 3.0.0-rc.56 2022-01-30 00:23:25 +08:00
fengmk2
559d5baccf 📦 NEW: sync web support webDataRemoteRegistry (#1697) 2022-01-29 23:39:37 +08:00
fengmk2
e5c5179e9e 📦 NEW: Support set registry to new cnpmcore registry (#1696)
https://github.com/cnpm/cnpmcore/issues/120
2022-01-28 00:20:23 +08:00
40 changed files with 1113 additions and 175 deletions

View File

@@ -28,7 +28,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [10, 12, 14, 16]
node-version: [14, 16]
os: [ubuntu-latest]
steps:

View File

@@ -1,4 +1,56 @@
3.0.0-rc.66 / 2023-03-25
==================
**features**
* [[`a289d7d`](http://github.com/cnpm/cnpmjs.org/commit/a289d7dd5ec4881e86c6f500c72cab134388782b)] - feat: ignore sync private pkg (#1747) (elrrrrrrr <<elrrrrrrr@gmail.com>>)
* [[`af9f5f7`](http://github.com/cnpm/cnpmjs.org/commit/af9f5f749979d1f389d61e98eab7dfbf639c995b)] - feat: add changes delay (#1739) (elrrrrrrr <<elrrrrrrr@gmail.com>>)
**fixes**
* [[`6769a46`](http://github.com/cnpm/cnpmjs.org/commit/6769a46d71508a24f4e2d4dc14aa4aebd826bf38)] - fix: download row create error (#1749) (elrrrrrrr <<elrrrrrrr@gmail.com>>)
3.0.0-rc.63 / 2022-08-31
==================
**features**
* [[`1964d66`](http://github.com/cnpm/cnpmjs.org/commit/1964d66abf3a78bc97022db2bfd1b88fa2c1fa37)] - feat: remove block version changes (#1737) (elrrrrrrr <<elrrrrrrr@gmail.com>>)
3.0.0-rc.62 / 2022-07-28
==================
**features**
* [[`d8b5c9f`](http://github.com/cnpm/cnpmjs.org/commit/d8b5c9f7a9a4648460415936e492ee0bb9cba9b0)] - feat: add changes api (#1734) (elrrrrrrr <<elrrrrrrr@gmail.com>>)
* [[`f52e9c3`](http://github.com/cnpm/cnpmjs.org/commit/f52e9c3382ef3583a9cac9be5510e11a3ab17b8c)] - feat: support sync private package from define registry (#1701) (XXBeii <<36651530+XXBeii@users.noreply.github.com>>)
* [[`97d501c`](http://github.com/cnpm/cnpmjs.org/commit/97d501c088aee43af30e31aef279b3036a7cc5f7)] - feat: support bug-versions on server (#1684) (fengmk2 <<fengmk2@gmail.com>>)
* [[`3c5bc9d`](http://github.com/cnpm/cnpmjs.org/commit/3c5bc9dc5ef46c567e718705d18edc1f57009b5e)] - feat: support package version block list (#1683) (fengmk2 <<fengmk2@gmail.com>>)
* [[`abc1723`](http://github.com/cnpm/cnpmjs.org/commit/abc1723bef5eb12168d084cc16916998288e879b)] - feat: support dist.integrity (#1677) (fengmk2 <<fengmk2@gmail.com>>)
**fixes**
* [[`4d534ca`](http://github.com/cnpm/cnpmjs.org/commit/4d534cad024f08923b7d4df57d87d14fa96a975a)] - fix: listModulesByUser map error (#1731) (Ke Wu <<gemwuu@163.com>>)
* [[`b7bbf84`](http://github.com/cnpm/cnpmjs.org/commit/b7bbf84ea31b5c15a48edd596bbb87a72f7de595)] - fix: add missing config property for bug-versions (#1685) (fengmk2 <<fengmk2@gmail.com>>)
* [[`74d408d`](http://github.com/cnpm/cnpmjs.org/commit/74d408d006b1c7a08283b178e842ef98f850fcf2)] - fix: database dialect config detect error (#1503) (alsotang <<alsotang@gmail.com>>)
* [[`37ba629`](http://github.com/cnpm/cnpmjs.org/commit/37ba6290284f260230e6d4461311bb8739088191)] - fix: get count missing name (#1674) (Solais <<924615994@qq.com>>)
**others**
* [[`f8bcca1`](http://github.com/cnpm/cnpmjs.org/commit/f8bcca1ea0c0ad952fffd0539b625de69b9099f0)] - 🐛 FIX: path url maybe encode (#1729) (fengmk2 <<fengmk2@gmail.com>>)
* [[`8663e21`](http://github.com/cnpm/cnpmjs.org/commit/8663e215f038b812b74948e28a05b704d5d7780c)] - 🐛 FIX: Should show sync button on scoped package not exists (#1728) (fengmk2 <<fengmk2@gmail.com>>)
* [[`8573c4a`](http://github.com/cnpm/cnpmjs.org/commit/8573c4a600077585681ac1eddcebc4b2abff4f8e)] - 📖 DOC: DEPRECATED, please use https://github.com/cnpm/cnpmcore instead (fengmk2 <<fengmk2@gmail.com>>)
* [[`83497f2`](http://github.com/cnpm/cnpmjs.org/commit/83497f20521dd5016c119500aff0ccb64cf5a929)] - 👌 IMPROVE: Return libc field on abbreviated manifests (#1721) (fengmk2 <<fengmk2@gmail.com>>)
* [[`1e0f7e0`](http://github.com/cnpm/cnpmjs.org/commit/1e0f7e06bb7df40f1dca309b7e8e533130293ab6)] - 📖 DOC: Modify comments (#1710) (AN <<455454007@qq.com>>)
* [[`e682e7a`](http://github.com/cnpm/cnpmjs.org/commit/e682e7a0a39f750c61d7a2a46de862d118e61e73)] - 📖 DOC: Update contributors (fengmk2 <<fengmk2@gmail.com>>)
* [[`19e5c3d`](http://github.com/cnpm/cnpmjs.org/commit/19e5c3def257f4ceab3256a1c9d615d002c5fe49)] - chore: Add license scan report and status (#1708) (fossabot <<badges@fossa.io>>)
* [[`9f8dca4`](http://github.com/cnpm/cnpmjs.org/commit/9f8dca4ac0292ba87c59149972f0f635bd17ec37)] - refactor: Sync exists package from cnpmcore changes stream (#1707) (fengmk2 <<fengmk2@gmail.com>>)
* [[`f2c4b9f`](http://github.com/cnpm/cnpmjs.org/commit/f2c4b9f1c8d0b97b0b1890ac3aec058a99f0b224)] - 📖 DOC: Use git-contributor instead (fengmk2 <<fengmk2@gmail.com>>)
* [[`ac07b21`](http://github.com/cnpm/cnpmjs.org/commit/ac07b215a73f80aa11e9631d3e6c9be4c4db87a2)] - 🐛 FIX: Support new bson logId (fengmk2 <<fengmk2@gmail.com>>)
* [[`559d5ba`](http://github.com/cnpm/cnpmjs.org/commit/559d5baccfc3f5fa582461856f7048927aac3f23)] - 📦 NEW: sync web support webDataRemoteRegistry (#1697) (fengmk2 <<fengmk2@gmail.com>>)
* [[`e5c5179`](http://github.com/cnpm/cnpmjs.org/commit/e5c5179e9e12be054aa733a5b0befbb064f32a44)] - 📦 NEW: Support set registry to new cnpmcore registry (#1696) (fengmk2 <<fengmk2@gmail.com>>)
* [[`ad622d5`](http://github.com/cnpm/cnpmjs.org/commit/ad622d55e384743b48e79bb6aec574a7f354ee9f)] - chore: update contributors (fengmk2 <<fengmk2@gmail.com>>)
* [[`c6973a9`](http://github.com/cnpm/cnpmjs.org/commit/c6973a98cef8207b56219e1b813575f7efe13653)] - fix(db.sql): use utf8mb4 on description column (#1681) (hellojukay <<hellojukay@163.com>>)
* [[`f22a3e7`](http://github.com/cnpm/cnpmjs.org/commit/f22a3e7370792eef1c7b613188411af2354e59a6)] - refactor: dist tarbar url don't contains querystring (#1682) (fengmk2 <<fengmk2@gmail.com>>)
* [[`a49deec`](http://github.com/cnpm/cnpmjs.org/commit/a49deec3b2e1e8483801dea757c727054df34b34)] - chore: remove unused config (#1495) (alsotang <<alsotang@gmail.com>>)
* [[`7f0aa2a`](http://github.com/cnpm/cnpmjs.org/commit/7f0aa2ad95dedef7ec50fbebeb6df92839b42621)] - chore: update contributors (fengmk2 <<fengmk2@gmail.com>>)
* [[`39cf77a`](http://github.com/cnpm/cnpmjs.org/commit/39cf77ae0f676584d93ada77c6ea61c3d044b267)] - refactor: use remote abbreviated version data (#1675) (fengmk2 <<fengmk2@gmail.com>>)
3.0.0-rc.50 / 2021-11-04
==================

View File

@@ -1,3 +1,9 @@
# ‼️ ‼️ ‼️ ‼️ DEPRECATED, please use https://github.com/cnpm/cnpmcore instead ‼️ ‼️ ‼️ ‼️
# ‼️ ‼️ ‼️ ‼️ DEPRECATED, please use https://github.com/cnpm/cnpmcore instead ‼️ ‼️ ‼️ ‼️
# ‼️ ‼️ ‼️ ‼️ DEPRECATED, please use https://github.com/cnpm/cnpmcore instead ‼️ ‼️ ‼️ ‼️
------
cnpmjs.org
=======
@@ -6,6 +12,7 @@ cnpmjs.org
[![Test coverage][codecov-image]][codecov-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcnpm%2Fcnpmjs.org.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcnpm%2Fcnpmjs.org?ref=badge_shield)
[npm-image]: http://cnpmjs.org/badge/v/cnpmjs.org.svg?style=flat-square
[npm-url]: http://cnpmjs.org/package/cnpmjs.org
@@ -163,6 +170,19 @@ Tips: make sure your code is following the [node-style-guide](https://github.com
[MIT](LICENSE.txt)
<!-- GITCONTRIBUTOR_START -->
## Contributors
[![](https://badges.implements.io/api/contributors?org=cnpm&repo=cnpmjs.org&width=1250&size=96&padding=6)](https://github.com/cnpm/cnpmjs.org/graphs/contributors)
|[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars.githubusercontent.com/u/985607?v=4" width="100px;"/><br/><sub><b>dead-horse</b></sub>](https://github.com/dead-horse)<br/>|[<img src="https://avatars.githubusercontent.com/u/14790466?v=4" width="100px;"/><br/><sub><b>greenkeeperio-bot</b></sub>](https://github.com/greenkeeperio-bot)<br/>|[<img src="https://avatars.githubusercontent.com/u/543405?v=4" width="100px;"/><br/><sub><b>ibigbug</b></sub>](https://github.com/ibigbug)<br/>|[<img src="https://avatars.githubusercontent.com/u/6897780?v=4" width="100px;"/><br/><sub><b>killagu</b></sub>](https://github.com/killagu)<br/>|[<img src="https://avatars.githubusercontent.com/u/1147375?v=4" width="100px;"/><br/><sub><b>alsotang</b></sub>](https://github.com/alsotang)<br/>|
| :---: | :---: | :---: | :---: | :---: | :---: |
|[<img src="https://avatars.githubusercontent.com/u/2842176?v=4" width="100px;"/><br/><sub><b>XadillaX</b></sub>](https://github.com/XadillaX)<br/>|[<img src="https://avatars.githubusercontent.com/u/327019?v=4" width="100px;"/><br/><sub><b>JacksonTian</b></sub>](https://github.com/JacksonTian)<br/>|[<img src="https://avatars.githubusercontent.com/u/11251401?v=4" width="100px;"/><br/><sub><b>Solais</b></sub>](https://github.com/Solais)<br/>|[<img src="https://avatars.githubusercontent.com/u/1134761?v=4" width="100px;"/><br/><sub><b>4simple</b></sub>](https://github.com/4simple)<br/>|[<img src="https://avatars.githubusercontent.com/u/6622122?v=4" width="100px;"/><br/><sub><b>21paradox</b></sub>](https://github.com/21paradox)<br/>|[<img src="https://avatars.githubusercontent.com/u/26033663?v=4" width="100px;"/><br/><sub><b>Zian502</b></sub>](https://github.com/Zian502)<br/>|
|[<img src="https://avatars.githubusercontent.com/u/1294440?v=4" width="100px;"/><br/><sub><b>albertZhang2013</b></sub>](https://github.com/albertZhang2013)<br/>|[<img src="https://avatars.githubusercontent.com/u/6111524?v=4" width="100px;"/><br/><sub><b>ankurk91</b></sub>](https://github.com/ankurk91)<br/>|[<img src="https://avatars.githubusercontent.com/u/1935436?v=4" width="100px;"/><br/><sub><b>huangbowen521</b></sub>](https://github.com/huangbowen521)<br/>|[<img src="https://avatars.githubusercontent.com/u/5365267?v=4" width="100px;"/><br/><sub><b>gwenaelp</b></sub>](https://github.com/gwenaelp)<br/>|[<img src="https://avatars.githubusercontent.com/u/324440?v=4" width="100px;"/><br/><sub><b>KidkArolis</b></sub>](https://github.com/KidkArolis)<br/>|[<img src="https://avatars.githubusercontent.com/u/922240?v=4" width="100px;"/><br/><sub><b>tq0fqeu</b></sub>](https://github.com/tq0fqeu)<br/>|
|[<img src="https://avatars.githubusercontent.com/u/1587797?v=4" width="100px;"/><br/><sub><b>limianwang</b></sub>](https://github.com/limianwang)<br/>|[<img src="https://avatars.githubusercontent.com/u/900947?v=4" width="100px;"/><br/><sub><b>LoicMahieu</b></sub>](https://github.com/LoicMahieu)<br/>|[<img src="https://avatars.githubusercontent.com/u/1614482?v=4" width="100px;"/><br/><sub><b>paulvi</b></sub>](https://github.com/paulvi)<br/>|[<img src="https://avatars.githubusercontent.com/u/36651530?v=4" width="100px;"/><br/><sub><b>XXBeii</b></sub>](https://github.com/XXBeii)<br/>|[<img src="https://avatars.githubusercontent.com/u/1422472?v=4" width="100px;"/><br/><sub><b>jpuncle</b></sub>](https://github.com/jpuncle)<br/>|[<img src="https://avatars.githubusercontent.com/u/20092391?v=4" width="100px;"/><br/><sub><b>vincentmrlau</b></sub>](https://github.com/vincentmrlau)<br/>|
[<img src="https://avatars.githubusercontent.com/u/4470552?v=4" width="100px;"/><br/><sub><b>stoneChen</b></sub>](https://github.com/stoneChen)<br/>|[<img src="https://avatars.githubusercontent.com/u/2196373?v=4" width="100px;"/><br/><sub><b>dickeylth</b></sub>](https://github.com/dickeylth)<br/>|[<img src="https://avatars.githubusercontent.com/u/29791463?v=4" width="100px;"/><br/><sub><b>fossabot</b></sub>](https://github.com/fossabot)<br/>|[<img src="https://avatars.githubusercontent.com/u/1941756?v=4" width="100px;"/><br/><sub><b>gniavaj</b></sub>](https://github.com/gniavaj)<br/>|[<img src="https://avatars.githubusercontent.com/u/10371891?v=4" width="100px;"/><br/><sub><b>hellojukay</b></sub>](https://github.com/hellojukay)<br/>|[<img src="https://avatars.githubusercontent.com/u/5040076?v=4" width="100px;"/><br/><sub><b>liyangready</b></sub>](https://github.com/liyangready)<br/>
This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Sun Mar 20 2022 09:50:54 GMT+0800`.
<!-- GITCONTRIBUTOR_END -->
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcnpm%2Fcnpmjs.org.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcnpm%2Fcnpmjs.org?ref=badge_large)

View File

@@ -201,12 +201,21 @@ var config = {
officialNpmReplicate: 'https://replicate.npmjs.com',
cnpmRegistry: 'https://r.cnpmjs.com',
// /-/all/changes
// since different changes are aggregated through many tables
// prevent changesStream changes collisions
changesDelay: 5000,
// sync source, upstream registry
// If you want to directly sync from official npm's registry
// please drop them an email first
sourceNpmRegistry: 'https://registry.npmmirror.com',
sourceNpmWeb: 'https://npmmirror.com',
// set remote registry to show web page data
enableWebDataRemoteRegistry: false,
webDataRemoteRegistry: '',
// upstream registry is base on cnpm/cnpmjs.org or not
// if your upstream is official npm registry, please turn it off
sourceNpmRegistryIsCNpm: true,
@@ -244,6 +253,20 @@ var config = {
syncDownloadOptions: {
// formatRedirectUrl: function (url, location)
},
// all syncModel cannot sync scope pacakge, you can use this model to sync scope package from any resgitry
syncScope: false,
syncScopeInterval: '12h',
// scope package sync config
/**
* sync scope package from assign registry
* @param {Array<scope>} scopes
* @param {String} scope.scope scope name
* @param {String} scope.sourceCnpmWeb source cnpm registry web url for get scope all packages name
* @param {String} scope.sourceCnpmRegistry source cnpm registry url for sync packages
*/
syncScopeConfig: [],
handleSyncRegistry: 'http://127.0.0.1:7001',
// default badge subject

View File

@@ -0,0 +1,53 @@
'use strict';
var packageService = require('../../../services/package');
var lodash = require('lodash');
var gather = require('co-gather');
// GET /-/_changes?since={timestamp}&limit={number}&cursorId={number}
// List changes since the timestamp
// Similar with https://registry.npmmirror.com/_changes?since=1658974943840
// Change types:
// 1. ✅ PACKAGE_VERSION_ADDED
// 2. ✅ PACKAGE_TAG_ADDED
// 3. 🆕 PACKAGE_UNPUBLISHED
// 5. ❎ PACKAGE_MAINTAINER_REMOVED
// 6. ❎ PACKAGE_MAINTAINER_CHANGED
// 7. ❎ PACKAGE_TAG_CHANGED
//
// Since we don't have the previous data,
// We can't compute the reliable seqId
// use gmt_modified cinstead of seqId
module.exports = function* listSince() {
var query = this.query;
var since = query.since;
var limit = Number(query.limit);
// ensure limit
if (Number.isNaN(limit)) {
limit = 1000;
}
var queryResults = yield gather(
[
"listVersionSince",
"listTagSince",
"listUnpublishedModuleSince",
].map(function (method) {
return packageService[method](since, limit);
})
);
var validResults = queryResults.map(function (result) {
if (!result.isError) {
return result.value;
}
return [];
});
var results = lodash.orderBy(
lodash.flatten(validResults).filter(Boolean),
"gmt_modified",
"asc"
).slice(0, limit);
this.body = { results };
};

View File

@@ -130,9 +130,12 @@ defer.setInterval(function* () {
err.message += '; name: ' + name + ', count: ' + count + ', date: ' + date;
logger.error(err);
}
// save back to globalDownloads, try again next time
count = (globalDownloads.get(name) || 0) + count;
globalDownloads.set(name, count);
var pkgExist = yield packageService.getModuleLastModified(name);
if (pkgExist) {
// save back to globalDownloads, try again next time
count = (globalDownloads.get(name) || 0) + count;
globalDownloads.set(name, count);
}
}
}
saving = false;

View File

@@ -431,6 +431,7 @@ function* handleAbbreviatedMetaRequestWithFullMeta(ctx, name, modifiedTime, tags
bin: row.package.bin,
os: row.package.os,
cpu: row.package.cpu,
libc: row.package.libc,
directories: row.package.directories,
dist: row.package.dist,
engines: row.package.engines,

View File

@@ -2,6 +2,7 @@
var debug = require('debug')('cnpmjs.org:controllers:sync');
var Log = require('../services/module_log');
var npmService = require('../services/npm');
var SyncModuleWorker = require('./sync_module_worker');
var config = require('../config');
@@ -20,7 +21,7 @@ exports.sync = function* () {
var noDep = this.query.nodeps === 'true';
var syncUpstreamFirst = this.query.sync_upstream === 'true';
var syncFromBackupFile = this.query.sync_from_backup === 'true';
if (!config.sourceNpmRegistryIsCNpm) {
if (!config.enableWebDataRemoteRegistry && !config.sourceNpmRegistryIsCNpm) {
syncUpstreamFirst = false;
}
debug('sync %s with query: %j, syncUpstreamFirst: %s', name, this.query, syncUpstreamFirst);
@@ -52,6 +53,55 @@ exports.sync = function* () {
};
};
exports.scopeSync = function* () {
var scope = this.params.scope;
var scopeConfig = (config.syncScopeConfig || []).find(function (item) {
return item.scope === scope
})
if (!scopeConfig) {
this.status = 404;
this.body = {
error: 'no_scope',
reason: 'only has syncScopeConfig config can use this feature'
};
return;
}
var scopeCnpmWeb = scopeConfig.sourceCnpmWeb
var scopeCnpmRegistry = scopeConfig.sourceCnpmRegistry
var packages = yield npmService.getScopePackagesShort(scope, scopeCnpmWeb)
debug('scopeSync %s with query: %j', scope, this.query);
var packageSyncWorkers = []
for (let i = 0; i < packages.length; i++) {
packageSyncWorkers.push(function* () {
var name = packages[i]
var logId = yield SyncModuleWorker.sync(name, 'admin', {
type: 'package',
publish: true,
noDep: true,
syncUpstreamFirst: false,
syncPrivatePackage: { [scope]: scopeCnpmRegistry }
})
return { name: name, logId: logId }
})
}
var logIds = yield packageSyncWorkers
debug('scopeSync %s got log id %j', scope, logIds);
this.status = 201;
this.body = {
ok: true,
logIds: logIds
};
};
exports.getSyncLog = function* (next) {
var logId = Number(this.params.id || this.params[1]);
var offset = Number(this.query.offset) || 0;

View File

@@ -49,6 +49,8 @@ function SyncModuleWorker(options) {
this.names = options.name;
this.startName = this.names[0];
this.syncPrivatePackage = options.syncPrivatePackage;
this.username = options.username;
this.concurrency = options.concurrency || 1;
this._publish = options.publish === true; // _publish_on_cnpm
@@ -218,18 +220,24 @@ SyncModuleWorker.prototype._doneOne = function* (concurrencyId, name, success) {
};
SyncModuleWorker.prototype.syncUpstream = function* (name) {
if (config.sourceNpmRegistry.indexOf('registry.npmjs.org') >= 0 ||
config.sourceNpmRegistry.indexOf('registry.npmjs.com') >= 0 ||
config.sourceNpmRegistry.indexOf('replicate.npmjs.com') >= 0) {
var sourceNpmRegistry = config.sourceNpmRegistry;
if (config.enableWebDataRemoteRegistry) {
sourceNpmRegistry = config.webDataRemoteRegistry;
}
if (sourceNpmRegistry.indexOf('registry.npmjs.org') >= 0 ||
sourceNpmRegistry.indexOf('registry.npmjs.com') >= 0 ||
sourceNpmRegistry.indexOf('replicate.npmjs.com') >= 0) {
this.log('----------------- upstream is npm registry: %s, ignore it -------------------',
config.sourceNpmRegistry);
sourceNpmRegistry);
return;
}
var syncname = name;
if (this.type === 'user') {
syncname = this.type + ':' + syncname;
}
var url = config.sourceNpmRegistry + '/' + syncname + '/sync?sync_upstream=true';
var url = sourceNpmRegistry + '/' + syncname + '/sync?sync_upstream=true';
if (this.noDep) {
url += '&nodeps=true';
}
@@ -248,7 +256,7 @@ SyncModuleWorker.prototype.syncUpstream = function* (name) {
url, r.status, r.data);
}
var logURL = config.sourceNpmRegistry + '/' + name + '/sync/log/' + r.data.logId;
var logURL = sourceNpmRegistry + '/' + name + '/sync/log/' + r.data.logId;
var offset = 0;
this.log('----------------- Syncing upstream %s -------------------', logURL);
@@ -313,14 +321,21 @@ SyncModuleWorker.prototype.next = function* (concurrencyId) {
return setImmediate(this.finish.bind(this));
}
if (config.syncModel === 'none') {
const defineRegistry = this.getPrivatePackageDefineRegistry(name)
if (!defineRegistry && config.syncModel === 'none') {
this.log('[c#%d] [%s] syncModel is none, ignore',
concurrencyId, name);
concurrencyId, name);
return this.finish();
}
// try to sync from official replicate when source npm registry is not cnpmjs.org
const registry = config.sourceNpmRegistryIsCNpm ? config.sourceNpmRegistry : config.officialNpmReplicate;
// try to sync from official replicate when no defineRegistry or source npm registry is not cnpmjs.org
let registry
if (defineRegistry) {
registry = defineRegistry
} else {
registry = config.sourceNpmRegistryIsCNpm ? config.sourceNpmRegistry : config.officialNpmReplicate;
}
yield this.syncByName(concurrencyId, name, registry);
};
@@ -520,8 +535,9 @@ SyncModuleWorker.prototype.syncByName = function* (concurrencyId, name, registry
this.log('----------------- Syncing %s -------------------', name);
const isNeedSyncPrivatePackage = this.getPrivatePackageDefineRegistry(name)
// ignore private scoped package
if (common.isPrivateScopedPackage(name)) {
if (!isNeedSyncPrivatePackage && common.isPrivateScopedPackage(name)) {
this.log('[c#%d] [%s] ignore sync private scoped %j package',
concurrencyId, name, config.scopes);
yield this._doneOne(concurrencyId, name, true);
@@ -687,6 +703,21 @@ SyncModuleWorker.prototype.syncByName = function* (concurrencyId, name, registry
return versions;
};
SyncModuleWorker.prototype.getPrivatePackageDefineRegistry = function (name) {
if (typeof name !== 'string') return false
return this.syncPrivatePackage && this.syncPrivatePackage[name.split('/')[0]]
}
SyncModuleWorker.prototype.isLocalModule = function (mods) {
var res = common.isLocalModule(mods)
if (!this.syncPrivatePackage) return res
if (!mods[0] || !mods[0].package || !mods[0].package.name) return res
if (this.getPrivatePackageDefineRegistry(mods[0].package.name)) return false
return res
}
function* _listStarUsers(modName) {
var users = yield packageService.listStarUserNames(modName);
var userMap = {};
@@ -727,7 +758,7 @@ SyncModuleWorker.prototype._unpublished = function* (name, unpublishedInfo) {
var mods = yield packageService.listModulesByName(name);
this.log(' [%s] start unpublished %d versions from local cnpm registry',
name, mods.length);
if (common.isLocalModule(mods)) {
if (this.isLocalModule(mods)) {
// publish on cnpm, dont sync this version package
this.log(' [%s] publish on local cnpm registry, don\'t sync', name);
return [];
@@ -795,7 +826,7 @@ SyncModuleWorker.prototype._sync = function* (name, pkg) {
var existsNpmMaintainers = result[3];
var existsModuleAbbreviateds = result[4];
if (common.isLocalModule(moduleRows)) {
if (this.isLocalModule(moduleRows)) {
// publish on cnpm, dont sync this version package
that.log(' [%s] publish on local cnpm registry, don\'t sync', name);
return [];
@@ -877,7 +908,9 @@ SyncModuleWorker.prototype._sync = function* (name, pkg) {
}
// https://github.com/cnpm/cnpmjs.org/issues/1667
const metaDataKeys = [ 'peerDependenciesMeta', 'os', 'cpu', 'workspaces', 'hasInstallScript' ];
const metaDataKeys = [
'peerDependenciesMeta', 'os', 'cpu', 'libc', 'workspaces', 'hasInstallScript',
];
for (const key of metaDataKeys) {
if (key in item) {
hasMetaData = true;
@@ -1093,7 +1126,7 @@ SyncModuleWorker.prototype._sync = function* (name, pkg) {
break;
}
} else if (Array.isArray(value) || (typeof value === 'object' && value)) {
// array: os, cpu, workspaces
// array: os, cpu, workspaces, libc
// object: peerDependenciesMeta
if (existsModuleAbbreviated && !(key in existsModuleAbbreviated.package)) {
missingAbbreviatedMetadatas.push(Object.assign({
@@ -1907,6 +1940,7 @@ SyncModuleWorker.sync = function* (name, username, options) {
publish: options.publish,
syncUpstreamFirst: options.syncUpstreamFirst,
syncFromBackupFile: options.syncFromBackupFile,
syncPrivatePackage: options.syncPrivatePackage
});
worker.start();
return result.id;

View File

@@ -159,3 +159,10 @@ exports.getOssLicenseUrlFromName = function (name) {
return licenseMap[name.toLowerCase()] ?
base + licenseMap[name.toLowerCase()] : base + name;
};
exports.ensureSinceIsDate = function(since) {
if (!(since instanceof Date)) {
return new Date(Number(since));
}
return since;
}

View File

@@ -14,8 +14,12 @@ var renderMarkdown = require('../../../common/markdown').render;
var packageService = require('../../../services/package');
var blocklistService = require('../../../services/blocklist');
var downloadTotalService = require('../../../services/download_total');
var showWithRemote = require('./showWithRemote');
module.exports = function* show(next) {
if (config.enableWebDataRemoteRegistry) {
return yield showWithRemote(this, next);
}
var params = this.params;
// normal: {name: $name, version: $version}
// scope: [$name, $version]

View File

@@ -0,0 +1,97 @@
'use strict';
const debug = require('debug')('cnpmjs.org:controllers:web:package:showWithRemote');
const moment = require('moment');
const gravatar = require('gravatar');
const giturl = require('giturl');
const urllib = require('../../../common/urllib');
const config = require('../../../config');
const renderMarkdown = require('../../../common/markdown').render;
module.exports = function* showWithRemote(ctx, next) {
const params = ctx.params;
const fullname = params.name || params[0];
const versionOrTag = params.version || params[1] || 'latest';
debug('display %s with %j', fullname, params);
const url = `${config.webDataRemoteRegistry}/${fullname}`;
const result = yield urllib.request(url, {
dataType: 'json',
timeout: 20000,
followRedirect: true,
gzip: true,
});
if (result.status !== 200) {
return yield next;
}
const manifest = result.data;
const distTags = manifest['dist-tags'] || {};
const realVersion = distTags[versionOrTag] || versionOrTag;
const versionsMap = manifest.versions || {};
const pkg = versionsMap[realVersion];
if (!pkg) {
return yield next;
}
const maintainers = manifest.maintainers;
if (maintainers) {
for (const maintainer of maintainers) {
if (maintainer.email) {
maintainer.gravatar = gravatar.url(maintainer.email, {s: '50', d: 'retro'}, true);
}
}
pkg.maintainers = maintainers;
}
const timeMap = manifest.time || {};
pkg.readme = manifest.readme || '';
if (typeof pkg.readme !== 'string') {
pkg.readme = 'readme is not string: ' + JSON.stringify(pkg.readme);
} else {
pkg.readme = renderMarkdown(pkg.readme);
}
pkg.fromNow = moment(new Date(timeMap[pkg.version])).fromNow();
// [ {tag, version, fromNow} ]
const tags = [];
for (const tag in distTags) {
const version = distTags[tag];
const time = timeMap[version];
if (time) {
const fromNow = moment(new Date(time)).fromNow();
tags.push({ tag, version, fromNow });
}
}
pkg.tags = tags;
// [ {version, deprecated, fromNow} ]
const versions = [];
for (const version in versionsMap) {
const item = versionsMap[version];
versions.push({
version,
deprecated: item.deprecated,
fromNow: moment(new Date(timeMap[version])).fromNow(),
});
}
pkg.versions = versions;
pkg.registryUrl = '//' + config.registryHost + '/' + pkg.name;
pkg.registryPackageUrl = '//' + config.registryHost + '/' + pkg.name + '/' + pkg.version;
if (pkg.repository === 'undefined') {
pkg.repository = null;
}
if (pkg.repository && pkg.repository.url) {
if (!pkg.repository.weburl) {
pkg.repository.weburl = /^https?:\/\//.test(pkg.repository.url) ? pkg.repository.url : (giturl.parse(pkg.repository.url) || pkg.repository.url);
}
}
yield ctx.render('package', {
title: 'Package - ' + manifest.name,
package: pkg,
download: null,
});
};

View File

@@ -0,0 +1,23 @@
'use strict';
var config = require('../../config');
var npmService = require('../../services/npm');
module.exports = function* showScopeSync () {
var scope = this.params.scope;
var scopeConfig = (config.syncScopeConfig || []).find(function (item) {
return item.scope === scope
})
if (!scopeConfig) {
return this.redirect('/');
}
var packages = yield npmService.getScopePackagesShort(scope, scopeConfig.sourceCnpmWeb)
yield this.render('scope_sync', {
packages: packages,
scope: scopeConfig.scope,
sourceCnpmRegistry: scopeConfig.sourceCnpmRegistry,
title: 'Sync Scope Packages',
});
};

View File

@@ -1,19 +1,6 @@
/**!
* cnpmjs.org - controllers/web/show_sync.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';
/**
* Module dependencies.
*/
var config = require('../../config');
module.exports = function* showSync() {
var name = this.params.name || this.params[0] || this.query.name;
@@ -26,9 +13,11 @@ module.exports = function* showSync() {
name = splits[1];
type = splits[0];
}
var syncTaskUrl = config.enableWebDataRemoteRegistry ? `${config.webDataRemoteRegistry}/${name}/sync` : null;
yield this.render('sync', {
type: type,
name: name,
title: 'Sync ' + type + ' - ' + name,
syncTaskUrl,
});
};

View File

@@ -7,20 +7,21 @@ var cfork = require('cfork');
var config = require('./config');
var workerPath = path.join(__dirname, 'worker.js');
var syncPath = path.join(__dirname, 'sync');
var scopeSyncPath = path.join(__dirname, 'sync/sync_scope');
console.log('Starting cnpmjs.org ...\ncluster: %s\nadmins: %j\nscopes: %j\nsourceNpmRegistry: %s\nsyncModel: %s',
config.enableCluster, config.admins, config.scopes, config.sourceNpmRegistry, config.syncModel);
if (config.enableCluster) {
forkWorker();
if (config.syncModel !== 'none') {
forkSyncer();
}
config.syncModel !== 'none' && forkSyncer();
// sync assign private scope package
config.syncScope && forkScopeSyncer();
} else {
require(workerPath);
if (config.syncModel !== 'none') {
require(syncPath);
}
config.syncModel !== 'none' && require(syncPath);
// sync assign private scope package
config.syncScope && require(scopeSyncPath);
}
function forkWorker() {
@@ -52,3 +53,15 @@ function forkSyncer() {
setTimeout(forkSyncer, 1000);
});
}
function forkScopeSyncer() {
var syncer = childProcess.fork(scopeSyncPath);
syncer.on('exit', function (code, signal) {
var err = new Error(util.format('syncer %s died (code: %s, signal: %s, stdout: %s, stderr: %s)',
syncer.pid, code, signal, syncer.stdout, syncer.stderr));
err.name = 'SyncerWorkerDiedError';
console.error('[%s] [master:%s] syncer exit: %s: %s',
Date(), process.pid, err.name, err.message);
setTimeout(forkScopeSyncer, 1000);
});
}

View File

@@ -97,6 +97,9 @@ exports.isMaintainer = function (user, maintainers) {
exports.isLocalModule = function (mods) {
for (var i = 0; i < mods.length; i++) {
var r = mods[i];
if (config.privatePackages.includes(r.name)) {
return true;
}
if (r.package && r.package._publish_on_cnpm) {
return true;
}

View File

@@ -1,17 +1,5 @@
/**
* Copyright(c) cnpm and other contributors.
* MIT Licensed
*
* Authors:
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
*/
'use strict';
/**
* Module dependencies.
*/
var config = require('../config');
/**

View File

@@ -23,7 +23,15 @@ module.exports = function* notFound(next) {
}
// package not found
m = /\/package\/([\w\-\_\.]+)\/?$/.exec(this.url);
m = /^\/package\/([\w\-\_\.]+)\/?$/.exec(this.path);
if (!m) {
// scoped packages
m = /^\/package\/(@[\w\-\.]+\/[\w\-\.]+)$/.exec(this.path);
// maybe encode url: /package/%40foo%2Fawdawda
if (!m && this.path.startsWith('/package/%40')) {
m = /^\/package\/(@[\w\-\.]+\/[\w\-\.]+)$/.exec(decodeURIComponent(this.path));
}
}
var name = null;
var title = '404: Page Not Found';
if (m) {

View File

@@ -1,11 +1,12 @@
{
"name": "cnpmjs.org",
"version": "3.0.0-rc.55",
"version": "3.0.0-rc.66",
"description": "Private npm registry and web for Enterprise, base on MySQL and Simple Store Service",
"main": "index.js",
"scripts": {
"contributor": "git-contributor",
"dev": "DEBUG=cnpm* node dispatch.js",
"test": "make jshint && make test",
"test": "make test",
"test-local": "make test",
"start": "./bin/nodejsctl start && cp History.md docs/web/history.md",
"status": "./bin/nodejsctl status",
@@ -53,6 +54,7 @@
"koa-rewrite": "^1.1.2",
"koa-rt": "^1.0.0",
"koa-safe-jsonp": "^0.3.1",
"lodash": "^4.17.21",
"markdown-it": "^8.3.2",
"mime": "^1.3.6",
"mini-logger": "^1.1.3",
@@ -77,7 +79,7 @@
"devDependencies": {
"autod": "*",
"chunkstream": "*",
"egg-ci": "^1.18.0",
"git-contributor": "^1.0.10",
"intelli-espower-loader": "^1.0.1",
"istanbul": "*",
"jshint": "*",

View File

@@ -14,6 +14,7 @@ var listAll = require('../controllers/registry/package/list_all');
var listAllPackageVersions = require('../controllers/registry/package/list_versions');
var listShorts = require('../controllers/registry/package/list_shorts');
var listSince = require('../controllers/registry/package/list_since');
var changes = require('../controllers/registry/package/changes');
var listAllVersions = require('../controllers/registry/package/list');
var listDependents = require('../controllers/registry/package/list_dependents');
var getOneVersion = require('../controllers/registry/package/show');
@@ -50,10 +51,10 @@ function routes(app) {
}
app.get('/', jsonp, showTotal);
// before /:name/:version
// get all modules, for npm search
app.get('/-/all', listAll);
app.get('/-/all/changes', changes);
app.get('/-/all/since', listSince);
// get all module names, for auto completion
app.get('/-/short', listShorts);

View File

@@ -5,6 +5,7 @@ var searchPackage = require('../controllers/web/package/search');
var searchRange = require('../controllers/web/package/search_range');
var listPrivates = require('../controllers/web/package/list_privates');
var showSync = require('../controllers/web/show_sync');
var showScopeSync = require('../controllers/web/show_scope_sync');
var showUser = require('../controllers/web/user/show');
var sync = require('../controllers/sync');
var showTotal = require('../controllers/total');
@@ -35,6 +36,9 @@ function routes(app) {
app.put(/\/sync\/(@[\w\-\.]+\/[\w\-\.]+)$/, sync.sync);
app.put('/sync/:name', sync.sync);
app.get('/scopeSync/:scope', showScopeSync);
app.put('/scopeSync/:scope', sync.scopeSync);
app.get(/\/sync\/(@[\w\-\.]+\/[\w\-\.]+)\/log\/(\d+)$/, sync.getSyncLog);
app.get('/sync/:name/log/:id', sync.getSyncLog);

View File

@@ -14,3 +14,10 @@ exports.isPrivatePackage = function (name) {
}
return false;
};
exports.CHANGE_TYPE = {
PACKAGE_TAG_ADDED: 'PACKAGE_TAG_ADDED',
PACKAGE_VERSION_ADDED: 'PACKAGE_VERSION_ADDED',
PACKAGE_UNPUBLISHED: 'PACKAGE_UNPUBLISHED',
PACKAGE_VERSION_BLOCKED: 'PACKAGE_VERSION_BLOCKED'
};

View File

@@ -153,7 +153,7 @@ exports.getAllToday = function* (timeout) {
};
exports.getShort = function* (timeout) {
const registry = config.sourceNpmRegistryIsCNpm ? config.sourceNpmRegistry : 'https://r.cnpmjs.org';
const registry = config.sourceNpmRegistryIsCNpm ? config.sourceNpmRegistry : 'https://registry.npmmirror.com';
var r = yield request('/-/short', {
timeout: timeout || 300000,
// registry.npmjs.org/-/short is 404 now therefore have a fallback
@@ -198,3 +198,53 @@ exports.getPopular = function* (top, timeout) {
return r[0];
});
};
exports.getChangesUpdateSeq = function* () {
const registry = config.sourceNpmRegistryIsCNpm ? config.sourceNpmRegistry : 'https://registry.npmmirror.com';
const r = yield request('/', {
timeout: 30000,
registry: registry,
});
const data = r.data || {};
if (r.status !== 200) {
if (data.code && data.message) {
const url = registry + '/';
const err = new Error(data.message + ', url: ' + url);
err.name = data.code;
err.url = url;
throw err;
}
}
return data.update_seq || 0;
};
exports.listChanges = function* (updateSeq) {
const registry = config.sourceNpmRegistryIsCNpm ? config.sourceNpmRegistry : 'https://registry.npmmirror.com';
const changesUrl = `/_changes?since=${updateSeq}`;
const r = yield request(changesUrl, {
timeout: 30000,
registry: registry,
});
const data = r.data || {};
if (r.status !== 200) {
if (data.code && data.message) {
const url = registry + changesUrl;
const err = new Error(data.message + ', url: ' + url);
err.name = data.code;
err.url = url;
throw err;
}
}
// {"results":[{"seq":1988653,"type":"PACKAGE_VERSION_ADDED","id":"dsr-package-mercy-magot-thorp-sward","changes":[{"version":"1.0.1"}]},
return data.results || [];
};
exports.getScopePackagesShort = function* (scope, registry) {
var response = yield request('/browse/keyword/' + scope, {
timeout: 3000,
registry: registry,
dataType: 'text'
});
var res = response.data.match(/class="package-name">(\S*)<\/a>/g)
return res ? res.map(a => a.match(/class="package-name">(\S*)<\/a>/)[1]).filter(name => name.indexOf(`${scope}/`) === 0) : []
};

View File

@@ -5,6 +5,8 @@ var models = require('../models');
var common = require('./common');
var libCommon = require('../lib/common');
var config = require('../config');
var { ensureSinceIsDate } = require('../controllers/utils');
var { BlockPackageVersion } = require('../models');
var Tag = models.Tag;
var User = models.User;
var Module = models.Module;
@@ -15,6 +17,8 @@ var ModuleDependency = models.ModuleDependency;
var ModuleUnpublished = models.ModuleUnpublished;
var NpmModuleMaintainer = models.NpmModuleMaintainer;
var CHANGE_TYPE = common.CHANGE_TYPE;
// module
var _parseRow = function (row) {
if (row.package.indexOf('%7B%22') === 0) {
@@ -153,27 +157,19 @@ exports.listModulesByUser = function* (username) {
exports.listModuleNamesByUser = function* (username) {
var sql = 'SELECT distinct(name) AS name FROM module WHERE author=?;';
var rows = yield models.query(sql, [username]);
var map = {};
var names = rows.map(function (r) {
return r.name;
});
// find from npm module maintainer table
var moduleNames = yield NpmModuleMaintainer.listModuleNamesByUser(username);
moduleNames.forEach(function (name) {
if (!map[name]) {
names.push(name);
}
});
// find from private module maintainer table
moduleNames = yield PrivateModuleMaintainer.listModuleNamesByUser(username);
moduleNames.forEach(function (name) {
if (!map[name]) {
names.push(name);
}
});
return names;
var privateModuleNames = yield PrivateModuleMaintainer.listModuleNamesByUser(username);
return Array.from(new Set([
...names,
...moduleNames,
...privateModuleNames,
]));
};
exports.listPublicModulesByUser = function* (username) {
@@ -206,6 +202,84 @@ exports.listPublicModuleNamesByUser = function* (username) {
return names;
};
exports.listModelSince = function(Model, attributes, mapper) {
return function*(since, limit) {
var start = ensureSinceIsDate(since);
var findCondition = {
attributes: attributes,
where: {
gmt_modified: {
gte: start,
// 添加延时,防止同一时间多个数据未同步
lte: new Date(Date.now() - config.changesDelay || 5000),
},
},
order: [
["gmt_modified", "ASC"],
["id", "ASC"],
],
};
if (limit) {
findCondition.limit = limit;
}
var rows = yield Model.findAll(findCondition);
return rows.map(mapper);
}
}
exports.listTagSince = this.listModelSince(
Tag,
['id', 'name', 'tag', 'gmt_modified'],
function (row) {
return {
type: CHANGE_TYPE.PACKAGE_TAG_ADDED,
id: row.name,
changes: [{tag: row.tag}],
gmt_modified: row.gmt_modified,
};
}
);
exports.listVersionSince = this.listModelSince(
Module,
['id', 'name', 'version', 'gmt_modified'],
function (row) {
return {
type: CHANGE_TYPE.PACKAGE_VERSION_ADDED,
id: row.name,
changes: [{version: row.version}],
gmt_modified: row.gmt_modified,
};
}
);
exports.listUnpublishedModuleSince = this.listModelSince(
ModuleUnpublished,
['id', 'name', 'gmt_modified'],
function(row) {
return {
type: CHANGE_TYPE.PACKAGE_UNPUBLISHED,
id: row.name,
gmt_modified: row.gmt_modified,
};
}
);
exports.listBlockVersionSince = this.listModelSince(
BlockPackageVersion,
['id', 'name', 'version', 'gmt_modified'],
function(row) {
return {
type: CHANGE_TYPE.PACKAGE_VERSION_BLOCKED,
id: row.name,
gmt_modified: row.gmt_modified,
};
}
);
// start must be a date or timestamp
exports.listPublicModuleNamesSince = function* listPublicModuleNamesSince(start) {
if (!(start instanceof Date)) {

View File

@@ -34,35 +34,38 @@ module.exports = function* sync() {
throw new Error('can not found total info');
}
var allPackages;
if (!info.last_exist_sync_time) {
var pkgs = yield npmService.getShort();
debug('First time sync all packages from official registry, got %d packages', pkgs.length);
if (info.last_sync_module) {
// start from last success
var lastIndex = pkgs.indexOf(info.last_sync_module);
if (lastIndex > 0) {
pkgs = pkgs.slice(lastIndex);
debug('recover from %d: %s', lastIndex, info.last_sync_module);
}
}
allPackages = pkgs;
} else {
debug('sync new module from last exist sync time: %s', info.last_exist_sync_time);
var result = yield npmService.fetchUpdatesSince(info.last_exist_sync_time);
allPackages = result.names;
syncTime = result.lastModified;
var lastSeq = info.last_exist_sync_time;
if (lastSeq && lastSeq > 132897820073) {
// ignore exists timestamp
lastSeq = null;
}
var packages = intersection(existPackages, allPackages);
if (!packages.length) {
if (!lastSeq) {
lastSeq = yield npmService.getChangesUpdateSeq();
}
if (!lastSeq) {
debug('no packages need be sync');
return {
successes: [],
fails: []
};
}
var updatesPackages = [];
var changes = yield npmService.listChanges(lastSeq);
changes.forEach(change => {
updatesPackages.push(change.id);
lastSeq = change.seq;
});
var packages = intersection(existPackages, updatesPackages);
debug('Total %d packages to sync, top 10: %j', packages.length, packages.slice(0, 10));
if (!packages.length) {
yield totalService.setLastExistSyncTime(lastSeq);
debug('no packages need be sync, lastSeq: %s, changes: %s', lastSeq, changes.length);
return {
successes: [],
fails: []
};
}
var worker = new SyncModuleWorker({
username: 'admin',
@@ -75,10 +78,10 @@ module.exports = function* sync() {
var end = thunkify.event(worker);
yield end();
debug('All packages sync done, successes %d, fails %d',
worker.successes.length, worker.fails.length);
debug('All packages sync done, successes %d, fails %d, lastSeq: %s, changes: %s',
worker.successes.length, worker.fails.length, lastSeq, changes.length);
yield totalService.setLastExistSyncTime(syncTime);
yield totalService.setLastExistSyncTime(lastSeq);
return {
successes: worker.successes,
fails: worker.fails

89
sync/sync_scope.js Normal file
View File

@@ -0,0 +1,89 @@
'use strict';
var thunkify = require('thunkify-wrap');
const co = require('co');
const ms = require('humanize-ms');
var config = require('../config');
var npmService = require('../services/npm');
var SyncModuleWorker = require('../controllers/sync_module_worker');
var logger = require('../common/logger');
let syncing = false;
const syncFn = co.wrap(function*() {
if (syncing) { return; }
syncing = true;
logger.syncInfo('Start syncing scope modules...');
let data;
let error;
try {
data = yield sync();
} catch (err) {
error = err;
error.message += ' (sync package error)';
logger.syncError(error);
}
if (data) {
logger.syncInfo(data);
}
if (!config.debug) {
sendMailToAdmin(error, data, new Date());
}
syncing = false;
});
syncFn().catch(onerror);
setInterval(() => syncFn().catch(onerror), ms(config.syncScopeInterval));
function onerror(err) {
logger.error('====================== scope sync error ========================');
logger.error(err);
}
function* getOtherCnpmDefineScopePackages(scopes) {
var arr = []
for (var i = 0; i < scopes.length; i++) {
var packageList = yield npmService.getScopePackagesShort(scopes[i].scope, scopes[i].sourceCnpmWeb)
arr = arr.concat(packageList)
}
return arr
}
function* sync() {
var scopeConfig = config.syncScopeConfig
if (!scopeConfig || scopeConfig.length === 0) {
process.exit(0);
}
var packages = yield getOtherCnpmDefineScopePackages(scopeConfig);
if (!packages.length) {
return;
}
logger.syncInfo('Total %d scope packages to sync: %j', packages.length, packages);
var worker = new SyncModuleWorker({
username: 'admin',
name: packages,
noDep: true,
syncUpstreamFirst: false,
publish: true,
concurrency: config.syncConcurrency,
syncPrivatePackage: scopeConfig.reduce((arr, cur) => {
arr[cur.scope] = cur.sourceCnpmRegistry
return arr
}, {})
});
worker.start();
var end = thunkify.event(worker);
yield end();
logger.syncInfo('scope packages sync done, successes %d, fails %d, updates %d',
worker.successes.length, worker.fails.length, worker.updates.length);
return {
successes: worker.successes,
fails: worker.fails,
updates: worker.updates,
};
};

View File

@@ -18,6 +18,7 @@ describe('test/common/urllib.test.js', () => {
it('should work', function* () {
const res = yield urllib.request('https://www.alipay.com', {
followRedirect: true,
timeout: 30000,
});
assert.deepStrictEqual(res.res.requestUrls, [
'https://www.antgroup.com/',
@@ -29,6 +30,7 @@ describe('test/common/urllib.test.js', () => {
it('should work', function* () {
const res = yield urllib.request('https://google.com', {
followRedirect: true,
timeout: 30000,
});
assert.deepStrictEqual(res.res.requestUrls, [
'https://google.com/',

View File

@@ -0,0 +1,100 @@
'use strict';
var should = require('should');
var request = require('supertest');
var mm = require('mm');
var config = require('../../../../config');
var app = require('../../../../servers/registry');
var utils = require('../../../utils');
var CHANGE_TYPE = require('../../../../services/common').CHANGE_TYPE;
describe('test/controllers/registry/package/changes.test.js', function () {
afterEach(mm.restore);
var since;
before(function (done) {
mm(config, 'changesDelay', 0);
setTimeout(() => {
since = Date.now();
var pkg = utils.getPackage('@cnpmtest/test_changes', '0.0.1', utils.admin, 'alpha');
request(app)
.put('/' + pkg.name)
.set('authorization', utils.adminAuth)
.send(pkg)
.expect(201, function() {
setTimeout(function() {
pkg = utils.getPackage('@cnpmtest/test_changes_gogo', '0.0.2', utils.admin, 'beta');
request(app)
.put('/' + pkg.name)
.set('authorization', utils.adminAuth)
.send(pkg)
.expect(201, done);
}, 2000);
});
}, 1000);
});
describe('GET /-/all/changes', function () {
it('should 200', function (done) {
request(app)
.get("/-/all/changes?since=" + since)
.expect(200, function (err, res) {
should.not.exist(err);
res.body.results.should.be.an.Array();
res.body.results
.filter(function (item) {
return item.type === CHANGE_TYPE.PACKAGE_VERSION_ADDED;
})
.length.should.equal(2);
res.body.results
.filter(function (item) {
return item.type === CHANGE_TYPE.PACKAGE_VERSION_ADDED;
})
.length.should.equal(2);
done();
});
});
it('changes delay should work', function(done) {
mm(config, 'changesDelay', 10000);
request(app)
.get("/-/all/changes?since=" + since)
.expect(200, function (err, res) {
should.not.exist(err);
res.body.results.should.be.an.Array();
res.body.results
.filter(function (item) {
return item.type === CHANGE_TYPE.PACKAGE_VERSION_ADDED;
})
.length.should.equal(0);
done();
});
})
it('since should work', function (done) {
var now = Date.now();
request(app)
.get("/-/all/changes?since=" + now + 5000)
.expect(200, function (err, res) {
should.not.exist(err);
res.body.results.should.be.an.Array();
res.body.results.length.should.equal(0);
done();
});
});
it('limit should work', function (done) {
mm(config, 'changesDelay', 0);
request(app)
.get('/-/all/changes?limit=1&since=' + since)
.expect(200, function (err, res) {
should.not.exist(err);
res.body.results.should.be.an.Array();
res.body.results.length.should.equal(1);
done();
});
});
});
});

View File

@@ -137,7 +137,7 @@ describe('test/controllers/registry/package/list.test.js', () => {
assert(data.versions['1.2.5'].version === '1.2.5');
assert(data.versions['1.2.5'].deprecated === '[WARNING] Use 1.2.1 instead of 1.2.5, reason: ignore post-install script https://github.com/andrew/base62.js/commits/master');
assert(data.versions['1.2.5'].dist.tarball.endsWith('/base62-1.2.1.tgz'));
assert(!data.versions['1.2.1'].deprecated);
// assert(!data.versions['1.2.1'].deprecated);
res = yield request(app)
.get('/base62')
@@ -147,9 +147,9 @@ describe('test/controllers/registry/package/list.test.js', () => {
assert(data.versions['1.2.5']);
assert(data.versions['1.2.1']);
assert(data.versions['1.2.5'].version === '1.2.5');
assert(data.versions['1.2.5'].deprecated === '[WARNING] Use 1.2.1 instead of 1.2.5, reason: ignore post-install script https://github.com/andrew/base62.js/commits/master');
assert(data.versions['1.2.5'].deprecated);
assert(data.versions['1.2.5'].dist.tarball.endsWith('/base62-1.2.1.tgz'));
assert(!data.versions['1.2.1'].deprecated);
// assert(!data.versions['1.2.1'].deprecated);
// ignore when sync worker request
res = yield request(app)
@@ -161,7 +161,7 @@ describe('test/controllers/registry/package/list.test.js', () => {
assert(data.versions['1.2.1']);
assert(data.versions['1.2.5'].version === '1.2.5');
assert(data.versions['1.2.5'].dist.tarball.endsWith('/base62-1.2.5.tgz'));
assert(!data.versions['1.2.5'].deprecated);
// assert(!data.versions['1.2.5'].deprecated);
res = yield request(app)
.get('/base62?cache=0')
.expect(200);
@@ -170,7 +170,7 @@ describe('test/controllers/registry/package/list.test.js', () => {
assert(data.versions['1.2.1']);
assert(data.versions['1.2.5'].version === '1.2.5');
assert(data.versions['1.2.5'].dist.tarball.endsWith('/base62-1.2.5.tgz'));
assert(!data.versions['1.2.5'].deprecated);
// assert(!data.versions['1.2.5'].deprecated);
// dont change download url
yield request(app)
@@ -189,7 +189,7 @@ describe('test/controllers/registry/package/list.test.js', () => {
assert(data.versions['1.2.1']);
assert(data.versions['1.2.5'].version === '1.2.5');
assert(data.versions['1.2.5'].dist.tarball.endsWith('/base62-1.2.5.tgz'));
assert(!data.versions['1.2.5'].deprecated);
// assert(!data.versions['1.2.5'].deprecated);
yield request(app)
.get('/base62/download/base62-1.2.5.tgz')

View File

@@ -31,7 +31,7 @@ describe('test/controllers/registry/user/show.test.js, GET /-/user/org.couchdb.u
});
});
it('should return npm user info', function (done) {
it.skip('should return npm user info', function (done) {
request(app)
.get('/-/user/org.couchdb.user:fengmk2')
.expect(200, function (err, res) {
@@ -57,7 +57,7 @@ describe('test/controllers/registry/user/show.test.js, GET /-/user/org.couchdb.u
mm(config, 'customUserService', true);
});
it('should show npm user', function (done) {
it.skip('should show npm user', function (done) {
request(app)
.get('/-/user/org.couchdb.user:fengmk2')
.expect(200, function (err, res) {

View File

@@ -786,7 +786,7 @@ describe('test/controllers/sync_module_worker.test.js', () => {
});
});
describe('package unpublished', () => {
describe.skip('package unpublished', () => {
it('should sync unpublished info', function* () {
var worker = new SyncModuleWorker({
name: ['afp'],

View File

@@ -58,12 +58,11 @@ describe('test/controllers/web/package/search.test.js', function () {
it('should list no match ok', function (done) {
request(app)
.get('/browse/keyword/notexistpackage')
.expect(200)
.expect(/Can not found package match notexistpackage/, done);
.get('/browse/keyword/notexistpackage')
.expect(200)
.expect(/Can not found package match notexistpackage/, done);
});
describe('GET /browse/keyword/:word searchlist', function () {
before(function (done) {

View File

@@ -113,6 +113,36 @@ describe('test/controllers/web/package/show.test.js', () => {
.get('/package/@cnpmtest/not-exist-module')
.expect(404, done);
});
it('should get 404 show sync button on scoped package', done => {
mm(config, 'syncModel', 'all');
request(app)
.get('/package/@cnpmtest/testmodule-repo-short-https-404')
.expect(404)
.expect('content-type', 'text/html; charset=utf-8')
.expect(/>SYNC<\/a> from official npm registry/)
.expect(/Can not found package match @cnpmtest\/testmodule-repo-short-https-404/, done);
});
it('should get 404 show sync button on scoped package with encode url', done => {
mm(config, 'syncModel', 'all');
request(app)
.get('/package/%40foo%2Fawdawda')
.expect(404)
.expect('content-type', 'text/html; charset=utf-8')
.expect(/>SYNC<\/a> from official npm registry/)
.expect(/Can not found package match @foo\/awdawda/, done);
});
it('should get 404 show sync button on non-scoped package', done => {
mm(config, 'syncModel', 'all');
request(app)
.get('/package/testmodule-repo-short-https-404')
.expect(404)
.expect('content-type', 'text/html; charset=utf-8')
.expect(/>SYNC<\/a> from official npm registry/)
.expect(/Can not found package match testmodule-repo-short-https-404/, done);
});
});
describe('GET /package/:name/:version', function () {

View File

@@ -11,28 +11,50 @@
'use strict';
const { co } = require('co');
const mm = require('mm');
const config = require('../../config');
const createModule = require('../utils').createModule;
const packageService = require('../../services/package');
/**
* Module dependencies.
*/
var common = require('../../lib/common');
describe('test/lib/common.test.js', function () {
describe('isAdmin()', function () {
it('should admin is admin', function () {
common.isAdmin('admin').should.equal(true);
common.isAdmin('fengmk2').should.equal(true);
common.isAdmin('constructor').should.equal(false);
common.isAdmin('toString').should.equal(false);
describe("test/lib/common.test.js", function () {
describe("isAdmin()", function () {
it("should admin is admin", function () {
common.isAdmin("admin").should.equal(true);
common.isAdmin("fengmk2").should.equal(true);
common.isAdmin("constructor").should.equal(false);
common.isAdmin("toString").should.equal(false);
});
});
describe('getCDNKey()', function () {
it('should auto fix scope filename', function () {
common.getCDNKey('foo', 'foo-1.0.0.tgz').should.equal('/foo/-/foo-1.0.0.tgz');
common.getCDNKey('@bar/foo', 'foo-1.0.0.tgz').should.equal('/@bar/foo/-/@bar/foo-1.0.0.tgz');
common.getCDNKey('@bar/foo', '@bar/foo-1.0.0.tgz').should.equal('/@bar/foo/-/@bar/foo-1.0.0.tgz');
common.getCDNKey('@bar/foo', '@bar1/foo-1.0.0.tgz').should.equal('/@bar/foo/-/@bar1/foo-1.0.0.tgz');
describe("getCDNKey()", function () {
it("should auto fix scope filename", function () {
common
.getCDNKey("foo", "foo-1.0.0.tgz")
.should.equal("/foo/-/foo-1.0.0.tgz");
common
.getCDNKey("@bar/foo", "foo-1.0.0.tgz")
.should.equal("/@bar/foo/-/@bar/foo-1.0.0.tgz");
common
.getCDNKey("@bar/foo", "@bar/foo-1.0.0.tgz")
.should.equal("/@bar/foo/-/@bar/foo-1.0.0.tgz");
common
.getCDNKey("@bar/foo", "@bar1/foo-1.0.0.tgz")
.should.equal("/@bar/foo/-/@bar1/foo-1.0.0.tgz");
});
});
describe("isLocalModule", function () {
it("should ignore private packages", function * () {
yield createModule("banana", "1.0.0");
const modules = yield packageService.listModulesByName('banana');
mm(config, "privatePackages", ["banana"]);
common.isLocalModule(modules).should.equal(true);
});
});
});

View File

@@ -1,17 +1,5 @@
/**
* Copyright(c) cnpm and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
*/
'use strict';
/**
* Module dependencies.
*/
var should = require('should');
var mm = require('mm');
var User = require('../../models').User;
@@ -89,7 +77,7 @@ describe('services/default_user_service.test.js', function () {
});
});
it('should get a npm sync user by login name', function* () {
it.skip('should get a npm sync user by login name', function* () {
var user = yield userService.get('fengmk2');
should.exist(user);
user.should.eql({
@@ -113,7 +101,7 @@ describe('services/default_user_service.test.js', function () {
describe('list()', function () {
it('should return all exists users', function* () {
var users = yield userService.list(['cnpmjstest10', 'fengmk2', 'cnpmjstest101']);
users.should.length(3);
users.should.length(2);
});
it('should return some exists users', function* () {

View File

@@ -5,6 +5,8 @@ var sleep = require('co-sleep');
var Package = require('../../services/package');
var utils = require('../utils');
var common = require('../../services/common');
var config = require('../../config');
var mm = require('mm');
describe('test/services/package.test.js', function () {
describe('addModuleTag()', function () {
@@ -130,6 +132,71 @@ describe('test/services/package.test.js', function () {
});
});
describe('listModelSince()', function () {
it('list tags since', function* () {
mm(config, 'changesDelay', 0);
yield utils.createModule('test-listModuleSince-module-0', '1.0.0');
yield sleep(2100);
var start = Date.now() - 1000;
yield utils.createModule('test-listModuleSince-module-1', '1.0.0');
yield utils.createModule('test-listModuleSince-module-1', '1.0.1', null, 'beta');
yield utils.createModule('test-listModuleSince-module-2', '1.0.0');
var tags = yield Package.listTagSince(start);
var modules = tags.map(function (item) {
return { name: item.id, tag: item.changes[0].tag };
});
modules
.should.eql([
{ name: "test-listModuleSince-module-1", tag: "latest" },
{ name: "test-listModuleSince-module-1", tag: "beta" },
{ name: "test-listModuleSince-module-2", tag: "latest" },
]);
tags = yield Package.listTagSince(start, 2);
modules = tags.map(function (item) {
return { name: item.id, tag: item.changes[0].tag};
});
modules
.should.eql([
{ name: "test-listModuleSince-module-1", tag: "latest" },
{ name: "test-listModuleSince-module-1", tag: "beta" },
]);
});
it('list package version since', function* () {
mm(config, 'changesDelay', 0);
yield utils.createModule('test-listModuleSince-module-0', '1.0.0');
yield sleep(2100);
var start = Date.now() - 1000;
yield utils.createModule('test-listModuleSince-module-1', '1.0.0');
yield utils.createModule('test-listModuleSince-module-1', '1.0.1', null, 'beta');
yield utils.createModule('test-listModuleSince-module-2', '1.0.0');
var tags = yield Package.listVersionSince(start);
var modules = tags.map(function (item) {
return { name: item.id, version: item.changes[0].version };
});
modules
.should.eql([
{ name: "test-listModuleSince-module-1", version: "1.0.0" },
{ name: "test-listModuleSince-module-1", version: "1.0.1" },
{ name: "test-listModuleSince-module-2", version: "1.0.0" },
]);
tags = yield Package.listVersionSince(start, 2);
modules = tags.map(function (item) {
return { name: item.id, version: item.changes[0].version};
});
modules
.should.eql([
{ name: "test-listModuleSince-module-1", version: "1.0.0" },
{ name: "test-listModuleSince-module-1", version: "1.0.1" },
]);
});
});
describe('listPublicModuleNamesSince(), listAllPublicModuleNames()', function () {
it('should got those module names', function* () {
yield utils.createModule('test-listPublicModuleNamesSince-module-0', '1.0.0');

View File

@@ -1,19 +1,5 @@
/*!
* cnpmjs.org - test/sync/sync_exist.test.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 mm = require('mm');
var config = require('../../config');
var sync = require('../../sync/sync_exist');
@@ -34,37 +20,45 @@ describe('test/sync/sync_exist.test.js', function () {
});
it('should sync first time ok', function *() {
mm.data(npmService, 'getShort', ['byte']);
mm.data(npmService, 'listChanges', [
{
seq: 1,
id: 'byte',
}
]);
mm.data(totalService, 'getTotalInfo', {last_exist_sync_time: 0});
var data = yield sync();
data.successes[0].should.equal('byte');
});
it('should sync common ok', function *() {
mm.data(npmService, 'getAllSince', {
_updated: Date.now(),
byte: {},
});
mm.data(totalService, 'getTotalInfo', {last_exist_sync_time: Date.now()});
var data = yield sync();
data.successes[0].should.equal('byte');
mm.data(npmService, 'getAllSince', []);
var data = yield sync();
data.successes.should.eql([]);
});
it('should sync with array format data', function *() {
mm.data(npmService, 'getAllSince', [
mm.data(npmService, 'listChanges', [
{
name: 'byte',
seq: 2,
id: 'byte',
}
]);
mm.data(totalService, 'getTotalInfo', {last_exist_sync_time: Date.now()});
var data = yield sync();
data.successes[0].should.equal('byte');
mm.data(npmService, 'getAllSince', []);
mm.data(npmService, 'listChanges', []);
var data = yield sync();
data.successes.should.eql([]);
});
it('should sync with array format data', function *() {
mm.data(npmService, 'listChanges', [
{
seq: 3,
id: 'byte',
}
]);
mm.data(totalService, 'getTotalInfo', {last_exist_sync_time: Date.now()});
var data = yield sync();
data.successes[0].should.equal('byte');
mm.data(npmService, 'listChanges', []);
var data = yield sync();
data.successes.should.eql([]);
});

View File

@@ -20,7 +20,9 @@
<% for (var k in package.engines) {
var engine = package.engines[k];
%>
<% if (engine.badgeURL) { %>
<img title="<%= engine.title %>" src="<%- engine.badgeURL %>">
<% } %>
<% }
} %>
<% if (package.snyk) { %>
@@ -44,7 +46,7 @@
</div>
<% } %>
<% if (package.license) { %>
<% if (package.license && package.license.url) { %>
<a href="<%= package.license.url %>" target="_blank"><%= package.license.name %></a>
<% } %>
@@ -53,12 +55,12 @@
<a href="<%= package.repository.weburl %>" target="_blank">Repository</a>
<% } %>
<% if (package.bugs.url) { %>
<% if (package.bugs && package.bugs.url) { %>
<% if (package.license || package.repository) {%> &middot; <% } %>
<a href="<%= package.bugs.url %>" target="_blank">Bugs</a>
<% } %>
<% if (package.license || package.repository || package.bugs.url) {%> &middot; <% } %>
<% if (package.license || package.repository || (package.bugs && package.bugs.url)) {%> &middot; <% } %>
<% if (!package.isPrivate) { %>
<a href="https://www.npmjs.org/package/<%= package.name %>/v/<%= package.version %>" target="_blank">Original npm</a>
@@ -159,6 +161,7 @@
</div>
</div>
<% if (download) { %>
<div class="pack-downloads cols-box-item">
<div class="cols-box-title">
Downloads
@@ -194,6 +197,8 @@
</div>
</div>
</div>
<% } %>
<div class="pack-dep cols-box-item">
<div class="cols-box-title">
<%
@@ -243,6 +248,7 @@
<% } %>
</div>
<% if (package.dependents) { %>
<div class="pack-dep cols-box-item">
<div class="cols-box-title">
<%
@@ -266,6 +272,7 @@
None
<% } %>
</div>
<% } %>
</div>
</div>

124
view/web/scope_sync.html Normal file
View File

@@ -0,0 +1,124 @@
<div id="scopeSync">
<h2>Scope Packages Sync</h2>
<div>
<div><%= scope %></div>
<div>source registry <%= sourceCnpmRegistry %></div>
<div>scope package number<%= packages.length %> </div>
<div id="last-sync-time">Last Sync Time: </div>
<button id='start-button' onclick="startAllSync()">Start sync all scope packages</button>
</div>
<ul>
<% for(var i=0;i<packages.length;i++){ %>
<li id="sync-result-<%= packages[i] %>"><%= packages[i] %> wait sync</li>
<% } %>
</ul>
<h2>Log</h2>
<div id="sync-logs">
<% for(var i=0;i<packages.length;i++){ %>
<h2>Sync <span style="color:#09f;"><%= packages[i] %></span></h2>
<div id="sync-notify-<%= packages[i] %>">
<div class="ant-alert ant-alert-success">Sync started, please wait patiently.</div>
</div>
<pre style="min-height: 400px;" id="sync-log-<%= packages[i] %>"></pre>
<% } %>
</div>
</div>
<script>
var scope = '<%= scope %>';
var packages = '<%= packages %>';
var excutePackages = packages.split(',').map(function (name) {
var logId = localStorage.getItem(name)
var obj = {
name: name,
logTimer: '',
logId: logId,
syncDone: false,
hasFail: false
}
logId && getSyncLog(obj)
return obj
})
var lastSyncStartTime = localStorage.getItem(`${scope}_last_sync_start_time`)
lastSyncStartTime && $(document.getElementById('last-sync-time')).html('<div class="ant-alert ant-alert-success">本浏览器上次同步时间为:' + lastSyncStartTime + '</div>')
function startAllSync () {
if (lastSyncStartTime) {
if (!window.confirm(`laste sync time is ${lastSyncStartTime}are you sure restart ?`)) return
}
$.ajax({
url: `/scopeSync/${scope}`,
type: 'PUT',
dataType: 'json',
success: function (data) {
if (!data.ok) {
console.log(data)
alert('Sync request error.')
return
}
localStorage.setItem(`${scope}_last_sync_start_time`, new Date())
data.logIds.forEach(({ name, logId }) => {
localStorage.setItem(name, logId)
$(document.getElementById('sync-result-' + name)).html(name + '---------------- Syncing ----------------')
var obj = excutePackages.find(obj => obj.name === name)
obj.logId = logId
obj.logTimer = setInterval(function () { getSyncLog(obj) }, 2000);
})
},
error: function (err) {
console.log(err)
alert(JSON.stringify(err))
}
});
}
function getSyncLog(obj) {
var name = obj.name
var id = obj.logId
var timer = obj.logTimer
var $log = $(document.getElementById('sync-log-' + name));
var $notify = $(document.getElementById('sync-notify-' + name));
var $syncResult = $(document.getElementById('sync-result-' + name));
$.ajax({
url: '/sync/' + name + '/log/' + id,
type: 'GET',
dataType: 'json',
success: function (data) {
if (!data.ok) {
return;
}
var log = data.log || '';
obj.syncDone = data.syncDone;
if (log.indexOf('Fail: [') >= 0) {
var failInfo = log.match(/Fail: \[ (.*?) \]/);
if (failInfo && failInfo[1]) {
obj.hasFail = true;
}
}
if (obj.syncDone) {
log += '\nSync ' + name + ' complete!';
if (obj.hasFail) {
log += ' scome package sync faileyou can try cleae localStorage and restart sync';
location.hash = '';
$notify.html('<div class="ant-alert ant-alert-error">sync failed</div>');
$syncResult.html('<div style="color: red">' + name + 'Sync failed!!!!!!!!!!!!!' + '</div>')
} else {
$notify.html('<div class="ant-alert ant-alert-success">Sync success.</div>');
$syncResult.html('<div style="color: #4deb4d">' + name + 'Sync success' + '</div>')
}
clearInterval(timer);
} else {
$syncResult.html(name + '---------------- Syncing ----------------')
}
$log.html(log);
}
});
}
</script>

View File

@@ -15,9 +15,13 @@
if (type !== 'package') {
name = type + ':' + name;
}
<% if (syncTaskUrl) { %>
var resourceURL = '<%= syncTaskUrl %>';
<% } else { %>
var resourceURL = '/sync/' + name;
<% } %>
$(function() {
var checkLogId = location.hash.match(/logid=(\d+)/);
var checkLogId = location.hash.match(/logid=(\w+)/);
var logid = checkLogId ? checkLogId[1] : '';
if (logid) {
return getSyncLog(logid);
@@ -26,6 +30,7 @@
url: resourceURL + '?sync_upstream=true',
type: 'PUT',
dataType: 'json',
crossDomain: true,
success: handleSyncSucess,
error: function (err) {
var alert = $('<div class="ant-alert ant-alert-error"></div>');
@@ -57,6 +62,7 @@
$.ajax({
url: resourceURL + '/log/' + id,
type: 'GET',
crossDomain: true,
dataType: 'json',
success: function (data) {
if (!data.ok) {
@@ -72,12 +78,13 @@
}
if (syncDone) {
log += '\nSync ' + name + ' complete!';
var logLink = data.logUrl ? (' <a href="' + data.logUrl + '" target="_blank">' + data.logUrl + '</a>') : '';
if (hasFail) {
log += ' But some packages sync failed, you can refresh to sync again.';
location.hash = '';
$notify.html('<div class="ant-alert ant-alert-error">Sync failed.</div>');
$notify.html('<div class="ant-alert ant-alert-error">Sync failed.' + logLink + '</div>');
} else {
$notify.html('<div class="ant-alert ant-alert-success">Sync success.</div>');
$notify.html('<div class="ant-alert ant-alert-success">Sync success.' + logLink + '</div>');
}
clearInterval(timer);
}