add support for external token generator
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 58s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 58s
This commit is contained in:
parent
d631aada71
commit
8477e94011
1 changed files with 52 additions and 0 deletions
|
@ -22,8 +22,58 @@ export const poTokenGenerate = async (
|
||||||
konfigStore: Store<Record<string, unknown>>,
|
konfigStore: Store<Record<string, unknown>>,
|
||||||
innertubeClientCache: UniversalCache,
|
innertubeClientCache: UniversalCache,
|
||||||
): Promise<Innertube> => {
|
): Promise<Innertube> => {
|
||||||
|
const externalTokenGenerator = konfigStore.get(
|
||||||
|
"server.external_token_generator",
|
||||||
|
) as string;
|
||||||
const requestKey = "O43z0dpjhgX20SCx4KAo";
|
const requestKey = "O43z0dpjhgX20SCx4KAo";
|
||||||
|
|
||||||
|
if (externalTokenGenerator != "" && externalTokenGenerator != undefined) {
|
||||||
|
console.log(
|
||||||
|
"using external token generator at " + externalTokenGenerator,
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`${externalTokenGenerator}/generate`,
|
||||||
|
);
|
||||||
|
const data = await response.json();
|
||||||
|
// innertubeClient.session.po_token = data.potoken;
|
||||||
|
// innertubeClient.session.context.client.visitorData =
|
||||||
|
// data.visitorData;
|
||||||
|
console.log(data.potoken);
|
||||||
|
console.log(data.visitorData);
|
||||||
|
return (await Innertube.create({
|
||||||
|
po_token: data.potoken,
|
||||||
|
visitor_data: data.visitorData,
|
||||||
|
fetch: getFetchClient(konfigStore),
|
||||||
|
cache: innertubeClientCache,
|
||||||
|
generate_session_locally: true,
|
||||||
|
}));
|
||||||
|
} catch (e) {
|
||||||
|
console.error("error fetch token from the external token generator: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// setInterval(() => {
|
||||||
|
// fetch(
|
||||||
|
// `${externalTokenGenerator}/generate`,
|
||||||
|
// ).then((response) => response.json()).then((data) => {
|
||||||
|
// innertubeClient.session.po_token = data.potoken;
|
||||||
|
// innertubeClient.session.context.client.visitorData =
|
||||||
|
// data.visitorData;
|
||||||
|
// console.log("po_token: "+data.potoken);
|
||||||
|
// console.log("visitor_data"+data.visitorData);
|
||||||
|
// return (await Innertube.create({
|
||||||
|
// po_token: poTokenResult.poToken,
|
||||||
|
// visitor_data: visitorData,
|
||||||
|
// fetch: getFetchClient(konfigStore),
|
||||||
|
// cache: innertubeClientCache,
|
||||||
|
// generate_session_locally: true,
|
||||||
|
// }));
|
||||||
|
// }).catch(e => {
|
||||||
|
// console.error("error getting tokens from external token generator: " + e)
|
||||||
|
// console.log("tokens will not change")
|
||||||
|
// });
|
||||||
|
// }, 5000);
|
||||||
|
|
||||||
if (innertubeClient.session.po_token) {
|
if (innertubeClient.session.po_token) {
|
||||||
innertubeClient = await Innertube.create({ retrieve_player: false });
|
innertubeClient = await Innertube.create({ retrieve_player: false });
|
||||||
}
|
}
|
||||||
|
@ -69,6 +119,8 @@ export const poTokenGenerate = async (
|
||||||
|
|
||||||
await BG.PoToken.generatePlaceholder(visitorData);
|
await BG.PoToken.generatePlaceholder(visitorData);
|
||||||
|
|
||||||
|
console.log("realpotoken: "+poTokenResult.poToken)
|
||||||
|
console.log("realvisitordata: "+visitorData)
|
||||||
return (await Innertube.create({
|
return (await Innertube.create({
|
||||||
po_token: poTokenResult.poToken,
|
po_token: poTokenResult.poToken,
|
||||||
visitor_data: visitorData,
|
visitor_data: visitorData,
|
||||||
|
|
Loading…
Reference in a new issue