Compare commits

...

1 commit

Author SHA1 Message Date
8477e94011
add support for external token generator
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 58s
2024-12-16 16:48:15 -03:00

View file

@ -22,8 +22,58 @@ export const poTokenGenerate = async (
konfigStore: Store<Record<string, unknown>>,
innertubeClientCache: UniversalCache,
): Promise<Innertube> => {
const externalTokenGenerator = konfigStore.get(
"server.external_token_generator",
) as string;
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) {
innertubeClient = await Innertube.create({ retrieve_player: false });
}
@ -69,6 +119,8 @@ export const poTokenGenerate = async (
await BG.PoToken.generatePlaceholder(visitorData);
console.log("realpotoken: "+poTokenResult.poToken)
console.log("realvisitordata: "+visitorData)
return (await Innertube.create({
po_token: poTokenResult.poToken,
visitor_data: visitorData,