aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/envshare/pages/api/v1/load.ts
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-19 17:30:39 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-19 17:30:39 +0800
commit3adc965dd09490b7efa1cce9f09b0a3b30970277 (patch)
treef813abb07d7b003984aa74e3154752b6ffc3ccd5 /envshare/pages/api/v1/load.ts
parentc7c9ca6f0c8eddf6d34cd40779f3b2d9463f3a46 (diff)
downloadHydroRoll-3adc965dd09490b7efa1cce9f09b0a3b30970277.tar.gz
HydroRoll-3adc965dd09490b7efa1cce9f09b0a3b30970277.zip
✨优化文档
Diffstat (limited to 'envshare/pages/api/v1/load.ts')
-rw-r--r--envshare/pages/api/v1/load.ts36
1 files changed, 0 insertions, 36 deletions
diff --git a/envshare/pages/api/v1/load.ts b/envshare/pages/api/v1/load.ts
deleted file mode 100644
index ddbfac0..0000000
--- a/envshare/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",
-};