feat(profile): add privacy controls and progressive photo gallery
This commit is contained in:
1 parent
ba9c61d808
commit
74223984dc
13 files changed
+764
-167
No files matched your search
@@ -0,0 +1,34 @@
|
||||
"use server";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
import { WebsiteProfilePrivacy } from "@/db/profile-privacy";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { db } from "@/lib/db";
|
||||
import { rateLimit } from "@/lib/rate-limit";
|
||||
export async function saveProfilePrivacy(formData: FormData): Promise<void> {
|
||||
const session = await auth();
|
||||
const userId = Number(session?.user?.id);
|
||||
if (!Number.isSafeInteger(userId) || userId <= 0) redirect("/login");
|
||||
let outcome = "error";
|
||||
try {
|
||||
if ((await rateLimit(`profile-privacy:${userId}`, 10, 60_000)).ok) {
|
||||
const values = {
|
||||
wallet: formData.get("wallet") === "on",
|
||||
online: formData.get("online") === "on",
|
||||
friends: formData.get("friends") === "on",
|
||||
photos: formData.get("photos") === "on",
|
||||
registered: formData.get("registered") === "on",
|
||||
};
|
||||
await db
|
||||
.insert(WebsiteProfilePrivacy)
|
||||
.values({ userId, ...values })
|
||||
.onDuplicateKeyUpdate({ set: values });
|
||||
revalidatePath("/u/[username]", "page");
|
||||
revalidatePath("/settings");
|
||||
outcome = "saved";
|
||||
}
|
||||
} catch {
|
||||
outcome = "error";
|
||||
}
|
||||
redirect(`/settings?privacy=${outcome}#profile-privacy`);
|
||||
}
|
||||
Reference in new issue
Block a user