diff --git a/main.ts b/main.ts index 9fa664c..73213e3 100644 --- a/main.ts +++ b/main.ts @@ -1,4 +1,4 @@ -import { serve } from "https://deno.land/std/http/server.ts"; +import { serve } from "https://deno.land/std@0.220.1/http/server.ts"; // HTML 页面 const html = ` @@ -80,21 +80,18 @@ const html = ` `; -// 读取prices.json文件 +// 使用 Deno KV 存储数据 +const kv = await Deno.openKv(); + +// 读取价格数据 async function readPrices(): Promise { - try { - const decoder = new TextDecoder("utf-8"); - const data = await Deno.readFile("prices.json"); - return JSON.parse(decoder.decode(data)); - } catch { - return []; - } + const prices = await kv.get(["prices"]); + return prices.value || []; } -// 写入prices.json文件 +// 写入价格数据 async function writePrices(prices: any[]): Promise { - const encoder = new TextEncoder(); - await Deno.writeFile("prices.json", encoder.encode(JSON.stringify(prices, null, 2))); + await kv.set(["prices"], prices); } // 验证请求数据