Refactor fetchMentions function to enhance token handling and debug information
All checks were successful
Deploy / deploy (push) Successful in 1m21s

This commit is contained in:
Adrian Altner 2026-04-22 02:31:35 +02:00
parent 4f67fb99d4
commit d6a073d234

View file

@ -30,9 +30,12 @@ interface FetchResult {
} }
async function fetchMentions(target: string): Promise<FetchResult> { async function fetchMentions(target: string): Promise<FetchResult> {
const token = import.meta.env.WEBMENTION_TOKEN; const importMetaToken = import.meta.env.WEBMENTION_TOKEN;
const tokenLen = typeof token === 'string' ? token.length : 0; const processToken = typeof process !== 'undefined' ? process.env.WEBMENTION_TOKEN : undefined;
if (!token) return { mentions: [], debug: `no-token(len=${tokenLen})` }; const token = importMetaToken || processToken;
const iLen = typeof importMetaToken === 'string' ? importMetaToken.length : 0;
const pLen = typeof processToken === 'string' ? processToken.length : 0;
if (!token) return { mentions: [], debug: `no-token(iml=${iLen},pe=${pLen})` };
const withSlash = target.endsWith('/') ? target : `${target}/`; const withSlash = target.endsWith('/') ? target : `${target}/`;
const withoutSlash = target.replace(/\/+$/, ''); const withoutSlash = target.replace(/\/+$/, '');
const fetchOne = async (t: string) => { const fetchOne = async (t: string) => {
@ -56,7 +59,7 @@ async function fetchMentions(target: string): Promise<FetchResult> {
} }
return { return {
mentions: merged, mentions: merged,
debug: `len=${tokenLen} slash=${a.status}:${a.entries.length} noslash=${b.status}:${b.entries.length}`, debug: `iml=${iLen} pe=${pLen} slash=${a.status}:${a.entries.length} noslash=${b.status}:${b.entries.length}`,
}; };
} }