diff --git a/app.js b/app.js index 5ac0428..fe7c1e2 100644 --- a/app.js +++ b/app.js @@ -33,6 +33,19 @@ app.post("/__api/torrent", async function(req, res, next){ } }); +app.get("/__api/torrent/:id", async function(req, res, next){ + + try{ + let cres = await tr_client.get(Number(req.params.id), ["eta", "percentDone", "status", "rateDownload", "errorString", "hashString", 'name']); + res.json({id:req.params.id, cres}) + + }catch(e){ + console.error('error', e) + res.status(500).json({message: e}) + } +}); + + app.all("/*.js", function(req, res){res.send('')}); app.all("/*", proxy({ @@ -41,6 +54,17 @@ app.all("/*", proxy({ 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') + ){ + console.log('403') + var url = (req.protocol + '://' + req.get('host') + req.originalUrl); + proxyRes.headers['location'] = url.replace(/\??ckattempt\=\d+/, ''); + proxyRes.statusCode == 307 + + return res.end() + } + for(let key of Object.keys(proxyRes.headers)){ if(['content-encoding'].includes(key)) continue; res.set(key, proxyRes.headers[key].toString().replace('http://', 'https://')) @@ -54,7 +78,10 @@ app.all("/*", proxy({ proxyRes.on('end', function(){ body = proxyRes.headers['content-encoding'] === 'gzip' ? zlib.gunzipSync(body).toString('utf8') : body; - if(proxyRes.headers['content-type'] && proxyRes.headers['content-type'].match('html')){ + 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(/<\s*iframe[^]*?iframe>/igm, ''); body = body.replace("", ''); diff --git a/inject.html b/inject.html index 38d3a28..c9a5158 100644 --- a/inject.html +++ b/inject.html @@ -1,7 +1,19 @@ + + + + +
+

+ Torrents +

+ +
+