-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fatpandac
authored
Apr 1, 2022
1 parent
457e8f8
commit bb3924c
Showing
7 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/package/:name': ['Fatpandac'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const got = require('@/utils/got'); | ||
const { art } = require('@/utils/render'); | ||
const path = require('path'); | ||
|
||
module.exports = async (ctx) => { | ||
const name = ctx.params.name; | ||
const packageDownloadLastMonthAPI = `https://api.npmjs.org/downloads/point/last-month/${name}`; // 按月统计 | ||
const packageDownloadLastWeekAPI = `https://api.npmjs.org/downloads/point/last-week/${name}`; // 按周统计 | ||
const packageDownloadLastDayAPI = `https://api.npmjs.org/downloads/point/last-day/${name}`; // 按天统计 | ||
const packageVersionAPI = `https://registry.npmjs.org/${name}`; // 包基本信息 | ||
|
||
const downloadCountLastMonthRes = await got(packageDownloadLastMonthAPI).json(); | ||
const downloadCountLastWeekRes = await got(packageDownloadLastWeekAPI).json(); | ||
const downloadCountLastDayRes = await got(packageDownloadLastDayAPI).json(); | ||
const packageVersionRes = await got(packageVersionAPI).json(); | ||
|
||
const packageVersion = packageVersionRes.time; | ||
const packageVersionList = []; | ||
for (const key in packageVersion) { | ||
packageVersionList.push({ | ||
version: key, | ||
time: packageVersion[key], | ||
}); | ||
} | ||
packageVersionList.reverse(); | ||
|
||
ctx.state.data = { | ||
title: `${name} - npm`, | ||
link: `https://www.npmjs.com/package/${name}`, | ||
description: `${name} - npm`, | ||
item: [ | ||
{ | ||
title: `${name} - npm`, | ||
description: art(path.join(__dirname, 'templates/package.art'), { | ||
packageDownloadCountLastMonth: downloadCountLastMonthRes.downloads, | ||
packageDownloadCountLastWeek: downloadCountLastWeekRes.downloads, | ||
packageDownloadCountLastDay: downloadCountLastDayRes.downloads, | ||
packageVersion: packageVersionList, | ||
}), | ||
link: `https://www.npmjs.com/package/${name}`, | ||
guid: `https://www.npmjs.com/package/${name}${packageVersion.modified}`, | ||
}, | ||
], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
'npmjs.com': { | ||
_name: 'npm', | ||
'.': [ | ||
{ | ||
title: '包', | ||
docs: 'https://docs.rsshub.app/program-update.html#npm', | ||
source: ['/package/:name'], | ||
target: '/npm/package/:name', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function (router) { | ||
router.get('/package/:name', require('./package')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h3>Download</h3> | ||
<p>Last Day: {{packageDownloadCountLastDay}}</p> | ||
<p>Last week: {{packageDownloadCountLastWeek}}</p> | ||
<p>Last month: {{packageDownloadCountLastMonth}}</p> | ||
<hr/> | ||
<h3>Version</h3> | ||
{{ each packageVersion}} | ||
<p>{{$value.version}}: {{$value.time}}</p> | ||
{{/each}} | ||
|