Refactor fetchMentions function to improve token handling and 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
f436df55b0
commit
1a3e4bf64a
1 changed files with 8 additions and 5 deletions
|
|
@ -30,12 +30,15 @@ interface FetchResult {
|
|||
}
|
||||
|
||||
async function fetchMentions(target: string): Promise<FetchResult> {
|
||||
const importMetaToken = import.meta.env.WEBMENTION_TOKEN;
|
||||
const processToken = typeof process !== 'undefined' ? process.env.WEBMENTION_TOKEN : undefined;
|
||||
const token = importMetaToken || processToken;
|
||||
const iLen = typeof importMetaToken === 'string' ? importMetaToken.length : 0;
|
||||
// Bracket notation prevents Vite from statically replacing at build time.
|
||||
const envKey = 'WEBMENTION_TOKEN';
|
||||
const processToken =
|
||||
typeof process !== 'undefined' ? (process.env as Record<string, string | undefined>)[envKey] : undefined;
|
||||
const importMetaToken = (import.meta.env as Record<string, string | undefined>)[envKey];
|
||||
const token = processToken || importMetaToken;
|
||||
const pLen = typeof processToken === 'string' ? processToken.length : 0;
|
||||
if (!token) return { mentions: [], debug: `no-token(iml=${iLen},pe=${pLen})` };
|
||||
const iLen = typeof importMetaToken === 'string' ? importMetaToken.length : 0;
|
||||
if (!token) return { mentions: [], debug: `no-token(pe=${pLen},iml=${iLen})` };
|
||||
const withSlash = target.endsWith('/') ? target : `${target}/`;
|
||||
const withoutSlash = target.replace(/\/+$/, '');
|
||||
const fetchOne = async (t: string) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue