-
Notifications
You must be signed in to change notification settings - Fork 9.1k
feat(route): add some nowcoder route #20712
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
Merged
+136
−0
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ec5b695
feat(route): add nowcoder hots content route
xia0ne e7e11a1
refactor(nowcoder): use query param for hots size
xia0ne 5412f9b
feat(route): add nowcoder interview experience
xia0ne dc7eba1
Merge branch 'DIYgod:master' into nowcoder
xia0ne 5b59dcf
fix(nowcoder/interview): align interview route with RSSHub conventions
xia0ne c4dc6f6
fix(nowcoder/hots): align hots router with RSShub conventions
xia0ne 863adec
fix(nowcoder): polish hots route
xia0ne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import type { Route } from '@/types'; | ||
| import got from '@/utils/got'; | ||
|
|
||
| export const route: Route = { | ||
| path: '/hots/:type?', | ||
| categories: ['bbs'], | ||
| example: '/nowcoder/hots/1?limit=20', | ||
| parameters: { | ||
| type: '热榜类型,`1` 指热议话题,`2` 指全站热贴,默认为 `1`', | ||
| }, | ||
| features: { | ||
| requireConfig: false, | ||
| requirePuppeteer: false, | ||
| antiCrawler: false, | ||
| supportBT: false, | ||
| supportPodcast: false, | ||
| supportScihub: false, | ||
| }, | ||
| radar: [ | ||
| { | ||
| source: ['mnowpick.nowcoder.com/m/discuss/hot'], | ||
| }, | ||
| ], | ||
| name: '牛客热榜', | ||
| description: '牛客热榜,包括热议话题和全站热贴', | ||
| maintainers: ['xia0ne'], | ||
| handler, | ||
| url: 'nowcoder.com/', | ||
| }; | ||
|
|
||
| async function handler(ctx) { | ||
| const type = ctx.req.param('type') ?? '1'; | ||
| const limit = Number.parseInt(ctx.req.query('limit') ?? '20', 10); | ||
| const size = Number.isFinite(limit) && limit > 0 ? limit : 20; | ||
|
|
||
| let link = ''; | ||
| if (type === '1') { | ||
| link = `https://gw-c.nowcoder.com/api/sparta/subject/hot-subject?limit=${size}&_=${Date.now()}&t=`; | ||
| const responseBody = (await got.get(link)).data; | ||
| if (responseBody.code !== 0) { | ||
| throw new Error(`接口错误,错误代码:${responseBody.code},错误原因:${responseBody.msg}`); | ||
| } | ||
| const data = responseBody.data.result; | ||
| return { | ||
| title: '牛客网-热议话题', | ||
| link: 'https://mnowpick.nowcoder.com/m/discuss/hot', | ||
| description: '牛客网-热议话题', | ||
| item: data.map((item) => ({ | ||
| title: item.content, | ||
| description: `<img src="${item.numberIcon}" alt="rank">`, | ||
| link: `https://www.nowcoder.com/creation/subject/${item.uuid}`, | ||
| })), | ||
| }; | ||
| } else if (type === '2') { | ||
| link = `https://gw-c.nowcoder.com/api/sparta/hot-search/top-hot-pc?size=${size}&_=${Date.now()}&t=`; | ||
| const responseBody = (await got.get(link)).data; | ||
| if (responseBody.code !== 0) { | ||
| throw new Error(`接口错误,错误代码: ${responseBody.code},错误原因: ${responseBody.msg}`); | ||
| } | ||
| const data = responseBody.data.result; | ||
| return { | ||
| title: '牛客网-全站热贴', | ||
| link: 'https://mnowpick.nowcoder.com/m/discuss/hot', | ||
| description: '牛客网-全站热贴', | ||
| item: data.map((item) => ({ | ||
| title: item.title, | ||
| link: `https://www.nowcoder.com/feed/main/detail/${item.uuid}`, | ||
| })), | ||
| }; | ||
| } else { | ||
| throw new Error('Invalid type parameter'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import type { Route } from '@/types'; | ||
| import got from '@/utils/got'; | ||
| import { parseDate } from '@/utils/parse-date'; | ||
|
|
||
| export const route: Route = { | ||
| path: '/interview/:jobId', | ||
| categories: ['bbs'], | ||
| example: '/nowcoder/interview/11200', | ||
| parameters: { | ||
| jobId: '岗位 ID,如 11200(全部)、11002(Java)', | ||
| }, | ||
| features: { | ||
| requireConfig: false, | ||
| requirePuppeteer: false, | ||
| antiCrawler: false, | ||
| supportBT: false, | ||
| supportPodcast: false, | ||
| supportScihub: false, | ||
| }, | ||
| radar: [ | ||
| { | ||
| source: ['www.nowcoder.com/interview/'], | ||
| }, | ||
| ], | ||
| name: '牛客面试经验', | ||
| description: `牛客面试经验`, | ||
| maintainers: ['xia0ne'], | ||
| handler, | ||
| url: 'nowcoder.com/', | ||
| }; | ||
| async function handler(ctx) { | ||
| const jobId = ctx.req.param('jobId'); | ||
|
|
||
| const link = `https://gw-c.nowcoder.com/api/sparta/job-experience/experience/job/list?_=${Date.now()}`; | ||
| const payload = { | ||
| jobId, | ||
| level: 3, | ||
| order: 3, | ||
| page: 1, | ||
| }; | ||
|
|
||
| const responseBody = (await got.post(link, { json: payload })).data; | ||
| if (responseBody.code !== 0) { | ||
| throw new Error(`接口错误,错误代码:${responseBody.code},错误原因:${responseBody.msg}`); | ||
| } | ||
|
|
||
| const items = (responseBody.data.records ?? []) | ||
| .map((r) => r?.momentData) | ||
| .filter((m) => m?.uuid) | ||
| .map((m) => ({ | ||
| title: m.title || m.content || '面经', | ||
| description: m.content ?? '', | ||
| link: `https://www.nowcoder.com/feed/main/detail/${m.uuid}`, | ||
| pubDate: parseDate(m.createdAt), | ||
| })); | ||
xia0ne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return { | ||
| title: '牛客网-面试经验', | ||
| link: 'https://www.nowcoder.com/interview/', | ||
| description: '牛客网面试经验', | ||
| item: items, | ||
| }; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.