Move all code to old/ to prepare for Nuxt rewrite
This commit is contained in:
parent
6007f4caeb
commit
51ff27c569
33 changed files with 0 additions and 1 deletions
26
old/app/api/unsubscribe/route.ts
Normal file
26
old/app/api/unsubscribe/route.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { readFile, writeFile } from "fs/promises";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body: { subscription: PushSubscriptionJSON } = await request.json();
|
||||
let subscriptions: PushSubscriptionJSON[];
|
||||
try {
|
||||
subscriptions = JSON.parse(await readFile("push-subscriptions.json", "utf-8"));
|
||||
} catch (err: any) {
|
||||
if (err.code !== "ENOENT") {
|
||||
throw err;
|
||||
}
|
||||
subscriptions = [];
|
||||
}
|
||||
const existingIndex = subscriptions.findIndex(sub => sub.endpoint === body.subscription.endpoint);
|
||||
if (existingIndex !== -1) {
|
||||
subscriptions.splice(existingIndex, 1);
|
||||
} else {
|
||||
return new Response(JSON.stringify({ message: "No subscription registered."}));
|
||||
}
|
||||
await writeFile(
|
||||
"push-subscriptions.json",
|
||||
JSON.stringify(subscriptions, undefined, "\t"),
|
||||
"utf-8"
|
||||
);
|
||||
return new Response(JSON.stringify({ message: "Existing subscription removed."}));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue