Skip to content

Commit

Permalink
Merge pull request #124 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Mar 3, 2024
2 parents cafab54 + 172f6cf commit 5dd9a45
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/middleware/sentry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MiddlewareHandler } from 'hono';
import logger from '@/utils/logger';
import { config } from '@/config';
import Sentry from '@sentry/node';
import * as Sentry from '@sentry/node';
import { getRouteNameFromPath } from '@/utils/helpers';

if (config.sentry.dsn) {
Expand Down
35 changes: 35 additions & 0 deletions lib/routes/bilibili/like.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import got from '@/utils/got';
const cache = require('./cache');
const utils = require('./utils');
import { parseDate } from '@/utils/parse-date';

module.exports = async (ctx) => {
const uid = ctx.req.param('uid');
const disableEmbed = ctx.req.param('disableEmbed');

const name = await cache.getUsernameFromUID(ctx, uid);

const response = await got({
url: `https://api.bilibili.com/x/space/like/video?vmid=${uid}`,
headers: {
Referer: `https://space.bilibili.com/${uid}/`,
},
});
const { data, code, message } = response.data;
if (code) {
throw new Error(message ?? code);
}

ctx.set('data', {
title: `${name} 的 bilibili 点赞视频`,
link: `https://space.bilibili.com/${uid}`,
description: `${name} 的 bilibili 点赞视频`,
item: data.list.map((item) => ({
title: item.title,
description: `${item.desc}${disableEmbed ? '' : `<br><br>${utils.iframe(item.aid)}`}<br><img src='${item.pic}'>`,
pubDate: parseDate(item.pubdate * 1000),
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`,
author: item.owner.name,
})),
});
};
1 change: 1 addition & 0 deletions lib/routes/bilibili/maintainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {
'/user/fav/:uid/:disableEmbed?': ['DIYgod'],
'/user/followers/:uid/:loginUid': ['Qixingchen'],
'/user/followings/:uid/:loginUid': ['Qixingchen'],
'/user/like/:uid/:disableEmbed?': ['ygguorun'],
'/user/video/:uid/:disableEmbed?': ['DIYgod'],
'/video/danmaku/:bvid/:pid?': ['Qixingchen'],
'/video/page/:bvid/:disableEmbed?': ['sxzz'],
Expand Down
6 changes: 6 additions & 0 deletions lib/routes/bilibili/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ module.exports = {
source: '/:uid',
target: '/bilibili/user/coin/:uid',
},
{
title: 'UP 主点赞视频',
docs: 'https://docs.rsshub.app/routes/social-media#bilibili',
source: '/:uid',
target: '/bilibili/user/like/:uid',
},
{
title: 'UP 主粉丝',
docs: 'https://docs.rsshub.app/routes/social-media#bilibili',
Expand Down
1 change: 1 addition & 0 deletions lib/routes/bilibili/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default (router) => {
router.get('/user/fav/:uid/:disableEmbed?', './user-fav');
router.get('/user/followers/:uid/:loginUid', './followers');
router.get('/user/followings/:uid/:loginUid', './followings');
router.get('/user/like/:uid/:disableEmbed?', './like');
router.get('/user/video/:uid/:disableEmbed?', './video');
router.get('/user/video-all/:uid/:disableEmbed?', './video-all');
router.get('/video/danmaku/:bvid/:pid?', './danmaku');
Expand Down
12 changes: 5 additions & 7 deletions lib/routes/npm/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`; // 按天统计
Expand All @@ -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`,
Expand Down
3 changes: 2 additions & 1 deletion lib/routes/npm/router.js
Original file line number Diff line number Diff line change
@@ -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');
};
6 changes: 3 additions & 3 deletions lib/routes/radio-canada/latest.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export default async (ctx) => {
});

const $ = load(detailResponse.data);
const rcState = $('script:contains("window._rcState_ = JSON.parse")')
const rcState = $('script:contains("window._rcState_ = ")')
.text()
.match(/JSON\.parse\((".*")\);/)[1];
const rcStateJson = JSON.parse(JSON.parse(rcState));
.match(/window\._rcState_ = (.*);/)[1];
const rcStateJson = JSON.parse(rcState);
const news = Object.values(rcStateJson.pagesV2.pages)[0];
item.description = news.data.newsStory.body.html.replaceAll('\\n', '<br>');

Expand Down
4 changes: 4 additions & 0 deletions website/docs/routes/social-media.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@

<Route author="DIYgod" example="/bilibili/user/coin/208259" path="/bilibili/user/coin/:uid/:disableEmbed?" paramsDesc={['用户 id, 可在 UP 主主页中找到', '默认为开启内嵌视频, 任意值为关闭']} radar="1" />

### UP 主点赞视频 {#bilibili-up-zhu-dian-zan-shi-pin}

<Route author="ygguorun" example="/bilibili/user/like/208259" path="/bilibili/user/like/:uid/:disableEmbed?" paramsDesc={['用户 id, 可在 UP 主主页中找到', '默认为开启内嵌视频, 任意值为关闭']} radar="1" />

### UP 主粉丝 {#bilibili-up-zhu-fen-si}

<Route author="Qixingchen" example="/bilibili/user/followers/2267573/3" path="/bilibili/user/followers/:uid/:loginUid" paramsDesc={['用户 id, 可在 UP 主主页中找到','用于登入的用户id,需要配置对应的 Cookie 值']} radar="1" configRequired="1">
Expand Down

0 comments on commit 5dd9a45

Please sign in to comment.