diff --git a/README.md b/README.md index 272e11f..8563b18 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # NewsNow -English | [简体中文](README.zh-CN.md) - ![](screenshots/preview.light.png#gh-light-mode-only) ![](screenshots/preview.dark.png#gh-dark-mode-only) +English | [简体中文](README.zh-CN.md) + ## Deployment If login and caching are not required, you can directly deploy to platforms like Cloudflare Pages or Vercel. Just fork the repository and import it into the respective platform. diff --git a/README.zh-CN.md b/README.zh-CN.md index 4ecda33..d4930ee 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -1,9 +1,10 @@ # NewsNow -[English](./README.md) | 简体中文 ![](screenshots/preview.light.png#gh-light-mode-only) ![](screenshots/preview.dark.png#gh-dark-mode-only) +[English](./README.md) | 简体中文 + ## 部署 如果不需要登录,缓存,可以直接部署到 Cloudflare Pages,Vercel 等。Fork 之后在对应平台上导入即可。 diff --git a/server/middleware/auth.ts b/server/middleware/auth.ts index 3f1b12b..76e1987 100644 --- a/server/middleware/auth.ts +++ b/server/middleware/auth.ts @@ -9,7 +9,7 @@ export default defineEventHandler(async (event) => { throw createError({ statusCode: 506, message: "Server not configured, disable login" }) } else { if (["/api/s", "/api/me"].find(p => url.pathname.startsWith(p))) { - const token = getHeader(event, "Authorization")?.replace("Bearer ", "")?.trim() + const token = getHeader(event, "Authorization")?.replace(/Bearer\s*/, "")?.trim() if (token) { try { const { payload } = await jwtVerify(token, new TextEncoder().encode(process.env.JWT_SECRET)) as { payload?: { id: string, type: string } } diff --git a/shared/sources.ts b/shared/sources.ts index 51f9658..b18f0e1 100644 --- a/shared/sources.ts +++ b/shared/sources.ts @@ -196,7 +196,7 @@ function genSources() { name: source.name, type: source.type, disable: source.disable, - color: source.color ?? "red", + color: source.color ?? "primary", interval: source.interval ?? Time.Default, } if (source.sub && Object.keys(source.sub).length) { diff --git a/shared/types.ts b/shared/types.ts index ce86227..55e0aa6 100644 --- a/shared/types.ts +++ b/shared/types.ts @@ -2,7 +2,7 @@ import type { colors } from "unocss/preset-mini" import type { columnIds } from "./metadata" import type { originSources } from "./sources" -export type Color = Exclude +export type Color = "primary" | Exclude type ConstSources = typeof originSources type MainSourceID = keyof(ConstSources) @@ -15,14 +15,14 @@ export type SourceID = { }[keyof SubSource] | Key : Key; }[MainSourceID] -export type AllSourceID = { - [Key in MainSourceID]: ConstSources[Key] extends { sub?: infer SubSource } ? keyof { - // @ts-expect-error >_< - [SubKey in keyof SubSource as `${Key}-${SubKey}`]: never - } | Key : Key -}[MainSourceID] +// export type AllSourceID = { +// [Key in MainSourceID]: ConstSources[Key] extends { sub?: infer SubSource } ? keyof { +// // @ts-expect-error >_< +// [SubKey in keyof SubSource as `${Key}-${SubKey}`]: never +// } | Key : Key +// }[MainSourceID] -export type DisabledSourceID = Exclude +// export type DisabledSourceID = Exclude export type ColumnID = (typeof columnIds)[number] export type Metadata = Record diff --git a/src/components/column/card.tsx b/src/components/column/card.tsx index 5542d57..caebcc9 100644 --- a/src/components/column/card.tsx +++ b/src/components/column/card.tsx @@ -67,14 +67,15 @@ function NewsCard({ id, inView, handleListeners }: NewsCardProps) { queryFn: async ({ queryKey }) => { const [_id, _refetchTime] = queryKey as [SourceID, number] let url = `/api/s/${_id}` + const headers: Record = {} if (Date.now() - _refetchTime < 1000) { url = `/api/s/${_id}?latest` + const jwt = safeParseString(localStorage.getItem("jwt")) + if (jwt) headers.Authorization = `Bearer ${jwt}` } const response: SourceResponse = await ofetch(url, { timeout: 10000, - headers: { - Authorization: `Bearer ${safeParseString(localStorage.getItem("jwt"))}`, - }, + headers, }) return response },