diff --git a/lib/router.js b/lib/router.js index 0c89d215e..6acc307b7 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes-deprecated/afdian/dynamic.js b/lib/routes/afdian/dynamic.ts similarity index 72% rename from lib/routes-deprecated/afdian/dynamic.js rename to lib/routes/afdian/dynamic.ts index b25a3d605..b6260495b 100644 --- a/lib/routes-deprecated/afdian/dynamic.js +++ b/lib/routes/afdian/dynamic.ts @@ -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, diff --git a/lib/routes-deprecated/afdian/explore.js b/lib/routes/afdian/explore.ts similarity index 63% rename from lib/routes-deprecated/afdian/explore.js rename to lib/routes/afdian/explore.ts index bccd77236..8007b3de7 100644 --- a/lib/routes-deprecated/afdian/explore.js +++ b/lib/routes/afdian/explore.ts @@ -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`, diff --git a/lib/routes/afdian/namespace.ts b/lib/routes/afdian/namespace.ts new file mode 100644 index 000000000..3c4d181d7 --- /dev/null +++ b/lib/routes/afdian/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '爱发电', + url: 'afdian.net', +};