add support for external token generator key
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 53s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 53s
This commit is contained in:
parent
465878355b
commit
f73ed00b6d
1 changed files with 23 additions and 3 deletions
|
@ -25,6 +25,9 @@ export const poTokenGenerate = async (
|
||||||
const externalTokenGenerator = konfigStore.get(
|
const externalTokenGenerator = konfigStore.get(
|
||||||
"server.external_token_generator",
|
"server.external_token_generator",
|
||||||
) as string;
|
) as string;
|
||||||
|
const externalTokenGeneratorKey = konfigStore.get(
|
||||||
|
"server.external_token_generator_key",
|
||||||
|
) as string;
|
||||||
const requestKey = "O43z0dpjhgX20SCx4KAo";
|
const requestKey = "O43z0dpjhgX20SCx4KAo";
|
||||||
|
|
||||||
if (externalTokenGenerator != "" && externalTokenGenerator != undefined) {
|
if (externalTokenGenerator != "" && externalTokenGenerator != undefined) {
|
||||||
|
@ -33,9 +36,26 @@ export const poTokenGenerate = async (
|
||||||
externalTokenGenerator,
|
externalTokenGenerator,
|
||||||
);
|
);
|
||||||
try {
|
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`,
|
`${externalTokenGenerator}/generate`,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return (await Innertube.create({
|
return (await Innertube.create({
|
||||||
po_token: data.potoken,
|
po_token: data.potoken,
|
||||||
|
|
Loading…
Reference in a new issue