mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-01 14:57:14 +08:00
fix: use path param with regex for npm package feed (#14626)
* fix: use path param with regex for npm package feed
1. Don't include query params like `?code` in the package name.
2. Handle special cases when the org name of the package ends with
`package`, i.e. the package name is something like `@*package/*`.
* refactor: use map
---------
This commit is contained in:
@@ -3,7 +3,7 @@ import { art } from '@/utils/render';
|
||||
import * as path from 'node:path';
|
||||
|
||||
export default async (ctx) => {
|
||||
const name = ctx.req.url.split('package/')[1];
|
||||
const name = ctx.req.param('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}`; // 按天统计
|
||||
@@ -15,14 +15,12 @@ export default async (ctx) => {
|
||||
const packageVersionRes = await got(packageVersionAPI).json();
|
||||
|
||||
const packageVersion = packageVersionRes.time;
|
||||
const packageVersionList = [];
|
||||
for (const key in packageVersion) {
|
||||
packageVersionList.push({
|
||||
const packageVersionList = Object.keys(packageVersion)
|
||||
.map((key) => ({
|
||||
version: key,
|
||||
time: packageVersion[key],
|
||||
});
|
||||
}
|
||||
packageVersionList.reverse();
|
||||
}))
|
||||
.toReversed();
|
||||
|
||||
ctx.set('data', {
|
||||
title: `${name} - npm`,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export default (router) => {
|
||||
router.get('package/*', './package');
|
||||
// https://github.com/dword-design/package-name-regex/blob/master/src/index.js
|
||||
router.get('package/:name{(@[a-z0-9-~][a-z0-9-._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*}', './package');
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user