mirror of
https://github.com/Hackdex-App/hackdex-website.git
synced 2026-08-26 18:44:32 -05:00
Keep custom patcher list consistent across archive and new uploads
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user