add support for external token generator key
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 53s

This commit is contained in:
Fijxu 2024-12-17 03:28:49 -03:00
parent 465878355b
commit f73ed00b6d
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4

View file

@ -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(
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,