mirror of
https://github.com/ourongxing/newsnow.git
synced 2025-01-31 10:58:04 +08:00
pref: remove fallback source
This commit is contained in:
parent
1f08297e19
commit
fcddce3a83
49
server/sources/douyin.ts
Normal file
49
server/sources/douyin.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
interface Res {
|
||||||
|
data?: {
|
||||||
|
word_list?: {
|
||||||
|
sentence_id: string
|
||||||
|
word: string
|
||||||
|
event_time: string
|
||||||
|
hot_value: string
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getDyCookies() {
|
||||||
|
try {
|
||||||
|
const cookisUrl = "https://www.douyin.com/passport/general/login_guiding_strategy/?aid=6383"
|
||||||
|
const data = await $fetch.raw(cookisUrl)
|
||||||
|
const pattern = /passport_csrf_token=(.*); Path/s
|
||||||
|
const matchResult = data.headers.get("set-cookie")?.[0]?.match(pattern)
|
||||||
|
if (matchResult && matchResult.length > 1) {
|
||||||
|
const cookieData = matchResult[1]
|
||||||
|
return cookieData
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`获取抖音 Cookie 出错: ${error}`)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineSource(async () => {
|
||||||
|
const url = "https://www.douyin.com/aweme/v1/web/hot/search/list/?device_platform=webapp&aid=6383&channel=channel_pc_web&detail_list=1"
|
||||||
|
const cookie = await getDyCookies()
|
||||||
|
const res: Res = await $fetch(url, {
|
||||||
|
headers: {
|
||||||
|
Cookie: `passport_csrf_token=${cookie}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if (!res?.data?.word_list || res.data.word_list.length === 0) throw new Error("Cannot fetch data")
|
||||||
|
return res.data.word_list
|
||||||
|
.slice(0, 20)
|
||||||
|
.map((k) => {
|
||||||
|
return {
|
||||||
|
id: k.sentence_id,
|
||||||
|
title: k.word,
|
||||||
|
extra: {
|
||||||
|
info: k.hot_value,
|
||||||
|
},
|
||||||
|
url: `https://www.douyin.com/hot/${k.sentence_id}`,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
@ -9,6 +9,8 @@ import coolapk from "./coolapk"
|
|||||||
import sputniknewscn from "./sputniknewscn"
|
import sputniknewscn from "./sputniknewscn"
|
||||||
import kr from "./36kr"
|
import kr from "./36kr"
|
||||||
import wallstreetcn from "./wallstreetcn"
|
import wallstreetcn from "./wallstreetcn"
|
||||||
|
import douyin from "./douyin"
|
||||||
|
import toutiao from "./toutiao"
|
||||||
|
|
||||||
export const sourcesFn = {
|
export const sourcesFn = {
|
||||||
weibo,
|
weibo,
|
||||||
@ -20,7 +22,7 @@ export const sourcesFn = {
|
|||||||
cankaoxiaoxi,
|
cankaoxiaoxi,
|
||||||
sputniknewscn,
|
sputniknewscn,
|
||||||
wallstreetcn,
|
wallstreetcn,
|
||||||
"douyin": defineFallbackSource("douyin"),
|
douyin,
|
||||||
"toutiao": defineFallbackSource("toutiao"),
|
toutiao,
|
||||||
"36kr-quick": kr,
|
"36kr-quick": kr,
|
||||||
} as Record<SourceID, () => Promise<NewsItem[]>>
|
} as Record<SourceID, () => Promise<NewsItem[]>>
|
||||||
|
28
server/sources/toutiao.ts
Normal file
28
server/sources/toutiao.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
interface Res {
|
||||||
|
data?: {
|
||||||
|
ClusterIdStr: string
|
||||||
|
Title: string
|
||||||
|
HotValue: string
|
||||||
|
Image: {
|
||||||
|
url: string
|
||||||
|
}
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineSource(async () => {
|
||||||
|
const url = "https://www.toutiao.com/hot-event/hot-board/?origin=toutiao_pc"
|
||||||
|
const res: Res = await $fetch(url)
|
||||||
|
if (!res.data || res.data.length === 0) throw new Error("Cannot fetch data")
|
||||||
|
return res.data
|
||||||
|
.slice(0, 20)
|
||||||
|
.map((k) => {
|
||||||
|
return {
|
||||||
|
id: k.ClusterIdStr,
|
||||||
|
title: k.Title,
|
||||||
|
extra: {
|
||||||
|
info: k.HotValue,
|
||||||
|
},
|
||||||
|
url: `https://www.toutiao.com/trending/${k.ClusterIdStr}/`,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user