Refactor fetchMentions function to enhance token handling and debug information
All checks were successful
Deploy / deploy (push) Successful in 1m21s
All checks were successful
Deploy / deploy (push) Successful in 1m21s
This commit is contained in:
parent
4f67fb99d4
commit
d6a073d234
1 changed files with 7 additions and 4 deletions
|
|
@ -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}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue