chore!: bump up vite-plugin-with-nitro

This commit is contained in:
Ou 2024-10-17 04:33:52 +08:00
parent 9aed36201a
commit ff79054692
9 changed files with 986 additions and 680 deletions

View File

@ -32,12 +32,13 @@
"@tanstack/react-router": "^1.64.0",
"@tsndr/cloudflare-worker-jwt": "^3.1.2",
"@unocss/reset": "^0.63.4",
"better-sqlite3": "^11.3.0",
"cheerio": "^1.0.0",
"clsx": "^2.1.1",
"consola": "^3.2.3",
"cookie-es": "^1.2.2",
"dayjs": "1.11.13",
"db0": "npm:@ourongxing/db0@0.1.6",
"db0": "^0.2.1",
"defu": "^6.1.4",
"fast-xml-parser": "^4.5.0",
"framer-motion": "^11.11.8",
@ -46,7 +47,6 @@
"jose": "^5.9.4",
"jotai": "^2.10.0",
"jsonwebtoken": "^9.0.2",
"libsql": "^0.4.6",
"md5": "^2.3.0",
"ofetch": "^1.4.1",
"overlayscrollbars": "^2.10.0",
@ -79,7 +79,6 @@
"lint-staged": "^15.2.10",
"mlly": "^1.7.2",
"mockdate": "^3.0.5",
"nitropack": "^2.9.7",
"simple-git-hooks": "^2.11.1",
"tsx": "^4.19.1",
"typescript": "^5.6.3",
@ -87,7 +86,7 @@
"unocss": "^0.63.4",
"unplugin-auto-import": "^0.18.3",
"vite": "^5.4.8",
"vite-plugin-with-nitro": "0.0.0-beta.7",
"vite-plugin-with-nitro": "0.0.2",
"vite-tsconfig-paths": "^5.0.1",
"vitest": "^2.1.2",
"wrangler": "^3.80.3"
@ -99,8 +98,7 @@
},
"resolutions": {
"dayjs": "1.11.13",
"db0": "npm:@ourongxing/db0@0.1.6",
"nitropack": "^2.9.7"
"picomatch": "^4.0.0"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"

1622
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@ import { TTL } from "@shared/consts"
import type { SourceID, SourceResponse } from "@shared/types"
import { sources } from "@shared/sources"
import { sourcesFn } from "#/sources"
import { Cache } from "#/database/cache"
import { useCache } from "#/hooks/useCache"
export default defineEventHandler(async (event): Promise<SourceResponse> => {
try {
@ -18,8 +18,7 @@ export default defineEventHandler(async (event): Promise<SourceResponse> => {
if (isValid(id)) throw new Error("Invalid source id")
}
const db = useDatabase()
const cacheTable = db ? new Cache(db) : undefined
const cacheTable = useCache()
const now = Date.now()
if (cacheTable) {
if (process.env.INIT_TABLE !== "false") await cacheTable.init()
@ -59,7 +58,10 @@ export default defineEventHandler(async (event): Promise<SourceResponse> => {
const data = await sourcesFn[id]()
logger.success(`fetch ${id} latest`)
if (cacheTable) event.waitUntil(cacheTable.set(id, data))
if (cacheTable) {
if (event.context.waitUntil) event.context.waitUntil(cacheTable.set(id, data))
else await cacheTable.set(id, data)
}
return {
status: "success",
updatedTime: now,

10
server/hooks/useCache.ts Normal file
View File

@ -0,0 +1,10 @@
import { Cache } from "#/database/cache"
export function useCache() {
try {
const db = useDatabase()
if (db) return new Cache(db)
} catch (e) {
logger.error("failed to init database ", e)
}
}

View File

@ -3,11 +3,12 @@ import { jwtVerify } from "jose"
export default defineEventHandler(async (event) => {
const url = getRequestURL(event)
console.log(url.pathname)
if (["JWT_SECRET", "G_CLIENT_ID", "G_CLIENT_SECRET"].find(k => !process.env[k])) {
event.context.disabledLogin = true
if (url.pathname.startsWith("/me")) throw createError({ statusCode: 506, message: "Server not configured" })
} else {
if (/^\/(?:me|s)\//.test(url.pathname)) {
if (/^\/api\/(?:me|s)\//.test(url.pathname)) {
const token = getHeader(event, "Authorization")
if (token && process.env.JWT_SECRET) {
try {

View File

@ -1,11 +0,0 @@
{
"rewrites": [
{
"source": "/:path((?!api).*)",
"destination": "/"
}
],
"github": {
"silent": true
}
}