From 9f5fbd99aa232712bbe5e40013b5ca3a4ce338b0 Mon Sep 17 00:00:00 2001 From: Neeldhara Misra Date: Fri, 17 Apr 2026 03:57:35 +0530 Subject: [PATCH] Add debug logging to admin function --- netlify/functions/admin.mts | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/netlify/functions/admin.mts b/netlify/functions/admin.mts index cc2312c..e52eab9 100644 --- a/netlify/functions/admin.mts +++ b/netlify/functions/admin.mts @@ -10,17 +10,28 @@ const DEFAULT_DATA = { statusOverrides: {}, notes: {}, ideas: [], todos: {} }; // --- GitHub API helpers --- async function githubGetFile(path: string): Promise<{ content: string; sha: string } | null> { - if (!GITHUB_TOKEN) return null; + if (!GITHUB_TOKEN) { + console.log("[admin] No GITHUB_TOKEN set"); + return null; + } try { - const res = await fetch( - `https://api.github.com/repos/${GITHUB_REPO}/contents/${path}?ref=${GITHUB_BRANCH}`, - { headers: { Authorization: `Bearer ${GITHUB_TOKEN}`, Accept: "application/vnd.github.v3+json" } } - ); - if (!res.ok) return null; + const url = `https://api.github.com/repos/${GITHUB_REPO}/contents/${path}?ref=${GITHUB_BRANCH}`; + console.log("[admin] Fetching:", url); + const res = await fetch(url, { + headers: { Authorization: `Bearer ${GITHUB_TOKEN}`, Accept: "application/vnd.github.v3+json" }, + }); + if (!res.ok) { + console.log("[admin] GitHub API error:", res.status, await res.text().catch(() => "")); + return null; + } const data = await res.json(); const content = Buffer.from(data.content, "base64").toString("utf-8"); + console.log("[admin] Read file OK, length:", content.length); return { content, sha: data.sha }; - } catch { return null; } + } catch (e) { + console.log("[admin] githubGetFile error:", e); + return null; + } } async function githubPutFile(path: string, content: string, message: string, sha?: string): Promise {