From 2e21b0364485ed22983d5ce644483657e6c4b105 Mon Sep 17 00:00:00 2001 From: Jared Schoeny Date: Fri, 19 Jun 2026 23:02:24 -0600 Subject: [PATCH] Keep custom patcher list consistent across archive and new uploads --- src/app/hack/[slug]/actions.ts | 25 +++++++++++++++++++++++++ src/app/submit/actions.ts | 15 +++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/app/hack/[slug]/actions.ts b/src/app/hack/[slug]/actions.ts index 9788109..ba4aaa4 100644 --- a/src/app/hack/[slug]/actions.ts +++ b/src/app/hack/[slug]/actions.ts @@ -582,6 +582,20 @@ export async function archivePatchVersion(slug: string, patchId: number): Promis return { ok: false, error: "Patch not found" }; } + const { data: customRows, error: customErr } = await supabase + .from("hack_patcher_patches") + .select("patch_id") + .eq("hack_slug", slug); + if (customErr) return { ok: false, error: customErr.message }; + + const isInCustomList = (customRows || []).some((row) => row.patch_id === patchId); + if (isInCustomList && (customRows?.length || 0) <= 2) { + return { + ok: false, + error: "This is one of the last 2 versions in the Custom patcher list. Switch to Latest published patch or add another Custom version before archiving it.", + }; + } + // Archive the patch const serviceClient = await createServiceClient(); const { error: updateErr } = await serviceClient @@ -591,6 +605,17 @@ export async function archivePatchVersion(slug: string, patchId: number): Promis if (updateErr) return { ok: false, error: updateErr.message }; + if (isInCustomList) { + const { error: deleteErr } = await serviceClient + .from("hack_patcher_patches") + .delete() + .eq("hack_slug", slug) + .eq("patch_id", patchId); + if (deleteErr) return { ok: false, error: deleteErr.message }; + } + + revalidateTag(`hack:${slug}:metadata`); + revalidatePath(`/hack/${slug}`); revalidatePath(`/hack/${slug}/versions`); return { ok: true }; } diff --git a/src/app/submit/actions.ts b/src/app/submit/actions.ts index 1717776..8c85d82 100644 --- a/src/app/submit/actions.ts +++ b/src/app/submit/actions.ts @@ -251,6 +251,17 @@ export async function confirmPatchUpload(args: { slug: string; objectKey: string if (vErr) return { ok: false, error: vErr.message } as const; if (existing) return { ok: false, error: "That version already exists for this hack." } as const; + let shouldPublishAutomatically = !!args.publishAutomatically; + if (shouldPublishAutomatically) { + const { data: customPatcherRows, error: customPatcherErr } = await supabase + .from("hack_patcher_patches") + .select("patch_id") + .eq("hack_slug", args.slug) + .limit(1); + if (customPatcherErr) return { ok: false, error: customPatcherErr.message } as const; + shouldPublishAutomatically = (customPatcherRows || []).length === 0; + } + // Create patch row const patchInsert: any = { bucket: PATCHES_BUCKET, @@ -260,7 +271,7 @@ export async function confirmPatchUpload(args: { slug: string; objectKey: string }; // Set published status based on publishAutomatically flag - if (args.publishAutomatically) { + if (shouldPublishAutomatically) { patchInsert.published = true; patchInsert.published_at = new Date().toISOString(); } else { @@ -275,7 +286,7 @@ export async function confirmPatchUpload(args: { slug: string; objectKey: string if (pErr) return { ok: false, error: pErr.message } as const; // Only update current_patch if publishAutomatically is true - if (args.publishAutomatically) { + if (shouldPublishAutomatically) { // Check if this patch is newer than current_patch let shouldUpdateCurrentPatch = true; if (hack.current_patch) {