diff --git a/src/lib/jobs/potoken.ts b/src/lib/jobs/potoken.ts index b0b1d7a..f91119c 100644 --- a/src/lib/jobs/potoken.ts +++ b/src/lib/jobs/potoken.ts @@ -25,6 +25,9 @@ export const poTokenGenerate = async ( const externalTokenGenerator = konfigStore.get( "server.external_token_generator", ) as string; + const externalTokenGeneratorKey = konfigStore.get( + "server.external_token_generator_key", + ) as string; const requestKey = "O43z0dpjhgX20SCx4KAo"; if (externalTokenGenerator != "" && externalTokenGenerator != undefined) { @@ -33,9 +36,26 @@ export const poTokenGenerate = async ( externalTokenGenerator, ); try { - const response = await fetch( - `${externalTokenGenerator}/generate`, - ); + let response: Response; + if ( + externalTokenGeneratorKey != "" && + externalTokenGeneratorKey != undefined + ) { + response = await fetch( + `${externalTokenGenerator}/generate`, { + headers: { + 'Authorization': `Bearer ${externalTokenGeneratorKey}` + } + } + ); + if (response.status == 401) { + throw new Error(`Key '${externalTokenGeneratorKey}' is invalid!`) + } + } else { + response = await fetch( + `${externalTokenGenerator}/generate`, + ); + } const data = await response.json(); return (await Innertube.create({ po_token: data.potoken,