fix(route): Fix afdian (#14892)

* 迁移爱发电

* Update lib/routes/afdian/explore.ts

---------
This commit is contained in:
zcw159357 2024-03-22 12:20:49 +08:00 committed by GitHub
parent 2158895f01
commit a9f06f453d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 47 additions and 10 deletions

View File

@ -756,8 +756,8 @@ router.get('/nosetime/home', lazyloadRouteHandler('./routes/nosetime/home'));
router.get('/daxiaamu/home', lazyloadRouteHandler('./routes/daxiaamu/home'));
// 爱发电
router.get('/afdian/explore/:type?/:category?', lazyloadRouteHandler('./routes/afdian/explore'));
router.get('/afdian/dynamic/:uid', lazyloadRouteHandler('./routes/afdian/dynamic'));
// router.get('/afdian/explore/:type?/:category?', lazyloadRouteHandler('./routes/afdian/explore'));
// router.get('/afdian/dynamic/:uid', lazyloadRouteHandler('./routes/afdian/dynamic'));
// Simons Foundation
router.get('/simonsfoundation/articles', lazyloadRouteHandler('./routes/simonsfoundation/articles'));

View File

@ -1,7 +1,17 @@
const got = require('@/utils/got');
import got from '@/utils/got';
module.exports = async (ctx) => {
const url_slug = ctx.params.uid.replace('@', '');
export const route: Route = {
path: '/dynamic/:uid?',
categories: ['other'],
example: '/afdian/dynamic/@afdian',
parameters: { uid: '用户id用户动态页面url里可找到' },
name: '用户动态',
maintainers: ['sanmmm'],
handler,
};
async function handler(ctx) {
const url_slug = ctx.req.param('uid').replace('@', '');
const baseUrl = 'https://afdian.net';
const userInfoRes = await got(`${baseUrl}/api/user/get-profile-by-slug`, {
searchParams: {
@ -26,7 +36,7 @@ module.exports = async (ctx) => {
pubDate: new Date(Number(publish_time) * 1000).toUTCString(),
};
});
ctx.state.data = {
return {
title: `${name}的爱发电动态`,
description: `${name}的爱发电动态`,
image: avatar,

View File

@ -1,4 +1,4 @@
const got = require('@/utils/got');
import got from '@/utils/got';
const categoryMap = {
: '',
@ -26,8 +26,29 @@ const typeToLabel = {
hot: '人气',
};
module.exports = async (ctx) => {
const { type = 'rec', category = '所有' } = ctx.params;
export const route: Route = {
path: '/explore/:type/:category?',
categories: ['other'],
example: '/afdian/explore/hot/所有',
parameters: { type: '分类', category: '目录类型,默认为 `所有`' },
name: '发现用户',
maintainers: ['sanmmm'],
description: `分类
| | |
| ---- | ---- |
| rec | hot |
| | | | | | | | | | Vtuber | | | | | | | | |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ------ | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| | | | | | | | | | Vtuber | | | | | | | | |`,
handler,
};
async function handler(ctx) {
const { type = 'rec', category = '所有' } = ctx.req.param();
const baseUrl = 'https://afdian.net';
const link = `${baseUrl}/api/creator/list`;
const res = await got(link, {
@ -48,7 +69,7 @@ module.exports = async (ctx) => {
link: `${baseUrl}/@${item.url_slug}`,
};
});
ctx.state.data = {
return {
title: `爱发电-创作者 (按 ${category}/${typeToLabel[type]})`,
description: `爱发电-发现创作者 (按 ${category}/${typeToLabel[type]})`,
link: `${baseUrl}/explore`,

View File

@ -0,0 +1,6 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: '爱发电',
url: 'afdian.net',
};