aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/envshare/pages/api/v1/store.ts
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-18 03:02:17 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-18 03:02:17 +0800
commit4919f028c884a041da7ff098abb02389b4eac598 (patch)
treeb0f482568c4b8c8a680ce6e2e70a7b7ca87dc190 /envshare/pages/api/v1/store.ts
parentb135aac8531c1e1488147ad8c6f98eddbdbe0c99 (diff)
downloadHydroRoll-4919f028c884a041da7ff098abb02389b4eac598.tar.gz
HydroRoll-4919f028c884a041da7ff098abb02389b4eac598.zip
✨add envshare docs
Diffstat (limited to 'envshare/pages/api/v1/store.ts')
-rw-r--r--envshare/pages/api/v1/store.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/envshare/pages/api/v1/store.ts b/envshare/pages/api/v1/store.ts
new file mode 100644
index 0000000..c35e9b4
--- /dev/null
+++ b/envshare/pages/api/v1/store.ts
@@ -0,0 +1,38 @@
+import { NextRequest, NextResponse } from "next/server";
+import { Redis } from "@upstash/redis";
+import { generateId } from "pkg/id";
+
+type Request = {
+ encrypted: string;
+ ttl?: number;
+ reads: number;
+ iv: string;
+};
+
+const redis = Redis.fromEnv();
+export default async function handler(req: NextRequest) {
+ const { encrypted, ttl, reads, iv } = (await req.json()) as Request;
+
+ const id = generateId();
+ const key = ["envshare", id].join(":");
+
+ const tx = redis.multi();
+
+ tx.hset(key, {
+ remainingReads: reads > 0 ? reads : null,
+ encrypted,
+ iv,
+ });
+ if (ttl) {
+ tx.expire(key, ttl);
+ }
+ tx.incr("envshare:metrics:writes");
+
+ await tx.exec();
+
+ return NextResponse.json({ id });
+}
+
+export const config = {
+ runtime: "edge",
+};