From a3b989c39d8a4f6d4d49c8fd3f57a6bea3fcfa48 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 15:41:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E9=A6=99=E6=B8=AF?= =?UTF-8?q?=E9=AB=98=E7=99=BB=20(#8109)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: DIYgod --- docs/new-media.md | 50 ++++++++++++++++ lib/router.js | 3 + lib/routes/hkgolden/index.js | 110 +++++++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 lib/routes/hkgolden/index.js diff --git a/docs/new-media.md b/docs/new-media.md index 7a481a9827..10906e9261 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2644,6 +2644,56 @@ column 为 third 时可选的 category: +## 香港高登 + +### 頻道 + + + +頻道 + +| 吹水台 | 高登熱 | 最新 | 時事台 | 娛樂台 | +| ------ | ------ | ---- | ------ | ------ | +| BW | HT | NW | CA | ET | + +| 體育台 | 財經台 | 學術台 | 講故台 | 創意台 | +| ------ | ------ | ------ | ------ | ------ | +| SP | FN | ST | SY | EP | + +| 硬件台 | 電訊台 | 軟件台 | 手機台 | Apps 台 | +| ------ | ------ | ------ | ------ | ------- | +| HW | IN | SW | MP | AP | + +| 遊戲台 | 飲食台 | 旅遊台 | 潮流台 | 動漫台 | +| ------ | ------ | ------ | ------ | ------ | +| GM | ED | TR | CO | AN | + +| 玩具台 | 音樂台 | 影視台 | 攝影台 | 汽車台 | +| ------ | ------ | ------ | ------ | ------ | +| TO | MU | VI | DC | TS | + +| 上班台 | 感情台 | 校園台 | 親子台 | 寵物台 | +| ------ | ------ | ------ | ------ | ------ | +| WK | LV | SC | BB | PT | + +| 站務台 | 電台 | 活動台 | 買賣台 | 直播台 | 成人台 | 考古台 | +| ------ | ---- | ------ | ------ | ------ | ------ | ------ | +| MB | RA | AC | BS | JT | AU | OP | + +排序 + +| 最後回應時間 | 發表時間 | 熱門 | +| ------------ | -------- | ---- | +| 0 | 1 | 2 | + +類型 + +| 全部 | 正式 | 公海 | +| ---- | ---- | ---- | +| -1 | 1 | 0 | + + + ## 香港討論區 ### 版塊 diff --git a/lib/router.js b/lib/router.js index e93233cf5c..cfbfb5a058 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4210,6 +4210,9 @@ router.get('/right/forum/:id?', lazyloadRouteHandler('./routes/right/forum')); // 香港經濟日報 router.get('/hket/:category?', lazyloadRouteHandler('./routes/hket/index')); +// 香港高登 +router.get('/hkgolden/:id?/:limit?/:sort?', lazyloadRouteHandler('./routes/hkgolden')); + // 香港討論區 router.get('/discuss/:fid', lazyloadRouteHandler('./routes/discuss')); diff --git a/lib/routes/hkgolden/index.js b/lib/routes/hkgolden/index.js new file mode 100644 index 0000000000..a56b2d4bac --- /dev/null +++ b/lib/routes/hkgolden/index.js @@ -0,0 +1,110 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const dayjs = require('dayjs'); + +const channels = { + BW: '吹水台', + HT: '高登熱', + NW: '最 新', + CA: '時事台', + ET: '娛樂台', + SP: '體育台', + FN: '財經台', + ST: '學術台', + SY: '講故台', + EP: '創意台', + HW: '硬件台', + IN: '電訊台', + SW: '軟件台', + MP: '手機台', + AP: 'Apps台', + GM: '遊戲台', + ED: '飲食台', + TR: '旅遊台', + CO: '潮流台', + AN: '動漫台', + TO: '玩具台', + MU: '音樂台', + VI: '影視台', + DC: '攝影台', + TS: '汽車台', + WK: '上班台', + LV: '感情台', + SC: '校園台', + BB: '親子台', + PT: '寵物台', + MB: '站務台', + RA: '電 台', + AC: '活動台', + BS: '買賣台', + JT: '直播台', + AU: '成人台', + OP: '考古台', +}; + +const limits = { + '-1': '全部', + 1: '正式', + 0: '公海', +}; + +const sorts = { + 0: '最後回應時間', + 1: '發表時間', + 2: '熱門', +}; + +module.exports = async (ctx) => { + const id = ctx.params.id || 'BW'; + const sort = ctx.params.sort || '0'; + const limit = ctx.params.limit || '-1'; + + const rootUrl = 'https://forum.hkgolden.com'; + const apiRootUrl = 'https://api.hkgolden.com'; + const apiUrl = `${apiRootUrl}/v1/topics/HT/1?sort=${sort}&limit=${limit}`; + + const response = await got({ + method: 'get', + url: apiUrl, + }); + + const list = response.data.data.list.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 30).map((item) => ({ + link: item.id, + title: item.title, + author: item.authorName, + pubDate: parseDate(item.orderDate), + })); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: `${apiRootUrl}/v1/view/${item.link}`, + }); + + const data = detailResponse.data.data; + + item.link = `${rootUrl}/thread/${item.id}`; + item.description = + `` + + ``; + + for (const reply of data.replies) { + item.description += + `` + ``; + } + + item.description += '
${data.authorName} (${dayjs(data.messageDate).format('YYYY-MM-DD hh:mm:ss')})
${data.content.replace(/src="\/faces/g, 'src="https://assets.hkgolden.com/faces')}
${reply.authorName} (${dayjs(reply.replyDate).format('YYYY-MM-DD hh:mm:ss')})
${reply.content.replace(/src="\/faces/g, 'src="https://assets.hkgolden.com/faces')}
'; + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${channels[id]} (${sorts[sort]}|${limits[limit]}) - 香港高登`, + link: `${rootUrl}/channel/${id}`, + item: items, + }; +};