diff --git a/app.js b/app.js index fe7c1e2..96be9d2 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,6 @@ const zlib = require('zlib'); const fs = require('fs'); +var https = require('https'); const express = require('express'); const proxy = require('http-proxy-middleware'); @@ -12,7 +13,9 @@ const inject = fs.readFileSync('./inject.html', 'utf8'); const Transmission = require('transmission-promise') var tr_client = new Transmission({ - host:'192.168.1.176', + host:'tran.718it.biz', + ssl: true, + port: 443, username: 'william', password: 'palm7', }) @@ -49,13 +52,25 @@ app.get("/__api/torrent/:id", async function(req, res, next){ app.all("/*.js", function(req, res){res.send('')}); app.all("/*", proxy({ - target: 'http://piratebayztemzmv.onion', + target: 'https://piratebay.party', + agent: https.globalAgent, autoRewrite: true, + secure: false, + followRedirects: true, + autoRewrite: true, + changeOrigin: true, + secure: false, + followRedirects: true, + autoRewrite: true, + changeOrigin: true, + headers: { + host: 'piratebay.party' + }, selfHandleResponse: true, // so that the onProxyRes takes care of sending the response onProxyRes: function(proxyRes, req, res){ if(proxyRes.statusCode === 403 && proxyRes.headers['content-type'] && - proxyRes.headers['content-type'].match('html') + proxyRes.headers['content-type'].match('html') ){ console.log('403') var url = (req.protocol + '://' + req.get('host') + req.originalUrl); @@ -67,10 +82,13 @@ app.all("/*", proxy({ for(let key of Object.keys(proxyRes.headers)){ if(['content-encoding'].includes(key)) continue; - res.set(key, proxyRes.headers[key].toString().replace('http://', 'https://')) + // res.set(key, proxyRes.headers[key].toString().replace('http://', 'https://')) } let body = new Buffer(''); + proxyRes.on('error', function(e){ + console.error('ERROR!', e) + }); proxyRes.on('data', function(data){ body = Buffer.concat([body, data]); @@ -78,11 +96,13 @@ app.all("/*", proxy({ proxyRes.on('end', function(){ body = proxyRes.headers['content-encoding'] === 'gzip' ? zlib.gunzipSync(body).toString('utf8') : body; + body = proxyRes.headers['content-encoding'] === 'br' ? zlib.brotliDecompressSync(body).toString('utf8') : body; if(proxyRes.statusCode === 200 && proxyRes.headers['content-type'] && proxyRes.headers['content-type'].match('html') ){ body = body.toString().replace(/<\s*script[^]*?script>/igm, ''); + body = body.replace(/piratebay\.party/ig, 'tpb.718it.biz') body = body.replace(/<\s*iframe[^]*?iframe>/igm, ''); body = body.replace("", ''); body = body+inject+"";