newsnow/server/sources/fallback.ts

34 lines
692 B
TypeScript
Raw Normal View History

2024-10-05 17:20:49 +08:00
import type { NewsItem } from "@shared/types"
2024-10-03 13:16:14 +08:00
export interface Res {
code: number
message: string
name: string
title: string
subtitle: string
total: number
updateTime: string
data: {
title: string
desc: string
time?: string
url: string
mobileUrl: string
}[]
}
2024-10-05 17:20:49 +08:00
export async function fallback(id: string): Promise<NewsItem[]> {
2024-10-03 17:24:29 +08:00
const url = `https://smzdk.top/api/${id}/new`
const res: Res = await $fetch(url)
2024-10-03 13:16:14 +08:00
if (res.code !== 200 || !res.data) throw new Error(res.message)
2024-10-05 17:20:49 +08:00
return res.data.map(item => ({
extra: {
date: item.time,
},
id: item.url,
title: item.title,
url: item.url,
mobileUrl: item.mobileUrl,
}))
2024-10-03 13:16:14 +08:00
}