transmission added
This commit is contained in:
parent
d80073d715
commit
edcc7f6e62
29
app.js
29
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("/*.js", function(req, res){res.send('')});
|
||||||
|
|
||||||
app.all("/*", proxy({
|
app.all("/*", proxy({
|
||||||
@ -41,6 +54,17 @@ app.all("/*", proxy({
|
|||||||
selfHandleResponse: true, // so that the onProxyRes takes care of sending the response
|
selfHandleResponse: true, // so that the onProxyRes takes care of sending the response
|
||||||
onProxyRes: function(proxyRes, req, res){
|
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)){
|
for(let key of Object.keys(proxyRes.headers)){
|
||||||
if(['content-encoding'].includes(key)) continue;
|
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://'))
|
||||||
@ -54,7 +78,10 @@ app.all("/*", proxy({
|
|||||||
|
|
||||||
proxyRes.on('end', function(){
|
proxyRes.on('end', function(){
|
||||||
body = proxyRes.headers['content-encoding'] === 'gzip' ? zlib.gunzipSync(body).toString('utf8') : body;
|
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.toString().replace(/<\s*script[^]*?script>/igm, '');
|
||||||
body = body.replace(/<\s*iframe[^]*?iframe>/igm, '');
|
body = body.replace(/<\s*iframe[^]*?iframe>/igm, '');
|
||||||
body = body.replace("</html>", '');
|
body = body.replace("</html>", '');
|
||||||
|
119
inject.html
119
inject.html
@ -1,7 +1,19 @@
|
|||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment-with-locales.min.js"></script>
|
||||||
|
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
|
||||||
|
|
||||||
|
<div id="dialog" title="Torrents">
|
||||||
|
<h3>
|
||||||
|
Torrents
|
||||||
|
</h3>
|
||||||
|
<ul>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
function post(url, data, callack){
|
function post(url, data, callback){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
@ -9,7 +21,7 @@
|
|||||||
contentType: "application/json; charset=utf-8",
|
contentType: "application/json; charset=utf-8",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
complete: function(res, text){
|
complete: function(res, text){
|
||||||
callack(
|
callback(
|
||||||
text !== 'success' ? res.statusText : null,
|
text !== 'success' ? res.statusText : null,
|
||||||
JSON.parse(res.responseText),
|
JSON.parse(res.responseText),
|
||||||
res.status
|
res.status
|
||||||
@ -18,7 +30,107 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var torrents = (function(){
|
||||||
|
var torrents = {};
|
||||||
|
|
||||||
|
torrents.list = JSON.parse(window.localStorage.getItem('torrents') || '{}' ).list || [];
|
||||||
|
|
||||||
|
var in_list = function(data){
|
||||||
|
return false;
|
||||||
|
for(let torrent of torrents.list){
|
||||||
|
if(torrent.hash === data.hash) return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
torrents.add = function(data){
|
||||||
|
if(in_list(data)) return false;
|
||||||
|
torrents.list.push(data);
|
||||||
|
torrents.updateStorage();
|
||||||
|
};
|
||||||
|
|
||||||
|
torrents.updateStorage = function(){
|
||||||
|
window.localStorage.setItem('torrents', JSON.stringify({list: torrents.list}))
|
||||||
|
};
|
||||||
|
|
||||||
|
torrents.statusAll = function(callback){
|
||||||
|
var list_count = torrents.list.length;
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
|
for(let torrent of torrents.list){
|
||||||
|
if(torrent.percentDone === 1){
|
||||||
|
count++;
|
||||||
|
if(count === list_count){
|
||||||
|
torrents.updateStorage();
|
||||||
|
|
||||||
|
(callback || function(){})(torrents.list)
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$.getJSON('/__api/torrent/'+torrent.id, function(data){
|
||||||
|
$.extend(true, torrent, data.cres.torrents[0])
|
||||||
|
count++;
|
||||||
|
if(count === list_count){
|
||||||
|
torrents.updateStorage();
|
||||||
|
|
||||||
|
(callback || function(){})(torrents.list)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
torrents.updateDialog = function(){
|
||||||
|
var $ol = $($('#dialog').find('ul')[0]);
|
||||||
|
|
||||||
|
$ol.html('');
|
||||||
|
|
||||||
|
torrents.list.forEach(function(torrent){
|
||||||
|
|
||||||
|
let li = `<li>${torrent.name}`;
|
||||||
|
|
||||||
|
if(torrent.percentDone < 1){
|
||||||
|
li += `
|
||||||
|
<div id="progressbar-${torrent.hashString}"></div>
|
||||||
|
ETA: ${moment().seconds(torrent.eta).fromNow()} Rate: ${Math.floor(torrent.rateDownload/1024/1024)}mb
|
||||||
|
`
|
||||||
|
}else{
|
||||||
|
li += `<br /> Done! <a href="https://stuff.718it.biz/torrents/${torrent.name}" target="_blank"> HTTP Link</a>`
|
||||||
|
}
|
||||||
|
|
||||||
|
li += `<hr /></li>`
|
||||||
|
$ol.prepend(li)
|
||||||
|
|
||||||
|
$("#progressbar-"+torrent.hashString).progressbar({
|
||||||
|
value: torrent.percentDone*100
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$( document ).ready(function() {
|
||||||
|
|
||||||
|
torrents.statusAll();
|
||||||
|
|
||||||
|
torrents.timmer = setInterval(function(){
|
||||||
|
console.log('auto update')
|
||||||
|
torrents.statusAll(function(){
|
||||||
|
torrents.updateDialog()
|
||||||
|
});
|
||||||
|
}, 2000)
|
||||||
|
});
|
||||||
|
|
||||||
|
return torrents;
|
||||||
|
})()
|
||||||
|
|
||||||
$( document ).ready(function() {
|
$( document ).ready(function() {
|
||||||
|
|
||||||
|
$($('input[name="q"]')[0]).before($('<img src="https://chocolatey.org/content/packageimages/transmission.2.92.svg" height=24 width=24/>').on('click', function(){
|
||||||
|
torrents.statusAll(function(){
|
||||||
|
console.log('stats all')
|
||||||
|
$("#dialog").dialog();
|
||||||
|
torrents.updateDialog()
|
||||||
|
});
|
||||||
|
|
||||||
|
}))
|
||||||
|
|
||||||
$('a').each(function(idx, el){
|
$('a').each(function(idx, el){
|
||||||
var $el = $(el);
|
var $el = $(el);
|
||||||
@ -33,7 +145,8 @@
|
|||||||
magnet: window.btoa($(this).data('link')),
|
magnet: window.btoa($(this).data('link')),
|
||||||
password: prompt('password?')
|
password: prompt('password?')
|
||||||
}, function(err, data){
|
}, function(err, data){
|
||||||
console.log(arguments);
|
torrents.add(data);
|
||||||
|
// console.log(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user