Initial commit

This commit is contained in:
2026-07-28 08:58:44 +02:00
commit c3c1f5e216
46 changed files with 10231 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
import type { APIRoute } from "astro";
export const POST: APIRoute = async ({ request, locals }) => {
if (!locals.pb.authStore.isValid) {
return new Response(JSON.stringify({ error: "Unauthorized" }), {
status: 401,
headers: { "Content-Type": "application/json" },
});
}
try {
const { friendshipId } = await request.json();
if (!friendshipId) {
return new Response(JSON.stringify({ error: "Missing friendship id" }), {
status: 400,
headers: { "Content-Type": "application/json" },
});
}
const friendship = await locals.pb.collection("friendships").getOne(friendshipId);
// Only the addressee can accept
if (friendship.addressee !== locals.pb.authStore.record!.id) {
return new Response(JSON.stringify({ error: "Forbidden" }), {
status: 403,
headers: { "Content-Type": "application/json" },
});
}
await locals.pb.collection("friendships").update(friendshipId, {
status: "accepted",
});
return new Response(JSON.stringify({ success: true }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
} catch (err) {
console.error("Accept friend failed:", err);
return new Response(JSON.stringify({ error: "Failed to accept" }), {
status: 500,
headers: { "Content-Type": "application/json" },
});
}
};