trying to improve again dynamic import
This commit is contained in:
parent
57f4da848b
commit
f3fff5cc09
5 changed files with 103 additions and 77 deletions
1
compile.env
Normal file
1
compile.env
Normal file
|
@ -0,0 +1 @@
|
|||
DENO_COMPILED=true
|
|
@ -4,8 +4,14 @@ import { compress, decompress } from "https://deno.land/x/brotli@0.1.7/mod.ts";
|
|||
import { Store } from "@willsoto/node-konfig-core";
|
||||
let youtubePlayerReqLocation = "youtubePlayerReq";
|
||||
if (Deno.env.get("YT_PLAYER_REQ_LOCATION")) {
|
||||
youtubePlayerReqLocation = import.meta.dirname + "/" +
|
||||
if (Deno.env.has("DENO_COMPILED")) {
|
||||
youtubePlayerReqLocation = Deno.mainModule.replace("main.ts", "") +
|
||||
Deno.env.get("YT_PLAYER_REQ_LOCATION");
|
||||
} else {
|
||||
youtubePlayerReqLocation = Deno.env.get(
|
||||
"YT_PLAYER_REQ_LOCATION",
|
||||
) as string;
|
||||
}
|
||||
}
|
||||
const { youtubePlayerReq } = await import(youtubePlayerReqLocation);
|
||||
|
||||
|
|
|
@ -5,8 +5,14 @@ import { Innertube, UniversalCache } from "youtubei.js";
|
|||
import { Store } from "@willsoto/node-konfig-core";
|
||||
let getFetchClientLocation = "getFetchClient";
|
||||
if (Deno.env.get("GET_FETCH_CLIENT_LOCATION")) {
|
||||
getFetchClientLocation = import.meta.dirname + "/" +
|
||||
if (Deno.env.has("DENO_COMPILED")) {
|
||||
getFetchClientLocation = Deno.mainModule.replace("main.ts", "") +
|
||||
Deno.env.get("GET_FETCH_CLIENT_LOCATION");
|
||||
} else {
|
||||
getFetchClientLocation = Deno.env.get(
|
||||
"GET_FETCH_CLIENT_LOCATION",
|
||||
) as string;
|
||||
}
|
||||
}
|
||||
const { getFetchClient } = await import(getFetchClientLocation);
|
||||
|
||||
|
@ -14,7 +20,7 @@ const { getFetchClient } = await import(getFetchClientLocation);
|
|||
export const poTokenGenerate = async (
|
||||
innertubeClient: Innertube,
|
||||
konfigStore: Store<Record<string, unknown>>,
|
||||
innertubeClientCache: UniversalCache
|
||||
innertubeClientCache: UniversalCache,
|
||||
): Promise<Innertube> => {
|
||||
const requestKey = "O43z0dpjhgX20SCx4KAo";
|
||||
|
||||
|
@ -62,7 +68,7 @@ export const poTokenGenerate = async (
|
|||
bgConfig,
|
||||
});
|
||||
|
||||
await BG.PoToken.generatePlaceholder(visitorData);;
|
||||
await BG.PoToken.generatePlaceholder(visitorData);
|
||||
|
||||
return (await Innertube.create({
|
||||
po_token: poTokenResult.poToken,
|
||||
|
|
15
src/main.ts
15
src/main.ts
|
@ -5,8 +5,14 @@ import { poTokenGenerate } from "./lib/jobs/potoken.ts";
|
|||
import { konfigLoader } from "./lib/helpers/konfigLoader.ts";
|
||||
let getFetchClientLocation = "getFetchClient";
|
||||
if (Deno.env.get("GET_FETCH_CLIENT_LOCATION")) {
|
||||
getFetchClientLocation = import.meta.dirname + "/" +
|
||||
if (Deno.env.has("DENO_COMPILED")) {
|
||||
getFetchClientLocation = Deno.mainModule.replace("main.ts", "") +
|
||||
Deno.env.get("GET_FETCH_CLIENT_LOCATION");
|
||||
} else {
|
||||
getFetchClientLocation = Deno.env.get(
|
||||
"GET_FETCH_CLIENT_LOCATION",
|
||||
) as string;
|
||||
}
|
||||
}
|
||||
const { getFetchClient } = await import(getFetchClientLocation);
|
||||
|
||||
|
@ -26,10 +32,10 @@ const innertubeClientCookies = konfigStore.get(
|
|||
) as string;
|
||||
let innertubeClientCache = new UniversalCache(
|
||||
true,
|
||||
konfigStore.get('cache.directory') as string + "/youtubei.js/",
|
||||
konfigStore.get("cache.directory") as string + "/youtubei.js/",
|
||||
) as UniversalCache;
|
||||
|
||||
Deno.env.set('TMPDIR', konfigStore.get("cache.directory") as string)
|
||||
Deno.env.set("TMPDIR", konfigStore.get("cache.directory") as string);
|
||||
|
||||
if (!innertubeClientOauthEnabled) {
|
||||
if (innertubeClientJobPoTokenEnabled) {
|
||||
|
@ -110,6 +116,7 @@ app.use("*", async (c, next) => {
|
|||
routes(app, konfigStore);
|
||||
|
||||
Deno.serve({
|
||||
port: Number(Deno.env.get("PORT")) || konfigStore.get("server.port") as number,
|
||||
port: Number(Deno.env.get("PORT")) ||
|
||||
konfigStore.get("server.port") as number,
|
||||
hostname: Deno.env.get("HOST") || konfigStore.get("server.host") as string,
|
||||
}, app.fetch);
|
||||
|
|
|
@ -3,8 +3,14 @@ import { Store } from "@willsoto/node-konfig-core";
|
|||
import { HTTPException } from "hono/http-exception";
|
||||
let getFetchClientLocation = "getFetchClient";
|
||||
if (Deno.env.get("GET_FETCH_CLIENT_LOCATION")) {
|
||||
getFetchClientLocation = import.meta.dirname + "/" +
|
||||
if (Deno.env.has("DENO_COMPILED")) {
|
||||
getFetchClientLocation = Deno.mainModule.replace("main.ts", "") +
|
||||
Deno.env.get("GET_FETCH_CLIENT_LOCATION");
|
||||
} else {
|
||||
getFetchClientLocation = Deno.env.get(
|
||||
"GET_FETCH_CLIENT_LOCATION",
|
||||
) as string;
|
||||
}
|
||||
}
|
||||
const { getFetchClient } = await import(getFetchClientLocation);
|
||||
|
||||
|
|
Loading…
Reference in a new issue