From 896c1177bb43f7c72667682118caf8c10df0d7ee Mon Sep 17 00:00:00 2001 From: Jared Schoeny Date: Fri, 1 May 2026 23:12:44 -0600 Subject: [PATCH] Fix direct patch downloads not logged for counter --- src/components/Hack/VersionList.tsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/components/Hack/VersionList.tsx b/src/components/Hack/VersionList.tsx index dc0a435..fd07ddf 100644 --- a/src/components/Hack/VersionList.tsx +++ b/src/components/Hack/VersionList.tsx @@ -6,7 +6,7 @@ import { FaChevronDown, FaChevronUp, FaStar, FaDownload, FaTrash, FaRotateLeft, import { FiEdit2, FiEdit, FiX } from "react-icons/fi"; import VersionActions from "@/components/Hack/VersionActions"; import type { PatchesDownloadPermission } from "@/components/Hack/DownloadPermissionSettings"; -import { updatePatchChangelog, updatePatchVersion, getPatchDownloadUrl } from "@/app/hack/[slug]/actions"; +import { updatePatchChangelog, updatePatchVersion, getPatchDownloadUrl, updatePatchDownloadCount } from "@/app/hack/[slug]/actions"; import { useRouter } from "next/navigation"; import { createClient } from "@/utils/supabase/client"; @@ -41,6 +41,24 @@ function PublicPatchDownloadButton({ patchId }: { patchId: number }) { const result = await getPatchDownloadUrl(patchId); if (result.ok) { window.open(result.url, "_blank"); + // Best-effort log download for counting + try { + const key = "deviceId"; + let deviceId = localStorage.getItem(key); + if (!deviceId) { + deviceId = crypto.randomUUID(); + localStorage.setItem(key, deviceId); + } + setTimeout(async () => { + const deviceIdObscured = deviceId.split("-"); + const countResult = await updatePatchDownloadCount(patchId, deviceIdObscured); + if (!countResult.ok) { + console.error(countResult.error); + } + }, 50); + } catch (e) { + console.error(e); + } } else { alert(result.error || "Failed to generate download URL"); }