Skip to content

Commit 2323264

Browse files
committed
feat: added custom js evaluator
1 parent c0a4d3a commit 2323264

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

src/commands/play.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Message } from "../types/message";
33
import fs from "fs";
44
import path from "path";
55
import { exec } from "child_process";
6-
import { Innertube, UniversalCache, Utils, Types } from "youtubei.js";
6+
import { Innertube, UniversalCache, Utils, Platform, Types } from "youtubei.js";
77
import util from "util";
88
import log from "../components/utils/log";
99
import { fileExists } from "../components/utils/file";
@@ -19,6 +19,25 @@ export const info = {
1919
cooldown: 5000,
2020
};
2121

22+
Platform.shim.eval = async (
23+
data: Types.BuildScriptResult,
24+
env: Record<string, Types.VMPrimative>,
25+
) => {
26+
const properties = [];
27+
28+
if (env.n) {
29+
properties.push(`n: exportedVars.nFunction("${env.n}")`);
30+
}
31+
32+
if (env.sig) {
33+
properties.push(`sig: exportedVars.sigFunction("${env.sig}")`);
34+
}
35+
36+
const code = `${data.output}\nreturn { ${properties.join(", ")} }`;
37+
38+
return new Function(code)();
39+
};
40+
2241
async function safeDownload(
2342
yt: Innertube,
2443
id: string,

src/commands/video.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { MessageMedia } from "whatsapp-web.js";
22
import { Message } from "../types/message";
33
import fs from "fs";
44
import path from "path";
5-
import { Innertube, UniversalCache, Utils } from "youtubei.js";
5+
import { Innertube, UniversalCache, Platform, Types, Utils } from "youtubei.js";
66
import log from "../components/utils/log";
77
import { DownloadOptions } from "youtubei.js/dist/src/types";
88
import { fileExists } from "../components/utils/file";
@@ -16,6 +16,25 @@ export const info = {
1616
cooldown: 5000,
1717
};
1818

19+
Platform.shim.eval = async (
20+
data: Types.BuildScriptResult,
21+
env: Record<string, Types.VMPrimative>,
22+
) => {
23+
const properties = [];
24+
25+
if (env.n) {
26+
properties.push(`n: exportedVars.nFunction("${env.n}")`);
27+
}
28+
29+
if (env.sig) {
30+
properties.push(`sig: exportedVars.sigFunction("${env.sig}")`);
31+
}
32+
33+
const code = `${data.output}\nreturn { ${properties.join(", ")} }`;
34+
35+
return new Function(code)();
36+
};
37+
1938
async function safeDownload(
2039
yt: Innertube,
2140
id: string,

0 commit comments

Comments
 (0)