mirror of
https://github.com/ourongxing/newsnow.git
synced 2025-02-07 22:10:03 +08:00
23 lines
720 B
TypeScript
23 lines
720 B
TypeScript
|
import type { SourceID, SourceResponse } from "@shared/types"
|
||
|
import { getCacheTable } from "#/database/cache"
|
||
|
|
||
|
export default defineEventHandler(async (event) => {
|
||
|
try {
|
||
|
const { sources: _ }: { sources: SourceID[] } = await readBody(event)
|
||
|
const cacheTable = await getCacheTable()
|
||
|
const ids = _?.filter(k => sources[k])
|
||
|
if (ids?.length && cacheTable) {
|
||
|
const caches = await cacheTable.getEntire(ids)
|
||
|
const now = Date.now()
|
||
|
return caches.map(cache => ({
|
||
|
status: "cache",
|
||
|
id: cache.id,
|
||
|
items: cache.items,
|
||
|
updatedTime: now - cache.updated < sources[cache.id].interval ? now : cache.updated,
|
||
|
})) as SourceResponse[]
|
||
|
}
|
||
|
} catch {
|
||
|
//
|
||
|
}
|
||
|
})
|