Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add 香港高登 #8109

Merged
merged 2 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,56 @@ column 为 third 时可选的 category:

</Route>

## 香港高登

### 頻道

<Route author="nczitzk" example="/hkgolden/BW" path="/hkgolden/:id?/:limit?/:sort?" :paramsDesc="['頻道,见下表,默认为吹水台,可在对应频道页的 URL 中找到', '類型,见下表,默认为全部', '排序,见下表,默认为最後回應時間']">

頻道

| 吹水台 | 高登熱 | 最新 | 時事台 | 娛樂台 |
| ------ | ------ | ---- | ------ | ------ |
| 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 |

</Route>

## 香水时代

### 首页
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4237,4 +4237,7 @@ router.get('/biodiscover/:channel?', lazyloadRouteHandler('./routes/biodiscover'
// 香港經濟日報
router.get('/hket/:category?', lazyloadRouteHandler('./routes/hket/index'));

// 香港高登
router.get('/hkgolden/:id?/:limit?/:sort?', lazyloadRouteHandler('./routes/hkgolden'));

module.exports = router;
110 changes: 110 additions & 0 deletions lib/routes/hkgolden/index.js
Original file line number Diff line number Diff line change
@@ -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 =
`<table border="1" cellspacing="0"><tr><td>${data.authorName}&nbsp(${dayjs(data.messageDate).format('YYYY-MM-DD hh:mm:ss')})</td></tr>` +
`<tr><td>${data.content.replace(/src="\/faces/g, 'src="https://assets.hkgolden.com/faces')}</td></tr>`;

for (const reply of data.replies) {
item.description +=
`<tr><td>${reply.authorName}&nbsp(${dayjs(reply.replyDate).format('YYYY-MM-DD hh:mm:ss')})</td></tr>` + `<tr><td>${reply.content.replace(/src="\/faces/g, 'src="https://assets.hkgolden.com/faces')}</td></tr>`;
}

item.description += '</table>';

return item;
})
)
);

ctx.state.data = {
title: `${channels[id]} (${sorts[sort]}|${limits[limit]}) - 香港高登`,
link: `${rootUrl}/channel/${id}`,
item: items,
};
};