From 85f58ae557be68393c0c24526c7b0b2998dfce34 Mon Sep 17 00:00:00 2001 From: Adrian Altner Date: Wed, 22 Apr 2026 03:00:05 +0200 Subject: [PATCH] Enhance debug output for token retrieval in readTokenFromFile function --- src/components/Webmentions.astro | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/components/Webmentions.astro b/src/components/Webmentions.astro index 41eeedb..4dc0272 100644 --- a/src/components/Webmentions.astro +++ b/src/components/Webmentions.astro @@ -3,16 +3,25 @@ import { readFileSync } from 'node:fs'; import { DEFAULT_LOCALE, type Locale } from '~/consts'; import { getLocaleFromUrl, t } from '~/i18n/ui'; +let fileDebug = ''; function readTokenFromFile(): string | undefined { const paths = ['/app/.webmention-token', '.webmention-token']; + const logs: string[] = []; + logs.push(`cwd=${process.cwd()}`); for (const p of paths) { try { - const raw = readFileSync(p, 'utf-8').trim(); - if (raw) return raw; - } catch { - // file not present, try next + const raw = readFileSync(p, 'utf-8'); + logs.push(`${p}:ok(${raw.length})`); + const t = raw.trim(); + if (t) { + fileDebug = logs.join(';'); + return t; + } + } catch (err) { + logs.push(`${p}:err(${(err as Error).code ?? 'unknown'})`); } } + fileDebug = logs.join(';'); return undefined; } @@ -50,7 +59,7 @@ async function fetchMentions(target: string): Promise { const token = WEBMENTION_TOKEN; const tokenLen = typeof token === 'string' ? token.length : 0; const source = FILE_TOKEN ? 'file' : 'env'; - if (!token) return { mentions: [], debug: `no-token(src=${source},len=${tokenLen})` }; + if (!token) return { mentions: [], debug: `no-token(src=${source},len=${tokenLen},probe=${fileDebug})` }; const withSlash = target.endsWith('/') ? target : `${target}/`; const withoutSlash = target.replace(/\/+$/, ''); const fetchOne = async (t: string) => { @@ -74,7 +83,7 @@ async function fetchMentions(target: string): Promise { } return { mentions: merged, - debug: `ok(src=${source},len=${tokenLen}) slash=${a.status}:${a.entries.length} noslash=${b.status}:${b.entries.length}`, + debug: `ok(src=${source},len=${tokenLen},probe=${fileDebug}) slash=${a.status}:${a.entries.length} noslash=${b.status}:${b.entries.length}`, }; }