From 91ce25bcff1684fc695fa775f87d74b86c855955 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 4 Jan 2024 18:15:56 +0000 Subject: [PATCH] feat(route): recover gofans (#14183) --- lib/v2/gofans/index.js | 41 +++++++++++++++++++++++++ lib/v2/gofans/maintainer.js | 3 ++ lib/v2/gofans/radar.js | 13 ++++++++ lib/v2/gofans/router.js | 3 ++ lib/v2/gofans/templates/description.art | 7 +++++ website/docs/routes/program-update.mdx | 6 ++++ 6 files changed, 73 insertions(+) create mode 100644 lib/v2/gofans/index.js create mode 100644 lib/v2/gofans/maintainer.js create mode 100644 lib/v2/gofans/radar.js create mode 100644 lib/v2/gofans/router.js create mode 100644 lib/v2/gofans/templates/description.art diff --git a/lib/v2/gofans/index.js b/lib/v2/gofans/index.js new file mode 100644 index 0000000000..78665a6475 --- /dev/null +++ b/lib/v2/gofans/index.js @@ -0,0 +1,41 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const { join } = require('path'); + +module.exports = async (ctx) => { + const { kind = '' } = ctx.params; + const baseUrl = 'https://gofans.cn'; + + const { data: response } = await got('https://api.gofans.cn/v1/web/app_records', { + headers: { + origin: baseUrl, + }, + searchParams: { + limit: 20, + kind: kind && (kind === 'macos' ? 1 : 2), + page: 1, + }, + }); + + const items = response.data.map((item) => ({ + title: `「${item.price === '0.00' ? '免费' : '降价'}」-「${item.kind === 1 ? 'macOS' : 'iOS'}」${item.name}`, + description: art(join(__dirname, 'templates/description.art'), { + icon: item.icon, + originalPrice: item.original_price, + price: item.price, + kind: item.kind, + description: item.description.replaceAll('\n', '
'), + }), + pubDate: parseDate(item.updated_at, 'X'), + link: new URL(`/app/${item.uuid}`, baseUrl).href, + category: item.primary_genre_name, + })); + + ctx.state.data = { + title: '最新限免 / 促销应用', + link: baseUrl, + description: 'GoFans:最新限免 / 促销应用', + item: items, + }; +}; diff --git a/lib/v2/gofans/maintainer.js b/lib/v2/gofans/maintainer.js new file mode 100644 index 0000000000..c820bec4fa --- /dev/null +++ b/lib/v2/gofans/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:kind?': ['HenryQW'], +}; diff --git a/lib/v2/gofans/radar.js b/lib/v2/gofans/radar.js new file mode 100644 index 0000000000..b8980cb275 --- /dev/null +++ b/lib/v2/gofans/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'gofans.cn': { + _name: 'GoFans', + '.': [ + { + title: '最新限免 / 促销应用', + docs: 'https://docs.rsshub.app/program-update#gofans', + source: ['/limited/:kind?', '/'], + target: (params) => `/gofans${(params.kind && (params.kind === 'macos' ? '/macos' : '/ios')) || ''}`, + }, + ], + }, +}; diff --git a/lib/v2/gofans/router.js b/lib/v2/gofans/router.js new file mode 100644 index 0000000000..7267a807a3 --- /dev/null +++ b/lib/v2/gofans/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:kind?', require('./index')); +}; diff --git a/lib/v2/gofans/templates/description.art b/lib/v2/gofans/templates/description.art new file mode 100644 index 0000000000..1126b1bb67 --- /dev/null +++ b/lib/v2/gofans/templates/description.art @@ -0,0 +1,7 @@ + +
+原价:¥{{ originalPrice }} -> 现价:¥{{ price }} +
+平台:{{ kind === 1 ? 'macOS' : 'iOS' }} +
+{{@ description }} diff --git a/website/docs/routes/program-update.mdx b/website/docs/routes/program-update.mdx index 03f96da3c8..506dae42bb 100644 --- a/website/docs/routes/program-update.mdx +++ b/website/docs/routes/program-update.mdx @@ -266,6 +266,12 @@ Need to configure `CIVITAI_COOKIE` to obtain image information of NSFW models. +## GoFans {#gofans} + +### 最新限免 / 促销应用 {#gofans-zui-xin-xian-mian-cu-xiao-ying-yong} + + + ## Greasy Fork {#greasy-fork} ### Script Update {#greasy-fork-script-update}