Skip to content

Commit c5e3fec

Browse files
committed
fix?: add debugging info
1 parent dd94ff5 commit c5e3fec

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

scripts/checkup.js

+28-12
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,37 @@ const protocols = ["http:", "https:", "ws:", "wss:", "vrchat:"];
1010
const cdnUrl = "https://dtuitjyhwcl5y.cloudfront.net";
1111

1212
const userAgent = new UserAgent();
13+
const uniqueAgent = userAgent.toString();
1314

1415
const system = new SystemApi({
1516
basePath: "https://vrchat.com/api/1",
1617
baseOptions: {
1718
headers: {
18-
"User-Agent": userAgent.toString()
19+
"User-Agent": uniqueAgent
1920
}
2021
}
2122
});
2223

24+
async function getAppSource() {
25+
const response = await fetch("https://vrchat.com/api/1/js/app.js", {
26+
headers: {
27+
"user-agent": uniqueAgent
28+
}
29+
}).catch(() => null);
30+
31+
if (!response || !response.ok) {
32+
const source = await response.text();
33+
console.warn("failed to fetch app.js", source);
34+
35+
return null;
36+
}
37+
38+
const url = new URL(response.url);
39+
const source = await response.text();
40+
41+
return { url, source };
42+
}
43+
2344
function trim(value) {
2445
if (!value || typeof value !== "string")
2546
return value;
@@ -63,7 +84,7 @@ function parseChunk(source) {
6384

6485
async function getLicense(pathname) {
6586
const url = `${cdnUrl}/${pathname}.LICENSE.txt`;
66-
console.log("fetching license", url);
87+
// console.log("fetching license", url);
6788

6889
const response = await fetch(url).catch(() => null);
6990
if (!response || !response.ok) return null;
@@ -76,21 +97,17 @@ async function getLicense(pathname) {
7697
await fs.rm("./dist/chunks", { recursive: true }).catch(() => { });
7798
await fs.mkdir("./dist/chunks");
7899

79-
await fs.rm("./dist/raw/chunks", { recursive: true }).catch(() => { });
80-
// await fs.mkdir("./dist/raw/chunks");
100+
const app = await getAppSource();
101+
if (!app) return;
81102

82-
// Fetch and beautify the JavaScript bundle
83-
const { data: jsRaw, request } = await system.getJavaScript("public", "main");
84-
const license = await getLicense(request.path);
103+
const { url: request, source: jsRaw } = app;
104+
const license = await getLicense(request.pathname.replace(/^\//, ""));
85105

86-
const { source, identifiers: _identifiers, literals: _literals, probableChunks, pretty } = parseChunk(jsRaw);
106+
const { identifiers: _identifiers, literals: _literals, probableChunks, pretty } = parseChunk(jsRaw);
87107

88-
// await fs.writeFile("./dist/raw/app.js", source);
89108
await fs.writeFile("./dist/app.js", pretty);
90109
if (license) await fs.writeFile("./dist/app.js.LICENSE.txt", license);
91110

92-
console.log(probableChunks);
93-
94111
const chunks = (await Promise.all([...probableChunks.entries()].map(async ([id, hash]) => {
95112
try {
96113
const pathname = `${hash}.js`;
@@ -102,7 +119,6 @@ async function getLicense(pathname) {
102119
const source = await response.text();
103120

104121
const chunk = parseChunk(source);
105-
// await fs.writeFile(`./dist/raw/chunks/${id}.js`, source);
106122
await fs.writeFile(`./dist/chunks/${id}.js`, chunk.pretty);
107123
if (license) await fs.writeFile(`./dist/chunks/${id}.js.LICENSE.txt`, license);
108124

0 commit comments

Comments
 (0)