@@ -10,16 +10,37 @@ const protocols = ["http:", "https:", "ws:", "wss:", "vrchat:"];
10
10
const cdnUrl = "https://dtuitjyhwcl5y.cloudfront.net" ;
11
11
12
12
const userAgent = new UserAgent ( ) ;
13
+ const uniqueAgent = userAgent . toString ( ) ;
13
14
14
15
const system = new SystemApi ( {
15
16
basePath : "https://vrchat.com/api/1" ,
16
17
baseOptions : {
17
18
headers : {
18
- "User-Agent" : userAgent . toString ( )
19
+ "User-Agent" : uniqueAgent
19
20
}
20
21
}
21
22
} ) ;
22
23
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
+
23
44
function trim ( value ) {
24
45
if ( ! value || typeof value !== "string" )
25
46
return value ;
@@ -63,7 +84,7 @@ function parseChunk(source) {
63
84
64
85
async function getLicense ( pathname ) {
65
86
const url = `${ cdnUrl } /${ pathname } .LICENSE.txt` ;
66
- console . log ( "fetching license" , url ) ;
87
+ // console.log("fetching license", url);
67
88
68
89
const response = await fetch ( url ) . catch ( ( ) => null ) ;
69
90
if ( ! response || ! response . ok ) return null ;
@@ -76,21 +97,17 @@ async function getLicense(pathname) {
76
97
await fs . rm ( "./dist/chunks" , { recursive : true } ) . catch ( ( ) => { } ) ;
77
98
await fs . mkdir ( "./dist/chunks" ) ;
78
99
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 ;
81
102
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 ( / ^ \/ / , "" ) ) ;
85
105
86
- const { source , identifiers : _identifiers , literals : _literals , probableChunks, pretty } = parseChunk ( jsRaw ) ;
106
+ const { identifiers : _identifiers , literals : _literals , probableChunks, pretty } = parseChunk ( jsRaw ) ;
87
107
88
- // await fs.writeFile("./dist/raw/app.js", source);
89
108
await fs . writeFile ( "./dist/app.js" , pretty ) ;
90
109
if ( license ) await fs . writeFile ( "./dist/app.js.LICENSE.txt" , license ) ;
91
110
92
- console . log ( probableChunks ) ;
93
-
94
111
const chunks = ( await Promise . all ( [ ...probableChunks . entries ( ) ] . map ( async ( [ id , hash ] ) => {
95
112
try {
96
113
const pathname = `${ hash } .js` ;
@@ -102,7 +119,6 @@ async function getLicense(pathname) {
102
119
const source = await response . text ( ) ;
103
120
104
121
const chunk = parseChunk ( source ) ;
105
- // await fs.writeFile(`./dist/raw/chunks/${id}.js`, source);
106
122
await fs . writeFile ( `./dist/chunks/${ id } .js` , chunk . pretty ) ;
107
123
if ( license ) await fs . writeFile ( `./dist/chunks/${ id } .js.LICENSE.txt` , license ) ;
108
124
0 commit comments