diff --git a/AGENTS.md b/AGENTS.md index 771b053..4c0fef8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -24,4 +24,8 @@ export type HotListItem = { ## hotnow 模块 -单独的 api 的模块,纯粹负责获取数据,不涉及任何 UI 相关的东西。这样做的好处是可以让数据获取和 UI 展示解耦,方便后续维护和扩展。 \ No newline at end of file +单独的 api 的模块,纯粹负责获取数据,不涉及任何 UI 相关的东西。这样做的好处是可以让数据获取和 UI 展示解耦,方便后续维护和扩展。 + +## 其他模块 + +使用 bun 运行 \ No newline at end of file diff --git a/src/hotnow/36kr/README.md b/src/hotnow/36kr/README.md index be38dd7..2910ab7 100644 --- a/src/hotnow/36kr/README.md +++ b/src/hotnow/36kr/README.md @@ -19,4 +19,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/36kr/api.ts b/src/hotnow/36kr/api.ts index b566882..a0d5d44 100644 --- a/src/hotnow/36kr/api.ts +++ b/src/hotnow/36kr/api.ts @@ -29,7 +29,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.code === 0) { - const result: HotListItem[] = responseBody.data?.hotRankList.map((v) => { + const result: HotListItem[] = responseBody.data?.hotRankList.map((v: any) => { return { id: v.itemId, title: v?.templateMaterial?.widgetTitle, @@ -48,4 +48,6 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); +} diff --git a/src/hotnow/36kr/origin.d.ts b/src/hotnow/36kr/origin.d.ts new file mode 100644 index 0000000..400b9d6 --- /dev/null +++ b/src/hotnow/36kr/origin.d.ts @@ -0,0 +1,14 @@ +export interface OriginData { + itemId: number; + itemType: number; + templateMaterial: { + widgetTitle: string; + widgetImage: string; + statRead: number; + [key: string]: any; + }; + route: string; + siteId: number; + publishTime: number; + [key: string]: any; +} diff --git a/src/hotnow/baidu/README.md b/src/hotnow/baidu/README.md index 8e74aa1..30e9eba 100644 --- a/src/hotnow/baidu/README.md +++ b/src/hotnow/baidu/README.md @@ -17,4 +17,8 @@ url: string; // PC 端搜索链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/baidu/api.ts b/src/hotnow/baidu/api.ts index b4ff15d..c48336d 100644 --- a/src/hotnow/baidu/api.ts +++ b/src/hotnow/baidu/api.ts @@ -15,16 +15,16 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.success) { - const result: HotListItem[] = responseBody.data.cards[0]?.content[0]?.content.map((v) => { - return { - id: v.index, - title: v.word, - label: v.newHotName, - url: `https://www.baidu.com/s?wd=${encodeURIComponent(v.word)}`, - mobileUrl: v.url, - originData: v, - }; - }); + const result: HotListItem[] = responseBody.data.cards[0]?.content[0]?.content.map((v, idx) => { + return { + id: v.index ?? v.isTop ? idx + 1 : v.index, + title: v.word, + label: v.newHotName, + url: `https://www.baidu.com/s?wd=${encodeURIComponent(v.word)}`, + mobileUrl: v.url, + originData: v, + }; + }); return result; } return []; @@ -33,4 +33,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/baidu/origin.d.ts b/src/hotnow/baidu/origin.d.ts new file mode 100644 index 0000000..fcce627 --- /dev/null +++ b/src/hotnow/baidu/origin.d.ts @@ -0,0 +1,10 @@ +export interface OriginData { + isTop: boolean; + index?: number; + word: string; + url: string; + newHotName?: string; + hotTag?: string; + newHotTag?: Record; + [key: string]: any; +} diff --git a/src/hotnow/baidutieba/README.md b/src/hotnow/baidutieba/README.md index 8c8f51a..454aaed 100644 --- a/src/hotnow/baidutieba/README.md +++ b/src/hotnow/baidutieba/README.md @@ -19,4 +19,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/baidutieba/api.ts b/src/hotnow/baidutieba/api.ts index d2c317e..054e702 100644 --- a/src/hotnow/baidutieba/api.ts +++ b/src/hotnow/baidutieba/api.ts @@ -15,7 +15,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.errmsg === 'success') { - const result: HotListItem[] = responseBody.data.bang_topic.topic_list.map((v) => { + const result: HotListItem[] = responseBody.data.bang_topic.topic_list.map((v: any) => { return { id: v.topic_id.toString(), title: v.topic_name, @@ -35,4 +35,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/baidutieba/origin.d.ts b/src/hotnow/baidutieba/origin.d.ts new file mode 100644 index 0000000..295cece --- /dev/null +++ b/src/hotnow/baidutieba/origin.d.ts @@ -0,0 +1,17 @@ +export interface OriginData { + topic_id: number; + topic_name: string; + topic_desc: string; + topic_pic: string; + discuss_num: number; + topic_url: string; + abstract?: string; + tag?: number; + idx_num?: number; + create_time?: number; + content_num?: number; + topic_avatar?: string; + is_video_topic?: string; + topic_default_avatar?: string; + [key: string]: any; +} diff --git a/src/hotnow/bilibili/README.md b/src/hotnow/bilibili/README.md index c613d7c..b721808 100644 --- a/src/hotnow/bilibili/README.md +++ b/src/hotnow/bilibili/README.md @@ -22,6 +22,10 @@ } ``` +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) + ## 响应示例 ```json diff --git a/src/hotnow/bilibili/api.ts b/src/hotnow/bilibili/api.ts index 5b15c90..c61c034 100644 --- a/src/hotnow/bilibili/api.ts +++ b/src/hotnow/bilibili/api.ts @@ -24,7 +24,7 @@ export const main = async function(): Promise { if (!data) { return []; } - const result: HotListItem[] = data.map((v) => { + const result: HotListItem[] = data.map((v: any) => { return { id: v.bvid, title: v.title, @@ -42,4 +42,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/bilibili/origin.d.ts b/src/hotnow/bilibili/origin.d.ts new file mode 100644 index 0000000..c7b7f3f --- /dev/null +++ b/src/hotnow/bilibili/origin.d.ts @@ -0,0 +1,50 @@ +export interface OriginData { + aid: number; + videos: number; + tid: number; + tname: string; + copyright: number; + pic: string; + title: string; + pubdate: number; + ctime: number; + desc: string; + state: number; + duration: number; + mission_id?: number; + rights: Record; + owner: { + mid: number; + name: string; + face: string; + [key: string]: any; + }; + stat: { + view: number; + danmaku: number; + reply: number; + favorite: number; + coin: number; + share: number; + now_rank: number; + his_rank: number; + like: number; + [key: string]: any; + }; + dynamic: string; + cid: number; + dimension: { + width: number; + height: number; + rotate: number; + [key: string]: any; + }; + short_link_v2: string; + first_frame?: string; + pub_location?: string; + cover43?: string; + bvid: string; + score?: number; + enable_vt?: number; + [key: string]: any; +} diff --git a/src/hotnow/csdn/README.md b/src/hotnow/csdn/README.md index b4f679c..a54fa40 100644 --- a/src/hotnow/csdn/README.md +++ b/src/hotnow/csdn/README.md @@ -17,4 +17,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/csdn/api.ts b/src/hotnow/csdn/api.ts index 86606b8..992e55f 100644 --- a/src/hotnow/csdn/api.ts +++ b/src/hotnow/csdn/api.ts @@ -21,7 +21,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.code === 200) { - const result: HotListItem[] = responseBody.data.map((v) => { + const result: HotListItem[] = responseBody.data.map((v: any) => { return { id: v.articleDetailUrl, title: v.articleTitle, @@ -39,4 +39,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/csdn/origin.d.ts b/src/hotnow/csdn/origin.d.ts new file mode 100644 index 0000000..8dc2322 --- /dev/null +++ b/src/hotnow/csdn/origin.d.ts @@ -0,0 +1,22 @@ +export interface OriginData { + period: string; + hotRankScore: string; + pcHotRankScore: string; + loginUserIsFollow: boolean; + nickName: string; + avatarUrl: string; + userName: string; + articleTitle: string; + articleDetailUrl: string; + commentCount: string; + favorCount: string; + viewCount: string; + hotComment: string | null; + picList: string[]; + isNew: string | null; + productId: string; + productType: string; + recommendType: string; + report_data: string | null; + [key: string]: any; +} diff --git a/src/hotnow/dongchedi/README.md b/src/hotnow/dongchedi/README.md index c316dcc..de97521 100644 --- a/src/hotnow/dongchedi/README.md +++ b/src/hotnow/dongchedi/README.md @@ -17,4 +17,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/dongchedi/api.ts b/src/hotnow/dongchedi/api.ts index 9e849a2..874ed67 100644 --- a/src/hotnow/dongchedi/api.ts +++ b/src/hotnow/dongchedi/api.ts @@ -3,7 +3,7 @@ import { HotListItem } from "../type"; export const label = { name: '懂车帝-热搜榜', - icon: 'https://www.dongchedi.com/favicon.ico', + icon: 'https://p6-dcd.byteimg.com/img/tos-cn-i-dcdx/4fbb15493036489f950935fa4d86dd8e~tplv-dcdx-default:0:0.png', color: '#2B5D8A', }; @@ -34,4 +34,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/dongchedi/origin.d.ts b/src/hotnow/dongchedi/origin.d.ts new file mode 100644 index 0000000..54cdf81 --- /dev/null +++ b/src/hotnow/dongchedi/origin.d.ts @@ -0,0 +1,9 @@ +export interface OriginData { + gid: string; + title: string; + is_hot: number; + score: number; + description: string; + serial_icon: string; + [key: string]: any; +} diff --git a/src/hotnow/douban-movic/README.md b/src/hotnow/douban-movic/README.md index 95fe137..c32626d 100644 --- a/src/hotnow/douban-movic/README.md +++ b/src/hotnow/douban-movic/README.md @@ -18,4 +18,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/douban-movic/api.ts b/src/hotnow/douban-movic/api.ts index 7914004..5611618 100644 --- a/src/hotnow/douban-movic/api.ts +++ b/src/hotnow/douban-movic/api.ts @@ -47,4 +47,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/douban-movic/origin.d.ts b/src/hotnow/douban-movic/origin.d.ts new file mode 100644 index 0000000..6f410fa --- /dev/null +++ b/src/hotnow/douban-movic/origin.d.ts @@ -0,0 +1 @@ +export type OriginData = string; diff --git a/src/hotnow/douyin/README.md b/src/hotnow/douyin/README.md index 44033d8..e0a8c48 100644 --- a/src/hotnow/douyin/README.md +++ b/src/hotnow/douyin/README.md @@ -18,4 +18,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/douyin/api.ts b/src/hotnow/douyin/api.ts index cf4079e..c88f36e 100644 --- a/src/hotnow/douyin/api.ts +++ b/src/hotnow/douyin/api.ts @@ -15,7 +15,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.status_code === 0) { - const result: HotListItem[] = responseBody.data.word_list.map((v) => { + const result: HotListItem[] = responseBody.data.word_list.map((v: any) => { return { id: v.group_id, title: v.word, @@ -34,4 +34,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/douyin/origin.d.ts b/src/hotnow/douyin/origin.d.ts new file mode 100644 index 0000000..2d766a5 --- /dev/null +++ b/src/hotnow/douyin/origin.d.ts @@ -0,0 +1,26 @@ +export interface OriginData { + group_id: string; + word: string; + word_cover: { + url_list: string[]; + [key: string]: any; + }; + hot_value: string; + sentence_id: string; + label?: number; + position?: number; + word_type?: number; + sentence_tag?: number; + can_extend_detail?: boolean; + discuss_video_count?: number; + article_detail_count?: number; + video_count?: number; + room_count?: number; + drift_info?: Record | null; + event_time?: number; + hotlist_param?: string; + related_words?: Record | null; + word_sub_board?: Record | null; + aweme_infos?: Record | null; + [key: string]: any; +} diff --git a/src/hotnow/github-trending/README.md b/src/hotnow/github-trending/README.md index 130605a..06b53a9 100644 --- a/src/hotnow/github-trending/README.md +++ b/src/hotnow/github-trending/README.md @@ -18,4 +18,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/github-trending/api.ts b/src/hotnow/github-trending/api.ts index 38dc352..0078fff 100644 --- a/src/hotnow/github-trending/api.ts +++ b/src/hotnow/github-trending/api.ts @@ -59,4 +59,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/github-trending/origin.d.ts b/src/hotnow/github-trending/origin.d.ts new file mode 100644 index 0000000..6f410fa --- /dev/null +++ b/src/hotnow/github-trending/origin.d.ts @@ -0,0 +1 @@ +export type OriginData = string; diff --git a/src/hotnow/hello-github/README.md b/src/hotnow/hello-github/README.md index 4a70f48..b3b7ee0 100644 --- a/src/hotnow/hello-github/README.md +++ b/src/hotnow/hello-github/README.md @@ -18,4 +18,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/hello-github/api.ts b/src/hotnow/hello-github/api.ts index cfc7039..cb8e2b2 100644 --- a/src/hotnow/hello-github/api.ts +++ b/src/hotnow/hello-github/api.ts @@ -21,7 +21,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.success) { - const result: HotListItem[] = responseBody.data.map((v) => { + const result: HotListItem[] = responseBody.data.map((v: any) => { return { id: v.item_id, title: `${v.name}-${v.title}`, @@ -40,4 +40,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/hello-github/origin.d.ts b/src/hotnow/hello-github/origin.d.ts new file mode 100644 index 0000000..aa2dc19 --- /dev/null +++ b/src/hotnow/hello-github/origin.d.ts @@ -0,0 +1,9 @@ +export interface OriginData { + item_id: number; + name: string; + title: string; + summary: string; + clicks_total: number; + full_name: string; + [key: string]: any; +} diff --git a/src/hotnow/history-today/README.md b/src/hotnow/history-today/README.md index 389cd25..ffebf8a 100644 --- a/src/hotnow/history-today/README.md +++ b/src/hotnow/history-today/README.md @@ -18,4 +18,8 @@ url: string; // 详情链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/history-today/api.ts b/src/hotnow/history-today/api.ts index 67981da..784af6e 100644 --- a/src/hotnow/history-today/api.ts +++ b/src/hotnow/history-today/api.ts @@ -32,4 +32,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/history-today/origin.d.ts b/src/hotnow/history-today/origin.d.ts new file mode 100644 index 0000000..5d757b1 --- /dev/null +++ b/src/hotnow/history-today/origin.d.ts @@ -0,0 +1,6 @@ +export interface OriginData { + year: string; + title: string; + link: string; + [key: string]: any; +} diff --git a/src/hotnow/hupu/README.md b/src/hotnow/hupu/README.md index 0391d53..370921b 100644 --- a/src/hotnow/hupu/README.md +++ b/src/hotnow/hupu/README.md @@ -19,4 +19,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/hupu/api.ts b/src/hotnow/hupu/api.ts index a64166d..5d829da 100644 --- a/src/hotnow/hupu/api.ts +++ b/src/hotnow/hupu/api.ts @@ -20,7 +20,7 @@ export const main = async function(): Promise { const data = JSON.parse(json.text().split("window.$$data=")[1]) .pageData .threads; - const result: HotListItem[] = data.map((v) => { + const result: HotListItem[] = data.map((v: any) => { return { id: v.tid, title: v.title, @@ -38,4 +38,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/hupu/origin.d.ts b/src/hotnow/hupu/origin.d.ts new file mode 100644 index 0000000..4a96508 --- /dev/null +++ b/src/hotnow/hupu/origin.d.ts @@ -0,0 +1,9 @@ +export interface OriginData { + tid: number; + title: string; + desc: string; + cover: string; + lights: number; + url: string; + [key: string]: any; +} diff --git a/src/hotnow/huxiu/README.md b/src/hotnow/huxiu/README.md index 801cda7..d53c766 100644 --- a/src/hotnow/huxiu/README.md +++ b/src/hotnow/huxiu/README.md @@ -19,4 +19,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/huxiu/api.ts b/src/hotnow/huxiu/api.ts index 49804d4..465cb45 100644 --- a/src/hotnow/huxiu/api.ts +++ b/src/hotnow/huxiu/api.ts @@ -20,7 +20,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.success) { - const result: HotListItem[] = responseBody?.data?.moment_list?.datalist.map((v) => { + const result: HotListItem[] = responseBody?.data?.moment_list?.datalist.map((v: any) => { const content = (v.content || "").replace(//gi, "\n"); const [titleLine, ...rest] = content .split("\n") @@ -47,4 +47,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/huxiu/origin.d.ts b/src/hotnow/huxiu/origin.d.ts new file mode 100644 index 0000000..f55b923 --- /dev/null +++ b/src/hotnow/huxiu/origin.d.ts @@ -0,0 +1,6 @@ +export interface OriginData { + object_id: string; + content: string; + format_time: string; + [key: string]: any; +} diff --git a/src/hotnow/ifanr/README.md b/src/hotnow/ifanr/README.md index c3066b5..084f335 100644 --- a/src/hotnow/ifanr/README.md +++ b/src/hotnow/ifanr/README.md @@ -16,4 +16,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/ifanr/api.ts b/src/hotnow/ifanr/api.ts index 967c435..23deda3 100644 --- a/src/hotnow/ifanr/api.ts +++ b/src/hotnow/ifanr/api.ts @@ -18,7 +18,7 @@ export const main = async function(): Promise { if (!data) { return []; } - const result: HotListItem[] = data.map((v) => { + const result: HotListItem[] = data.map((v: any) => { return { id: v.post_id, title: v.post_title, @@ -33,4 +33,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/ifanr/origin.d.ts b/src/hotnow/ifanr/origin.d.ts new file mode 100644 index 0000000..7280f7b --- /dev/null +++ b/src/hotnow/ifanr/origin.d.ts @@ -0,0 +1,6 @@ +export interface OriginData { + post_id: number; + post_title: string; + buzz_original_url: string; + [key: string]: any; +} diff --git a/src/hotnow/ithome/README.md b/src/hotnow/ithome/README.md index 1c47065..2f25a32 100644 --- a/src/hotnow/ithome/README.md +++ b/src/hotnow/ithome/README.md @@ -18,4 +18,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/ithome/api.ts b/src/hotnow/ithome/api.ts index ef5b4d1..ace87c2 100644 --- a/src/hotnow/ithome/api.ts +++ b/src/hotnow/ithome/api.ts @@ -45,4 +45,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/ithome/origin.d.ts b/src/hotnow/ithome/origin.d.ts new file mode 100644 index 0000000..6f410fa --- /dev/null +++ b/src/hotnow/ithome/origin.d.ts @@ -0,0 +1 @@ +export type OriginData = string; diff --git a/src/hotnow/juejin/README.md b/src/hotnow/juejin/README.md index a2b2f38..0b81204 100644 --- a/src/hotnow/juejin/README.md +++ b/src/hotnow/juejin/README.md @@ -17,4 +17,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/juejin/api.ts b/src/hotnow/juejin/api.ts index c99fb62..cb72f77 100644 --- a/src/hotnow/juejin/api.ts +++ b/src/hotnow/juejin/api.ts @@ -15,7 +15,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.err_msg === 'success') { - const result: HotListItem[] = responseBody.data.map((v) => { + const result: HotListItem[] = responseBody.data.map((v: any) => { return { id: v.content.content_id, title: v.content.title, @@ -33,4 +33,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/juejin/origin.d.ts b/src/hotnow/juejin/origin.d.ts new file mode 100644 index 0000000..180005c --- /dev/null +++ b/src/hotnow/juejin/origin.d.ts @@ -0,0 +1,12 @@ +export interface OriginData { + content: { + content_id: string; + title: string; + [key: string]: any; + }; + content_counter: { + hot_rank: number; + [key: string]: any; + }; + [key: string]: any; +} diff --git a/src/hotnow/kuaishou/README.md b/src/hotnow/kuaishou/README.md index 43ec4d7..b1759fd 100644 --- a/src/hotnow/kuaishou/README.md +++ b/src/hotnow/kuaishou/README.md @@ -17,4 +17,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/kuaishou/api.ts b/src/hotnow/kuaishou/api.ts index b92a095..335cf89 100644 --- a/src/hotnow/kuaishou/api.ts +++ b/src/hotnow/kuaishou/api.ts @@ -39,4 +39,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/kuaishou/origin.d.ts b/src/hotnow/kuaishou/origin.d.ts new file mode 100644 index 0000000..f8ee6d8 --- /dev/null +++ b/src/hotnow/kuaishou/origin.d.ts @@ -0,0 +1,7 @@ +export interface OriginData { + poster: string; + name: string; + hotValue: string; + id: string; + [key: string]: any; +} diff --git a/src/hotnow/lol/README.md b/src/hotnow/lol/README.md index 431e394..1c8f400 100644 --- a/src/hotnow/lol/README.md +++ b/src/hotnow/lol/README.md @@ -19,4 +19,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/lol/api.ts b/src/hotnow/lol/api.ts index 7aa5eb7..868206c 100644 --- a/src/hotnow/lol/api.ts +++ b/src/hotnow/lol/api.ts @@ -15,7 +15,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.status === 1) { - const result: HotListItem[] = responseBody.data.result.map((v) => { + const result: HotListItem[] = responseBody.data.result.map((v: any) => { return { id: v.iDocID, title: v.sTitle, @@ -35,4 +35,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/lol/origin.d.ts b/src/hotnow/lol/origin.d.ts new file mode 100644 index 0000000..25c5cf1 --- /dev/null +++ b/src/hotnow/lol/origin.d.ts @@ -0,0 +1,8 @@ +export interface OriginData { + iDocID: string; + sTitle: string; + sAuthor: string; + sIMG: string; + iTotalPlay: string; + [key: string]: any; +} diff --git a/src/hotnow/netease-music/README.md b/src/hotnow/netease-music/README.md index d6ab734..85bf88f 100644 --- a/src/hotnow/netease-music/README.md +++ b/src/hotnow/netease-music/README.md @@ -19,4 +19,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/netease-music/api.ts b/src/hotnow/netease-music/api.ts index f5a5e0f..bc1b91c 100644 --- a/src/hotnow/netease-music/api.ts +++ b/src/hotnow/netease-music/api.ts @@ -28,7 +28,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.code === 200) { - const result: HotListItem[] = responseBody.result.tracks.map((v) => { + const result: HotListItem[] = responseBody.result.tracks.map((v: any) => { return { id: v.id, title: v.name, @@ -47,4 +47,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/netease-music/origin.d.ts b/src/hotnow/netease-music/origin.d.ts new file mode 100644 index 0000000..1c12297 --- /dev/null +++ b/src/hotnow/netease-music/origin.d.ts @@ -0,0 +1,10 @@ +export interface OriginData { + id: number; + name: string; + duration: number; + album: { + picUrl: string; + [key: string]: any; + }; + [key: string]: any; +} diff --git a/src/hotnow/netease/README.md b/src/hotnow/netease/README.md index 5ca123f..37484ff 100644 --- a/src/hotnow/netease/README.md +++ b/src/hotnow/netease/README.md @@ -18,4 +18,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/netease/api.ts b/src/hotnow/netease/api.ts index 53caf46..6a20a35 100644 --- a/src/hotnow/netease/api.ts +++ b/src/hotnow/netease/api.ts @@ -15,7 +15,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.msg === 'success') { - const result: HotListItem[] = responseBody.data.list.map((v) => { + const result: HotListItem[] = responseBody.data.list.map((v: any) => { return { id: v.skipID, title: v.title, @@ -34,4 +34,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/netease/origin.d.ts b/src/hotnow/netease/origin.d.ts new file mode 100644 index 0000000..9776ac4 --- /dev/null +++ b/src/hotnow/netease/origin.d.ts @@ -0,0 +1,8 @@ +export interface OriginData { + skipID: string; + title: string; + _keyword?: string; + imgsrc: string; + url: string; + [key: string]: any; +} diff --git a/src/hotnow/qq/README.md b/src/hotnow/qq/README.md index 20fa8f7..794f130 100644 --- a/src/hotnow/qq/README.md +++ b/src/hotnow/qq/README.md @@ -19,4 +19,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/qq/api.ts b/src/hotnow/qq/api.ts index a590c38..f97df60 100644 --- a/src/hotnow/qq/api.ts +++ b/src/hotnow/qq/api.ts @@ -15,7 +15,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.ret === 0) { - const result: HotListItem[] = responseBody.idlist[0].newslist.slice(1).map((v) => { + const result: HotListItem[] = responseBody.idlist[0].newslist.slice(1).map((v: any) => { return { id: v.id, title: v.title, @@ -35,4 +35,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/qq/origin.d.ts b/src/hotnow/qq/origin.d.ts new file mode 100644 index 0000000..544bb22 --- /dev/null +++ b/src/hotnow/qq/origin.d.ts @@ -0,0 +1,8 @@ +export interface OriginData { + id: string; + title: string; + abstract: string; + miniProShareImage: string; + readCount: number; + [key: string]: any; +} diff --git a/src/hotnow/quark/README.md b/src/hotnow/quark/README.md index fa4d734..17ab9ff 100644 --- a/src/hotnow/quark/README.md +++ b/src/hotnow/quark/README.md @@ -17,4 +17,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/quark/api.ts b/src/hotnow/quark/api.ts index f007ef7..0d5922d 100644 --- a/src/hotnow/quark/api.ts +++ b/src/hotnow/quark/api.ts @@ -16,7 +16,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.status === 0) { - const result: HotListItem[] = responseBody.data.articles.map((v) => { + const result: HotListItem[] = responseBody.data.articles.map((v: any) => { return { id: v.id, title: v.title, @@ -34,4 +34,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/quark/origin.d.ts b/src/hotnow/quark/origin.d.ts new file mode 100644 index 0000000..ddb1bf0 --- /dev/null +++ b/src/hotnow/quark/origin.d.ts @@ -0,0 +1,6 @@ +export interface OriginData { + id: string; + title: string; + publish_time: string; + [key: string]: any; +} diff --git a/src/hotnow/thepaper/README.md b/src/hotnow/thepaper/README.md index bc63966..195c57b 100644 --- a/src/hotnow/thepaper/README.md +++ b/src/hotnow/thepaper/README.md @@ -18,4 +18,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/thepaper/api.ts b/src/hotnow/thepaper/api.ts index 4752639..8f1d6ef 100644 --- a/src/hotnow/thepaper/api.ts +++ b/src/hotnow/thepaper/api.ts @@ -15,7 +15,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.resultCode === 1) { - const result: HotListItem[] = responseBody.data.hotNews.map((v) => { + const result: HotListItem[] = responseBody.data.hotNews.map((v: any) => { return { id: v.contId, title: v.name, @@ -34,4 +34,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/thepaper/origin.d.ts b/src/hotnow/thepaper/origin.d.ts new file mode 100644 index 0000000..7504cef --- /dev/null +++ b/src/hotnow/thepaper/origin.d.ts @@ -0,0 +1,7 @@ +export interface OriginData { + contId: number; + name: string; + pic: string; + praiseTimes: number; + [key: string]: any; +} diff --git a/src/hotnow/toutiao/README.md b/src/hotnow/toutiao/README.md index 9580ac2..00c334b 100644 --- a/src/hotnow/toutiao/README.md +++ b/src/hotnow/toutiao/README.md @@ -18,4 +18,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/toutiao/api.ts b/src/hotnow/toutiao/api.ts index 0596184..53aee6c 100644 --- a/src/hotnow/toutiao/api.ts +++ b/src/hotnow/toutiao/api.ts @@ -15,7 +15,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.status === 'success') { - const result: HotListItem[] = responseBody.data.map((v) => { + const result: HotListItem[] = responseBody.data.map((v: any) => { return { id: v.ClusterId, title: v.Title, @@ -34,4 +34,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/toutiao/origin.d.ts b/src/hotnow/toutiao/origin.d.ts new file mode 100644 index 0000000..7ec6560 --- /dev/null +++ b/src/hotnow/toutiao/origin.d.ts @@ -0,0 +1,11 @@ +export interface OriginData { + ClusterId: number; + ClusterIdStr?: string; + Title: string; + Image: { + url: string; + [key: string]: any; + }; + HotValue: number; + [key: string]: any; +} diff --git a/src/hotnow/weibo/README.md b/src/hotnow/weibo/README.md index 7e8de69..e0db672 100644 --- a/src/hotnow/weibo/README.md +++ b/src/hotnow/weibo/README.md @@ -22,6 +22,10 @@ } ``` +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) + ## 响应示例 ```json diff --git a/src/hotnow/weibo/api.ts b/src/hotnow/weibo/api.ts index 26957db..e9f1553 100644 --- a/src/hotnow/weibo/api.ts +++ b/src/hotnow/weibo/api.ts @@ -22,7 +22,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.ok === 1) { - const result: HotListItem[] = responseBody.data.realtime.map((v) => { + const result: HotListItem[] = responseBody.data.realtime.map((v: any) => { const key = v.word_scheme ? v.word_scheme : `#${v.word}`; return { id: v.mid, @@ -43,4 +43,6 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); +} diff --git a/src/hotnow/weibo/origin.d.ts b/src/hotnow/weibo/origin.d.ts new file mode 100644 index 0000000..186bda9 --- /dev/null +++ b/src/hotnow/weibo/origin.d.ts @@ -0,0 +1,8 @@ +export interface OriginData { + mid: string; + word: string; + word_scheme: string; + num: number; + label_name: string; + [key: string]: any; +} diff --git a/src/hotnow/weread/README.md b/src/hotnow/weread/README.md index 859a99d..9286c67 100644 --- a/src/hotnow/weread/README.md +++ b/src/hotnow/weread/README.md @@ -18,4 +18,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/weread/api.ts b/src/hotnow/weread/api.ts index b692490..dcb4588 100644 --- a/src/hotnow/weread/api.ts +++ b/src/hotnow/weread/api.ts @@ -58,7 +58,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.books) { - const result: HotListItem[] = responseBody.books.map((v) => { + const result: HotListItem[] = responseBody.books.map((v: any) => { const info = v.bookInfo; return { id: info.bookId, @@ -78,4 +78,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/weread/origin.d.ts b/src/hotnow/weread/origin.d.ts new file mode 100644 index 0000000..1ab214f --- /dev/null +++ b/src/hotnow/weread/origin.d.ts @@ -0,0 +1,10 @@ +export interface OriginData { + bookInfo: { + bookId: string; + title: string; + cover: string; + [key: string]: any; + }; + readingCount: number; + [key: string]: any; +} diff --git a/src/hotnow/woshipm/README.md b/src/hotnow/woshipm/README.md index 8a26194..7dff6aa 100644 --- a/src/hotnow/woshipm/README.md +++ b/src/hotnow/woshipm/README.md @@ -19,4 +19,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/woshipm/api.ts b/src/hotnow/woshipm/api.ts index 9420bb1..1d9eddd 100644 --- a/src/hotnow/woshipm/api.ts +++ b/src/hotnow/woshipm/api.ts @@ -21,7 +21,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.CODE === 200) { - const result: HotListItem[] = responseBody.RESULT.map((v) => { + const result: HotListItem[] = responseBody.RESULT.map((v: any) => { const articleUrl = `https://www.woshipm.com/${v.data.type}/${v.data.id}.html`; return { id: v.data.id, @@ -42,4 +42,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/woshipm/origin.d.ts b/src/hotnow/woshipm/origin.d.ts new file mode 100644 index 0000000..094a7d8 --- /dev/null +++ b/src/hotnow/woshipm/origin.d.ts @@ -0,0 +1,12 @@ +export interface OriginData { + data: { + id: number; + articleTitle: string; + articleSummary: string; + imageUrl: string; + type: string; + [key: string]: any; + }; + scores: number; + [key: string]: any; +} diff --git a/src/hotnow/xiaohongshu/README.md b/src/hotnow/xiaohongshu/README.md index ffdef0e..0528b7f 100644 --- a/src/hotnow/xiaohongshu/README.md +++ b/src/hotnow/xiaohongshu/README.md @@ -21,6 +21,10 @@ } ``` +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) + ## 响应示例 ```json diff --git a/src/hotnow/xiaohongshu/api.ts b/src/hotnow/xiaohongshu/api.ts index 3aea40e..8963aca 100644 --- a/src/hotnow/xiaohongshu/api.ts +++ b/src/hotnow/xiaohongshu/api.ts @@ -1,11 +1,12 @@ import { HotListItem } from "../type"; + export const label = { name: '小红书-实时热榜', icon: 'https://www.xiaohongshu.com/favicon.ico', color: '#FF0000', -} +}; + export const main = async function(): Promise { - // 官方 url const url = 'https://edith.xiaohongshu.com/api/sns/v1/search/hot_list'; const xhsHeaders = { 'User-Agent': @@ -18,19 +19,15 @@ export const main = async function(): Promise { 'platform=iOS&version=8.7&build=8070515&deviceId=C323D3A5-6A27-4CE6-AA0E-51C9D4C26A24&bundle=com.xingin.discover', 'xy-common-params': 'app_id=ECFAAF02&build=8070515&channel=AppStore&deviceId=C323D3A5-6A27-4CE6-AA0E-51C9D4C26A24&device_fingerprint=20230920120211bd7b71a80778509cf4211099ea911000010d2f20f6050264&device_fingerprint1=20230920120211bd7b71a80778509cf4211099ea911000010d2f20f6050264&device_model=phone&fid=1695182528-0-0-63b29d709954a1bb8c8733eb2fb58f29&gid=7dc4f3d168c355f1a886c54a898c6ef21fe7b9a847359afc77fc24ad&identifier_flag=0&lang=zh-Hans&launch_id=716882697&platform=iOS&project_id=ECFAAF&sid=session.1695189743787849952190&t=1695190591&teenager=0&tz=Asia/Shanghai&uis=light&version=8.7', - } + }; try { - // 请求数据 const response = await fetch(url, { headers: xhsHeaders, }); if (!response.ok) { - // 如果请求失败,抛出错误,不进行缓存 throw new Error(`请求错误 ${label.name}`); } - // 得到请求体 const responseBody = await response.json(); - // 处理数据 if (responseBody.success) { const result: HotListItem[] = responseBody.data?.items.map((v: any): HotListItem => { return { @@ -47,9 +44,10 @@ export const main = async function(): Promise { } return []; } catch { - // 请求失败,返回空数据 return []; } -} +}; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); +} \ No newline at end of file diff --git a/src/hotnow/xiaohongshu/origin.d.ts b/src/hotnow/xiaohongshu/origin.d.ts new file mode 100644 index 0000000..197fe1e --- /dev/null +++ b/src/hotnow/xiaohongshu/origin.d.ts @@ -0,0 +1,7 @@ +export interface OriginData { + id: string; + title: string; + score: number; + word_type?: string; + [key: string]: any; +} diff --git a/src/hotnow/zhihu-daily/README.md b/src/hotnow/zhihu-daily/README.md index faa0e14..84a8463 100644 --- a/src/hotnow/zhihu-daily/README.md +++ b/src/hotnow/zhihu-daily/README.md @@ -17,4 +17,8 @@ url: string; // PC 端链接 mobileUrl?: string; // 移动端链接 } -``` \ No newline at end of file +``` + +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) \ No newline at end of file diff --git a/src/hotnow/zhihu-daily/api.ts b/src/hotnow/zhihu-daily/api.ts index c75959b..a10b3f8 100644 --- a/src/hotnow/zhihu-daily/api.ts +++ b/src/hotnow/zhihu-daily/api.ts @@ -25,7 +25,7 @@ export const main = async function(): Promise { if (!data) { return []; } - const result: HotListItem[] = data.map((v) => { + const result: HotListItem[] = data.map((v: any) => { return { id: v.id, title: v.title, @@ -40,4 +40,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/zhihu-daily/origin.d.ts b/src/hotnow/zhihu-daily/origin.d.ts new file mode 100644 index 0000000..c639ea4 --- /dev/null +++ b/src/hotnow/zhihu-daily/origin.d.ts @@ -0,0 +1,6 @@ +export interface OriginData { + id: number; + title: string; + url: string; + [key: string]: any; +} diff --git a/src/hotnow/zhihu/README.md b/src/hotnow/zhihu/README.md index c95827f..e653204 100644 --- a/src/hotnow/zhihu/README.md +++ b/src/hotnow/zhihu/README.md @@ -20,6 +20,10 @@ } ``` +## OriginData 类型参考 + +类型定义文件:[origin.d.ts](./origin.d.ts) + ## 响应示例 ```json diff --git a/src/hotnow/zhihu/api.ts b/src/hotnow/zhihu/api.ts index 4f6c3fa..09c7d5f 100644 --- a/src/hotnow/zhihu/api.ts +++ b/src/hotnow/zhihu/api.ts @@ -15,7 +15,7 @@ export const main = async function(): Promise { } const responseBody = await response.json(); if (responseBody.data) { - const result: HotListItem[] = responseBody.data.map((v) => { + const result: HotListItem[] = responseBody.data.map((v: any) => { return { id: v.id, title: v.target.title, @@ -34,4 +34,7 @@ export const main = async function(): Promise { } }; -main().then(console.log).catch(console.error); \ No newline at end of file +if (import.meta.main) { + main().then(console.log).catch(console.error); + +} diff --git a/src/hotnow/zhihu/origin.d.ts b/src/hotnow/zhihu/origin.d.ts new file mode 100644 index 0000000..c1922fc --- /dev/null +++ b/src/hotnow/zhihu/origin.d.ts @@ -0,0 +1,14 @@ +export interface OriginData { + id: string; + card_id?: string; + target: { + title: string; + [key: string]: any; + }; + children?: { + thumbnail: string; + [key: string]: any; + }[]; + detail_text?: string; + [key: string]: any; +}