newsnow/server/sources/fallback.ts

37 lines
761 B
TypeScript
Raw Normal View History

2024-10-03 17:24:29 +08:00
import type { SourceInfo } 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-03 17:24:29 +08:00
export async function fallback(id: string): Promise<SourceInfo> {
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)
return {
2024-10-04 15:36:03 +08:00
updatedTime: res.updateTime,
2024-10-03 17:24:29 +08:00
items: 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
}
}