-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
Open
xia0ne
wants to merge
6
commits into
DIYgod:master
Choose a base branch
from
xia0ne:nowcoder
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+139
−0
Open
Changes from 3 commits
Commits
Show all changes
6 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 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,77 @@ | ||
| import type { Route } from '@/types'; | ||
| import got from '@/utils/got'; | ||
|
|
||
| export const route: Route = { | ||
| path: '/hots/:type?', | ||
| categories: ['bbs'], | ||
| example: '/nowcoder/hots/1?size=20', | ||
| parameters: { | ||
| type: '热榜类型, `1` 指热议话题, `2`全站热贴, 默认为热议话题', | ||
| }, | ||
| features: { | ||
| requireConfig: false, | ||
| requirePuppeteer: false, | ||
| antiCrawler: false, | ||
| supportBT: false, | ||
| supportPodcast: false, | ||
| supportScihub: false, | ||
| }, | ||
| radar: [ | ||
| { | ||
| source: ['mnowpick.nowcoder.com/m/discuss/hot'], | ||
| }, | ||
| ], | ||
| name: '牛客热榜', | ||
| description: `牛客热榜,包括热议话题和全站热贴 | ||
| 可选参数: | ||
| - size: 返回列表大小(query 参数,默认 20) | ||
| `, | ||
| maintainers: ['xia0ne'], | ||
| handler, | ||
| url: 'nowcoder.com/', | ||
| }; | ||
|
|
||
| async function handler(ctx) { | ||
| const type = ctx.req.param('type') ?? '1'; | ||
| const rawSize = ctx.req.query('size'); | ||
| const sizeNum = Number.parseInt(rawSize ?? '20', 10); | ||
| const size = Number.isFinite(sizeNum) && sizeNum > 0 ? sizeNum : 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}>`, | ||
| 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,81 @@ | ||
| import type { Route } from '@/types'; | ||
| import got from '@/utils/got'; | ||
|
|
||
| export const route: Route = { | ||
| path: '/interview/:jobId', | ||
| categories: ['bbs'], | ||
| example: '/nowcoder/interview/11200?page=1', | ||
| parameters: { | ||
| jobId: ` | ||
| (必须)岗位ID, example: | ||
| 11200: 全部 | ||
| 11002: Java | ||
| `, | ||
xia0ne marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| features: { | ||
| requireConfig: false, | ||
| requirePuppeteer: false, | ||
| antiCrawler: false, | ||
| supportBT: false, | ||
| supportPodcast: false, | ||
| supportScihub: false, | ||
| }, | ||
| radar: [ | ||
| { | ||
| source: ['https://www.nowcoder.com/interview/'], | ||
xia0ne marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| ], | ||
| name: '牛客面试经验', | ||
| description: `牛客面试经验 | ||
| 可选参数: | ||
| - page (query 表示是第几页) | ||
| - companyList(query 公司列表,逗号分隔 example: 134,138 | ||
| `, | ||
| maintainers: ['xia0ne'], | ||
| handler, | ||
| url: 'nowcoder.com/', | ||
| }; | ||
| async function handler(ctx) { | ||
| const jobId = ctx.req.param('jobId'); | ||
| const page = ctx.req.query('page') ?? '1'; | ||
xia0ne marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const companyParam = ctx.req.query('companyList'); // string | undefined | ||
xia0ne marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const companyList = companyParam | ||
| ? companyParam | ||
| .split(',') | ||
| .map((c) => Number(c.trim())) | ||
| .filter((n) => !Number.isNaN(n)) | ||
| : []; | ||
| const link = `https://gw-c.nowcoder.com/api/sparta/job-experience/experience/job/list?_=${Date.now()}`; | ||
| const payload = { | ||
| companyList, | ||
| jobId, | ||
| level: 3, | ||
| order: 3, | ||
| page, | ||
| }; | ||
| const responseBody = ( | ||
| await got.post(link, { | ||
| json: payload, | ||
| }) | ||
| ).data; | ||
| if (responseBody.code !== 0) { | ||
| throw new Error(`接口错误,错误代码:${responseBody.code},错误原因:${responseBody.msg}`); | ||
| } | ||
| const data = responseBody.data.records; | ||
| const items = (data ?? []) | ||
| .map((r) => r?.momentData) | ||
| .filter(Boolean) | ||
| .map((m) => ({ | ||
| title: m.title ?? m.content?.slice(0, 60) ?? '面经', | ||
xia0ne marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| description: m.content ?? '', | ||
| link: m.uuid ? `https://www.nowcoder.com/feed/main/detail/${m.uuid}` : 'https://www.nowcoder.com/interview/', | ||
xia0ne marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| })); | ||
xia0ne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return { | ||
| title: '牛客网-面试经验', | ||
| link: 'https://www.nowcoder.com/interview/', | ||
| description: '面试经验', | ||
| item: items, | ||
| }; | ||
| } | ||
Oops, something went wrong.
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.