From 4919f028c884a041da7ff098abb02389b4eac598 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Tue, 18 Apr 2023 03:02:17 +0800 Subject: ✨add envshare docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/api/v1/load.ts | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 pages/api/v1/load.ts (limited to 'pages/api/v1/load.ts') diff --git a/pages/api/v1/load.ts b/pages/api/v1/load.ts deleted file mode 100644 index ddbfac0..0000000 --- a/pages/api/v1/load.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { NextRequest, NextResponse } from "next/server"; -import { Redis } from "@upstash/redis"; - -const redis = Redis.fromEnv(); -export default async function handler(req: NextRequest) { - const url = new URL(req.url); - const id = url.searchParams.get("id"); - if (!id) { - return new NextResponse("id param is missing", { status: 400 }); - } - const key = ["envshare", id].join(":"); - - const [data, _] = await Promise.all([ - await redis.hgetall<{ encrypted: string; remainingReads: number | null; iv: string }>(key), - await redis.incr("envshare:metrics:reads"), - ]); - if (!data) { - return new NextResponse("Not Found", { status: 404 }); - } - if (data.remainingReads !== null && data.remainingReads < 1) { - await redis.del(key); - return new NextResponse("Not Found", { status: 404 }); - } - - let remainingReads: number | null = null; - if (data.remainingReads !== null) { - // Decrement the number of reads and return the remaining reads - remainingReads = await redis.hincrby(key, "remainingReads", -1); - } - - return NextResponse.json({ iv: data.iv, encrypted: data.encrypted, remainingReads }); -} - -export const config = { - runtime: "edge", -}; -- cgit v1.2.3-70-g09d2