recycleactor commited on
Commit
0c6c772
·
verified ·
1 Parent(s): 8764d35

Upload server.js

Browse files
Files changed (1) hide show
  1. server.js +17 -41
server.js CHANGED
@@ -154,6 +154,17 @@ function jsWrapper(serverBase, baseUrl, transpiledCode, needRegenerator, useVpn,
154
  '}catch(e){}' +
155
  (useEs5 ? 'try{if(window.__es5CssVarsApply)window.__es5CssVarsApply();}catch(e){}' : '') +
156
  (useVpn ? (
 
 
 
 
 
 
 
 
 
 
 
157
  'var _origFetch=window.fetch;' +
158
  'var fetch=function(input,init){' +
159
  'try{' +
@@ -206,8 +217,12 @@ function jsWrapper(serverBase, baseUrl, transpiledCode, needRegenerator, useVpn,
206
  'Lampa.Player=Object.create(_RealPlayer);' +
207
  'Lampa.Player.play=function(data){' +
208
  'try{' +
209
- 'if(data&&data.url&&typeof data.url==="string"&&data.url.indexOf(__es5_server)===-1&&data.url.indexOf("warp.cfhttp.top")===-1){' +
210
- 'data.url=__es5_server+"/r?url="+encodeURIComponent(data.url).replace(/%3A/gi, ":").replace(/%2F/gi, "/");' +
 
 
 
 
211
  '}' +
212
  '}catch(e){}' +
213
  'return _RealPlayer.play.apply(this,arguments);' +
@@ -443,46 +458,7 @@ app.all('/r', async (req, res) => {
443
  signal: controller.signal
444
  })
445
 
446
- const isJson = (upstream.headers.get('content-type') || '').includes('application/json');
447
-
448
- if (isJson) {
449
- const buffer = await upstream.arrayBuffer();
450
- let text = Buffer.from(buffer).toString('utf8');
451
-
452
- // Replace wss:// urls to go through our proxy
453
- const serverBase = getSelfBase(req);
454
- const wsBase = serverBase.replace(/^http/, 'ws');
455
-
456
- text = text.replace(/wss:\/\/[^"'\s]+/g, (match) => {
457
- return wsBase + '/ws?url=' + encodeURIComponent(match);
458
- });
459
 
460
- const outBuf = Buffer.from(text, 'utf8');
461
-
462
- res.status(upstream.status);
463
- for (const h of RES_HEADERS_PASS) {
464
- if (h === 'content-length') {
465
- res.setHeader(h, outBuf.length);
466
- continue;
467
- }
468
-
469
- let v;
470
- if (h === 'set-cookie') {
471
- const cookies = upstream.headers.getSetCookie ? upstream.headers.getSetCookie() : [];
472
- if (cookies.length) {
473
- // Strip domain from cookies so they apply to our proxy's domain
474
- v = cookies.map(c => c.replace(/domain=[^;]+;?\s*/gi, ''));
475
- }
476
- } else {
477
- v = upstream.headers.get(h);
478
- }
479
-
480
- if (v) res.setHeader(h, v);
481
- }
482
- res.setHeader('access-control-allow-origin', '*');
483
-
484
- return res.end(outBuf);
485
- }
486
 
487
  res.status(upstream.status)
488
  for (const h of RES_HEADERS_PASS) {
 
154
  '}catch(e){}' +
155
  (useEs5 ? 'try{if(window.__es5CssVarsApply)window.__es5CssVarsApply();}catch(e){}' : '') +
156
  (useVpn ? (
157
+ 'var _RealWS=window.WebSocket;' +
158
+ 'window.WebSocket=function(url, protocols){' +
159
+ 'try{' +
160
+ 'if(typeof url==="string" && url.indexOf(__es5_server)===-1 && /^wss?:\\/\\//i.test(url)){' +
161
+ 'var wsBase=__es5_server.replace(/^http/,"ws");' +
162
+ 'url=wsBase+"/ws?url="+encodeURIComponent(url);' +
163
+ '}' +
164
+ '}catch(e){}' +
165
+ 'return protocols ? new _RealWS(url, protocols) : new _RealWS(url);' +
166
+ '};' +
167
+ 'if(_RealWS.prototype) window.WebSocket.prototype=_RealWS.prototype;' +
168
  'var _origFetch=window.fetch;' +
169
  'var fetch=function(input,init){' +
170
  'try{' +
 
217
  'Lampa.Player=Object.create(_RealPlayer);' +
218
  'Lampa.Player.play=function(data){' +
219
  'try{' +
220
+ 'function px(u){if(typeof u==="string"&&u.indexOf(__es5_server)===-1&&u.indexOf("warp.cfhttp.top")===-1){return __es5_server+"/r?url="+encodeURIComponent(u).replace(/%3A/gi, ":").replace(/%2F/gi, "/");}return u;}' +
221
+ 'if(data){' +
222
+ 'if(data.url) data.url=px(data.url);' +
223
+ 'if(data.file) data.file=px(data.file);' +
224
+ 'if(data.video&&data.video.url) data.video.url=px(data.video.url);' +
225
+ 'if(Array.isArray(data.url)){for(var i=0;i<data.url.length;i++){if(data.url[i].file)data.url[i].file=px(data.url[i].file);}}' +
226
  '}' +
227
  '}catch(e){}' +
228
  'return _RealPlayer.play.apply(this,arguments);' +
 
458
  signal: controller.signal
459
  })
460
 
 
 
 
 
 
 
 
 
 
 
 
 
 
461
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
462
 
463
  res.status(upstream.status)
464
  for (const h of RES_HEADERS_PASS) {