Refactor fetchMentions function to simplify token retrieval and enhance debug output
All checks were successful
Deploy / deploy (push) Successful in 1m19s
All checks were successful
Deploy / deploy (push) Successful in 1m19s
This commit is contained in:
parent
553cc63023
commit
868d34c1a1
1 changed files with 4 additions and 13 deletions
|
|
@ -47,19 +47,10 @@ interface FetchResult {
|
|||
}
|
||||
|
||||
async function fetchMentions(target: string): Promise<FetchResult> {
|
||||
// Probe multiple env sources to see which one has the token at build time.
|
||||
const fromAstroEnv = WEBMENTION_TOKEN;
|
||||
const procEnv = typeof process !== 'undefined' ? process.env : {};
|
||||
const procKeyCount = Object.keys(procEnv).length;
|
||||
const hasWebmentionKey = 'WEBMENTION_TOKEN' in procEnv;
|
||||
const procValLen =
|
||||
hasWebmentionKey && typeof procEnv['WEBMENTION_TOKEN'] === 'string'
|
||||
? (procEnv['WEBMENTION_TOKEN'] as string).length
|
||||
: 0;
|
||||
const token = fromAstroEnv || (hasWebmentionKey ? (procEnv['WEBMENTION_TOKEN'] as string) : undefined);
|
||||
const token = WEBMENTION_TOKEN;
|
||||
const tokenLen = typeof token === 'string' ? token.length : 0;
|
||||
const probe = `ae=${fromAstroEnv ? (fromAstroEnv as string).length : 0},pk=${procKeyCount},phas=${hasWebmentionKey},pv=${procValLen}`;
|
||||
if (!token) return { mentions: [], debug: `no-token(${probe})` };
|
||||
const source = FILE_TOKEN ? 'file' : 'env';
|
||||
if (!token) return { mentions: [], debug: `no-token(src=${source},len=${tokenLen})` };
|
||||
const withSlash = target.endsWith('/') ? target : `${target}/`;
|
||||
const withoutSlash = target.replace(/\/+$/, '');
|
||||
const fetchOne = async (t: string) => {
|
||||
|
|
@ -83,7 +74,7 @@ async function fetchMentions(target: string): Promise<FetchResult> {
|
|||
}
|
||||
return {
|
||||
mentions: merged,
|
||||
debug: `ok(${probe}) slash=${a.status}:${a.entries.length} noslash=${b.status}:${b.entries.length}`,
|
||||
debug: `ok(src=${source},len=${tokenLen}) slash=${a.status}:${a.entries.length} noslash=${b.status}:${b.entries.length}`,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue