blob: 203470e0421ee401787e0abd4e9b7cd813e38b36 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import { safeUserIdentity } from "$lib/Data/AniList/identity";
import { setUserSubscription } from "$lib/Database/SB/User/notifications";
import { decodeAuthCookieOrNull } from "$lib/Effect/authCookie";
import { decodeRequestJsonOrThrow } from "$lib/Effect/requestBody";
import { Schema } from "effect";
const unauthorised = new Response("Unauthorised", { status: 401 });
export const POST = async ({ cookies, request, url }) => {
const userCookie = cookies.get("user");
const fingerprint = url.searchParams.get("p");
if (!userCookie || !fingerprint) return unauthorised;
const user = decodeAuthCookieOrNull(userCookie);
if (!user) return unauthorised;
const userId = (await safeUserIdentity(user))?.id;
if (!userId) return unauthorised;
await setUserSubscription(
userId,
(await decodeRequestJsonOrThrow(
request,
Schema.Record(Schema.String, Schema.Unknown),
)) as unknown as JSON,
fingerprint,
);
return new Response(null, { status: 200 });
};
|