chore: minor changes
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
# NewsNow
|
||||
English | [简体中文](README.zh-CN.md)
|
||||
|
||||

|
||||

|
||||
|
||||
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.
|
||||
|
||||
+2
-1
@@ -1,9 +1,10 @@
|
||||
# NewsNow
|
||||
[English](./README.md) | 简体中文
|
||||
|
||||

|
||||

|
||||
|
||||
[English](./README.md) | 简体中文
|
||||
|
||||
## 部署
|
||||
|
||||
如果不需要登录,缓存,可以直接部署到 Cloudflare Pages,Vercel 等。Fork 之后在对应平台上导入即可。
|
||||
|
||||
@@ -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 } }
|
||||
|
||||
+1
-1
@@ -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) {
|
||||
|
||||
+8
-8
@@ -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<keyof typeof colors, "current" | "inherit" | "transparent" | "black" | "white">
|
||||
export type Color = "primary" | Exclude<keyof typeof colors, "current" | "inherit" | "transparent" | "black" | "white">
|
||||
|
||||
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<SourceID, MainSourceID>
|
||||
// export type DisabledSourceID = Exclude<SourceID, MainSourceID>
|
||||
|
||||
export type ColumnID = (typeof columnIds)[number]
|
||||
export type Metadata = Record<ColumnID, Column>
|
||||
|
||||
@@ -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<string, any> = {}
|
||||
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
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user