this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

purge leaflet

alice fb0a6699 103d04e9

+53
+22
src/app/leaflet/[rkey]/purge/actions.ts
··· 1 + "use server"; 2 + 3 + import { revalidatePath } from "next/cache"; 4 + import { redirect } from "next/navigation"; 5 + 6 + export async function purgeLeafletCache(formData: FormData) { 7 + const rkey = formData.get("rkey"); 8 + const password = formData.get("password"); 9 + 10 + if (typeof rkey !== "string" || rkey.length === 0) { 11 + throw new Error("Missing rkey"); 12 + } 13 + 14 + if (password === process.env.PURGE_PASSWORD) { 15 + revalidatePath(`/leaflet/${rkey}`, "page"); 16 + revalidatePath("/", "page"); 17 + redirect(`/leaflet/${rkey}`); 18 + } else { 19 + console.error(`Invalid purge password attempt for Leaflet post ${rkey}`); 20 + redirect(`/leaflet/${rkey}/purge?error=yeah`); 21 + } 22 + }
+31
src/app/leaflet/[rkey]/purge/page.tsx
··· 1 + import { purgeLeafletCache } from "./actions"; 2 + 3 + export default async function PurgeLeafletPost({ 4 + params, 5 + searchParams, 6 + }: { 7 + params: Promise<{ rkey: string }>; 8 + searchParams: Promise<{ error?: string }>; 9 + }) { 10 + const { rkey } = await params; 11 + const { error } = await searchParams; 12 + return ( 13 + <form 14 + action={purgeLeafletCache} 15 + method="post" 16 + className="mx-auto mt-24 flex max-w-96 flex-col gap-4 p-2" 17 + > 18 + <input type="hidden" name="rkey" value={rkey} /> 19 + <input 20 + type="password" 21 + name="password" 22 + placeholder="Password" 23 + className="rounded-xs border p-2" 24 + /> 25 + {error && <p className="text-red-500">wrong password mate</p>} 26 + <button type="submit" className="rounded-xs border p-2"> 27 + Purge 28 + </button> 29 + </form> 30 + ); 31 + }