works
This commit is contained in:
parent
7fad640cca
commit
1c7e2e794e
@ -3,13 +3,9 @@
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.createTable('Torrents', {
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
hashString: {
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
magnetLink: {
|
||||
|
@ -53,12 +53,47 @@ module.exports = (sequelize, DataTypes, Model) => {
|
||||
}
|
||||
}
|
||||
|
||||
static async migrate(hashString, username){
|
||||
try{
|
||||
let exists = await this.findByPk(hashString);
|
||||
|
||||
if(exists){
|
||||
console.log('torrent in DB, skipping')
|
||||
return {}
|
||||
}
|
||||
|
||||
let res = ( await tr_client.get(hashString, [
|
||||
"eta", "percentDone", "status", "rateDownload",
|
||||
"errorString", "hashString", 'name',
|
||||
'downloadDir',
|
||||
'addedDate',
|
||||
'magnetLink',
|
||||
'files', //array of files
|
||||
'filesStats', // array of files with status
|
||||
'isFinished',
|
||||
'isStalled',
|
||||
'peers',
|
||||
'peersConnected', // array of peers,
|
||||
'sizeWhenDone',
|
||||
]) ).torrents[0];
|
||||
|
||||
// console.log('date:', res.addedDate, new Date(res.addedDate*1000), 'res:', res)
|
||||
|
||||
let instance = await this.build({createdAt: new Date(res.addedDate*1000), ...res, added_by: username});
|
||||
await instance.save();
|
||||
return {...res, ...instance.dataValues};
|
||||
}catch(error){
|
||||
console.error('migrate error', error);
|
||||
}
|
||||
}
|
||||
|
||||
async getTorrentData(noUpdate){
|
||||
try{
|
||||
let res = ( await tr_client.get(this.hashString, [
|
||||
"eta", "percentDone", "status", "rateDownload",
|
||||
"errorString", "hashString", 'name',
|
||||
'downloadDir',
|
||||
'dateCreated',
|
||||
'files', //array of files
|
||||
'filesStats', // array of files with status
|
||||
'isFinished',
|
||||
@ -100,6 +135,11 @@ module.exports = (sequelize, DataTypes, Model) => {
|
||||
}
|
||||
}
|
||||
Torrent.init({
|
||||
hashString: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
magnetLink: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
@ -112,7 +152,6 @@ module.exports = (sequelize, DataTypes, Model) => {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
hashString: DataTypes.STRING,
|
||||
name: DataTypes.STRING,
|
||||
added_by: {
|
||||
type: DataTypes.STRING,
|
||||
@ -137,6 +176,9 @@ module.exports = (sequelize, DataTypes, Model) => {
|
||||
type: DataTypes.NUMBER,
|
||||
allowNull: true,
|
||||
},
|
||||
createdAt: {
|
||||
type: DataTypes.DATE
|
||||
},
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'Torrent',
|
||||
|
@ -7,7 +7,7 @@
|
||||
var make = function( element ){
|
||||
|
||||
//construct array
|
||||
function makeArray( input ){
|
||||
function makeArray( input , index ){
|
||||
|
||||
var result = [];
|
||||
|
||||
@ -25,6 +25,20 @@
|
||||
configurable: true
|
||||
} );
|
||||
|
||||
Object.defineProperty( result, "__jq_index", {
|
||||
value: index,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
} );
|
||||
|
||||
function removeEmpty(){
|
||||
if(result.__jq_empty){
|
||||
result.__jq_empty.remove();
|
||||
delete result.__jq_empty;
|
||||
}
|
||||
}
|
||||
|
||||
result.splice = function(inputValue, ...args){
|
||||
//splice does all the heavy lifting by interacting with the DOM elements.
|
||||
|
||||
@ -88,6 +102,7 @@
|
||||
|
||||
//if there are fields to add to the array, add them
|
||||
if( toAdd.length > 0 ){
|
||||
removeEmpty()
|
||||
|
||||
//$.each( toAdd, function( key, value ){
|
||||
for(var I = 0; I < toAdd.length; I++){
|
||||
@ -176,7 +191,7 @@
|
||||
result.indexOf = function( key, value ){
|
||||
if( !value ){
|
||||
value = arguments[0];
|
||||
key = this.__index;
|
||||
key = this.__jq_index;
|
||||
}
|
||||
for ( var index = 0; index < this.length; ++index ) {
|
||||
if( this[index][key] === value ){
|
||||
@ -200,7 +215,7 @@
|
||||
if( !update ){
|
||||
update = arguments[1];
|
||||
value = arguments[0];
|
||||
key = this.__index;
|
||||
key = this.__jq_index;
|
||||
}
|
||||
|
||||
var index = this.indexOf( key, value );
|
||||
@ -226,7 +241,7 @@
|
||||
if( type === 'object' ){
|
||||
result.push( value );
|
||||
}else if( type === 'string' ){
|
||||
Object.defineProperty( result, "__index", {
|
||||
Object.defineProperty( result, "__jq_index", {
|
||||
value: value,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
@ -248,19 +263,23 @@
|
||||
|
||||
var $this = $( element );
|
||||
var repeatId = $this.attr( 'jq-repeat' );
|
||||
var index = $this.attr( 'jq-repeat-index' );
|
||||
var tempId = repeatId + 'Template';
|
||||
var templateId = $( '#' + tempId ).html();
|
||||
var empty = $(`[jq-repeat-defualt="${repeatId}"]`);
|
||||
|
||||
|
||||
$this.removeAttr( 'jq-repeat' );
|
||||
var template = element.outerHTML
|
||||
$this.removeAttr( 'jq-repeat-index' );
|
||||
var template = element.outerHTML
|
||||
|
||||
$this.replaceWith( '<script type="x-tmpl-mustache" id="' + tempId + '" class="jq-repeat-' + repeatId + ' " jq-repeat-index="holder"><\/script>' );
|
||||
|
||||
Mustache.parse(templateId); // optional, speeds up future uses
|
||||
|
||||
|
||||
$.scope[repeatId] = makeArray($.scope[repeatId]);
|
||||
$.scope[repeatId].__rq_template = template
|
||||
$.scope[repeatId] = makeArray($.scope[repeatId], index);
|
||||
$.scope[repeatId].__rq_template = template;
|
||||
$.scope[repeatId].__jq_empty = empty;
|
||||
};
|
||||
|
||||
$( document ).ready( function(){
|
||||
|
@ -8,473 +8,540 @@
|
||||
<script src="/__static/js/app.js"></script>
|
||||
|
||||
<style type="text/css">
|
||||
.ui-dialog .ui-dialog-title{
|
||||
width: unset;
|
||||
}
|
||||
.ui-dialog{
|
||||
padding: 0;
|
||||
}
|
||||
.ui-dialog .ui-dialog-title{
|
||||
width: unset;
|
||||
}
|
||||
|
||||
#tbp_proxy_header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
z-index: 95;
|
||||
background: lightblue;
|
||||
height: 3em;
|
||||
text-align: initial;
|
||||
padding-top: .5em;
|
||||
padding-right: 1em;
|
||||
}
|
||||
#tbp_proxy_header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
z-index: 95;
|
||||
background: lightblue;
|
||||
height: 3em;
|
||||
text-align: initial;
|
||||
padding-top: .5em;
|
||||
padding-right: 1em;
|
||||
}
|
||||
|
||||
#tbp_proxy_header_right{
|
||||
margin-right: 2em;
|
||||
float: right;
|
||||
#tbp_proxy_header_right{
|
||||
margin-right: 2em;
|
||||
float: right;
|
||||
|
||||
display: flex;
|
||||
align-items:center;
|
||||
}
|
||||
display: flex;
|
||||
align-items:center;
|
||||
}
|
||||
|
||||
#tbp_proxy_torrent_dialog_opener{
|
||||
border-radius: 25px;
|
||||
background: lightseagreen;
|
||||
display: flex;
|
||||
align-items:center;
|
||||
#tbp_proxy_torrent_dialog_opener{
|
||||
border-radius: 25px;
|
||||
background: lightseagreen;
|
||||
display: flex;
|
||||
align-items:center;
|
||||
|
||||
padding: 1em;
|
||||
padding-top: .3em;
|
||||
padding-bottom: .3em;
|
||||
padding: 1em;
|
||||
padding-top: .3em;
|
||||
padding-bottom: .3em;
|
||||
|
||||
margin-right: .5em;
|
||||
}
|
||||
margin-right: .5em;
|
||||
}
|
||||
|
||||
#header {
|
||||
padding-top: 3.5em;
|
||||
}
|
||||
#header {
|
||||
padding-top: 3.5em;
|
||||
}
|
||||
</style>
|
||||
|
||||
<!--
|
||||
Dialog boxes to be displayed
|
||||
Dialog boxes to be displayed
|
||||
-->
|
||||
|
||||
<div id="tbp_proxy_login_dialog" title="SSO Login">
|
||||
<div class="shadow-lg card">
|
||||
<div class="card-header shadow actionMessage" style="display:none"></div>
|
||||
<div class="card-body">
|
||||
<form action="auth/login" onsubmit="formAJAX(this)" evalAJAX="
|
||||
app.auth.setToken(data.token);
|
||||
app.auth.logInRedirect();
|
||||
">
|
||||
<input type="hidden" name="redirect" value="<%= redirect %>">
|
||||
<div class="card-header shadow actionMessage" style="display:none"></div>
|
||||
<div class="card-body">
|
||||
<form action="auth/login" onsubmit="formAJAX(this)" evalAJAX="
|
||||
app.auth.setToken(data.token);
|
||||
app.auth.logInRedirect();
|
||||
">
|
||||
<input type="hidden" name="redirect" value="<%= redirect %>">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label">User name</label>
|
||||
<div class="input-group mb-3 shadow">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" ><i class="fa-solid fa-user-tie"></i></span>
|
||||
</div>
|
||||
<input type="text" name="uid" class="form-control" placeholder="jsmith" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label">User name</label>
|
||||
<div class="input-group mb-3 shadow">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" ><i class="fa-solid fa-user-tie"></i></span>
|
||||
</div>
|
||||
<input type="text" name="uid" class="form-control" placeholder="jsmith" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label">Password</label>
|
||||
<div class="input-group mb-3 shadow">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" ><i class="fa-solid fa-key"></i></span>
|
||||
</div>
|
||||
<input type="password" name="password" class="form-control" placeholder="hunter123!"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label">Password</label>
|
||||
<div class="input-group mb-3 shadow">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" ><i class="fa-solid fa-key"></i></span>
|
||||
</div>
|
||||
<input type="password" name="password" class="form-control" placeholder="hunter123!"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-outline-dark"><i class="fa-solid fa-right-to-bracket"></i> Log in</button>
|
||||
</form>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-outline-dark"><i class="fa-solid fa-right-to-bracket"></i> Log in</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!--
|
||||
Torrent List Dialog
|
||||
Torrent List Dialog
|
||||
-->
|
||||
|
||||
<style type="text/css">
|
||||
#tbp_proxy_torrent_dialog{
|
||||
padding: 0;
|
||||
}
|
||||
#tbp_proxy_torrent_dialog progress{
|
||||
width: 100%;
|
||||
height: 2em;
|
||||
}
|
||||
#tbp_proxy_torrent_dialog ul{
|
||||
max-height: 400px;
|
||||
overflow-y: scroll;
|
||||
list-style-type: none;
|
||||
padding-left: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
#tbp_proxy_torrent_dialog li{
|
||||
padding-left: 1em;
|
||||
padding-right: 1em;
|
||||
}
|
||||
#tbp_proxy_torrent_dialog{
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#tbp_proxy_torrent_dialog progress{
|
||||
width: 100%;
|
||||
height: 2em;
|
||||
}
|
||||
|
||||
#tbp_proxy_torrent_dialog ul{
|
||||
height: 400px;
|
||||
overflow-y: scroll;
|
||||
list-style-type: none;
|
||||
padding-left: 0;
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
#tbp_proxy_torrent_dialog li{
|
||||
padding-left: 1em;
|
||||
padding-right: 1em;
|
||||
}
|
||||
|
||||
#tbp_proxy_torrent_dialog li p{
|
||||
margin: .3em;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div id="tbp_proxy_torrent_dialog" title="Torrents">
|
||||
<ul>
|
||||
<li jq-repeat="tbp_proxy_torrent_dialog_torrents">{{name}}
|
||||
<br />
|
||||
{{^isFinished}}
|
||||
<progress id="file" max="100" value="{{percentDone}}">{{percentDone}}%</progress>
|
||||
<br />
|
||||
<b>{{statusText}}</b> @ <b>{{rateDownload}}</b> finishing <b>{{eta}}</b>
|
||||
<br />
|
||||
{{^isActive}}
|
||||
<button class="ui-button ui-widget ui-corner-all" onclick="app.torrent.start({{id}})">
|
||||
<span class="ui-icon ui-icon-play"></span> Start
|
||||
</button>
|
||||
{{/isActive}}
|
||||
<ul>
|
||||
<li jq-repeat="tbp_proxy_torrent_dialog_torrents" jq-repeat-index="hashString">
|
||||
<p>
|
||||
<b>{{name}}</b> - <i>{{statusText}}</i>
|
||||
</p>
|
||||
<p>
|
||||
Is <b>{{sizeWhenDone}}</b>
|
||||
saved to <b>{{downloadDir}}</b>
|
||||
added by <b>{{added_by}}</b>
|
||||
<b>{{createdAtString}}</b>
|
||||
</p>
|
||||
|
||||
{{#isActive}}
|
||||
<button class="ui-button ui-widget ui-corner-all" onclick="app.torrent.stop({{id}})">
|
||||
<span class="ui-icon ui-icon-pause"></span>Pause
|
||||
</button>
|
||||
{{/isActive}}
|
||||
{{^isFinished}}
|
||||
<p>
|
||||
<progress id="file" max="100" value="{{percentDone}}">{{percentDone}}%</progress>
|
||||
</p>
|
||||
|
||||
<button class="ui-button ui-widget ui-corner-all" onclick="
|
||||
app.torrent.destroy({{id}}, function(error, data){
|
||||
$.scope.tbp_proxy_torrent_dialog_torrents.splice({{__id}}, 1);
|
||||
});
|
||||
">
|
||||
<span class="ui-icon ui-icon-closethick"></span>Delete
|
||||
</button>
|
||||
{{#isActive}}
|
||||
<p>
|
||||
<b>{{rateDownload}}</b>
|
||||
Finishing <b>{{eta}}</b>
|
||||
From <b>{{peersConnected}}</b> Peers
|
||||
</p>
|
||||
|
||||
{{/isFinished}}
|
||||
<button class="ui-button ui-widget ui-corner-all" onclick="app.torrent.stop({{hashString}})">
|
||||
<span class="ui-icon ui-icon-pause"></span>Pause
|
||||
</button>
|
||||
{{/isActive}}
|
||||
|
||||
{{#isFinished}}
|
||||
<br /> Done! <a href="https://stuff.718it.biz/torrents/{{name}}" target="_blank"> HTTP Link</a>
|
||||
{{/isFinished}}
|
||||
<hr />
|
||||
</li>
|
||||
</ul>
|
||||
{{^isActive}}
|
||||
<button class="ui-button ui-widget ui-corner-all" onclick="app.torrent.start({{hashString}})">
|
||||
<span class="ui-icon ui-icon-play"></span> Start
|
||||
</button>
|
||||
{{/isActive}}
|
||||
|
||||
<button class="ui-button ui-widget ui-corner-all" onclick="
|
||||
app.torrent.destroy({{hashString}}, function(error, data){
|
||||
$.scope.tbp_proxy_torrent_dialog_torrents.splice({{__id}}, 1);
|
||||
});
|
||||
">
|
||||
<span class="ui-icon ui-icon-closethick"></span>Delete
|
||||
</button>
|
||||
</p>
|
||||
{{/isFinished}}
|
||||
|
||||
{{#errorString}}
|
||||
<p>
|
||||
<b>{{errorString}}</b>
|
||||
</p>
|
||||
{{/errorString}}
|
||||
|
||||
{{#isFinished}}
|
||||
<p>
|
||||
Done! <a href="https://stuff.718it.biz/torrents/{{name}}" target="_blank"> HTTP Link</a>
|
||||
</p>
|
||||
{{/isFinished}}
|
||||
<hr />
|
||||
</li>
|
||||
<li jq-repeat-defualt="tbp_proxy_torrent_dialog_torrents">
|
||||
<h3> No Torrents...</h3>
|
||||
<hr width="300pt" />
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
<!--
|
||||
Torrent Add Dialog
|
||||
Torrent Add Dialog
|
||||
-->
|
||||
<style type="text/css">
|
||||
#tbp_proxy_torrent_add_dialog_container{
|
||||
width: 32em;
|
||||
}
|
||||
#tbp_proxy_torrent_add_dialog_container{
|
||||
width: 32em;
|
||||
}
|
||||
|
||||
#tbp_proxy_torrent_add_dialog input[type="text"]{
|
||||
width: 90%;
|
||||
}
|
||||
#tbp_proxy_torrent_add_dialog label,legend{
|
||||
font-weight: bold;
|
||||
}
|
||||
#tbp_proxy_torrent_add_dialog input[type="text"]{
|
||||
width: 90%;
|
||||
}
|
||||
#tbp_proxy_torrent_add_dialog label,legend{
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<div id="tbp_proxy_torrent_add_dialog" title="Add torrent">
|
||||
<div id="tbp_proxy_torrent_add_dialog_container" class='card'>
|
||||
<div class="card-header shadow actionMessage" style="display:none"></div>
|
||||
<div jq-repeat="torrentAdd">
|
||||
<form action="torrent" method="post" onsubmit="formAJAX(this)" evalAJAX="
|
||||
app.publish('torrent:add', {...data, __noSocket: true});
|
||||
$('#tbp_proxy_torrent_add_dialog').dialog('close');
|
||||
openDialog($('#tbp_proxy_torrent_dialog'))
|
||||
">
|
||||
<p>
|
||||
<label for="_name">Name:</label>
|
||||
<br />
|
||||
<input type="text" name="_name" value="{{{name}}}" readonly/>
|
||||
</p>
|
||||
<div id="tbp_proxy_torrent_add_dialog_container" class='card'>
|
||||
<div class="card-header shadow actionMessage" style="display:none"></div>
|
||||
<div jq-repeat="torrentAdd">
|
||||
<form action="torrent" method="post" onsubmit="formAJAX(this)" evalAJAX="
|
||||
app.publish('torrent:add', {...data, __noSocket: true});
|
||||
$('#tbp_proxy_torrent_add_dialog').dialog('close');
|
||||
openDialog($('#tbp_proxy_torrent_dialog'))
|
||||
">
|
||||
<p>
|
||||
<label for="_name">Name:</label>
|
||||
<br />
|
||||
<input type="text" name="_name" value="{{{name}}}" readonly/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="magnetLink">Magnet Link:</label>
|
||||
<br />
|
||||
<input type="text" name="magnetLink" value="{{{magnetLink}}}" readonly/>
|
||||
</p>
|
||||
<p>
|
||||
<label for="magnetLink">Magnet Link:</label>
|
||||
<br />
|
||||
<input type="text" name="magnetLink" value="{{{magnetLink}}}" readonly/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<legend>Public Download:</legend>
|
||||
<p>
|
||||
<label for="hashString">Hash:</label>
|
||||
<br />
|
||||
<input type="text" name="hashString" value="{{{hashString}}}" readonly/>
|
||||
</p>
|
||||
|
||||
<label for="radio-1" title="The download will appare in the communal download folder">Public</label>
|
||||
<input type="radio" name="isPrivate" id="radio-1" value="true" checked readonly/>
|
||||
<p style="display:none">
|
||||
<legend>Public Download:</legend>
|
||||
|
||||
<label for="radio-2" title="Only you(and the admins) will be able to see this download">Private</label>
|
||||
<input type="radio" name="isPrivate" id="radio-2" value="false" readonly/>
|
||||
</p>
|
||||
<label for="radio-1" title="The download will appare in the communal download folder">Public</label>
|
||||
<input type="radio" name="isPrivate" id="radio-1" value="true" checked readonly/>
|
||||
|
||||
<p>
|
||||
<legend>Start on add:</legend>
|
||||
<label for="radio-2" title="Only you(and the admins) will be able to see this download">Private</label>
|
||||
<input type="radio" name="isPrivate" id="radio-2" value="false" readonly/>
|
||||
</p>
|
||||
|
||||
<label for="isStart-1" title="The download will appare in the communal download folder">Yes</label>
|
||||
<input type="radio" name="isStart" id="isStart-1" value="true" checked readonly/>
|
||||
<p style="display:none">
|
||||
<legend>Start on add:</legend>
|
||||
|
||||
<label for="isStart-2" title="Only you(and the admins) will be able to see this download">No</label>
|
||||
<input type="radio" name="isStart" id="isStart-2" value="false" readonly/>
|
||||
</p>
|
||||
<label for="isStart-1" title="The download will appare in the communal download folder">Yes</label>
|
||||
<input type="radio" name="isStart" id="isStart-1" value="true" checked readonly/>
|
||||
|
||||
<hr />
|
||||
<button type="submit">Start Download</button>
|
||||
<button onclick="$('#tbp_proxy_torrent_add_dialog').dialog('close')">Cancel</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<label for="isStart-2" title="Only you(and the admins) will be able to see this download">No</label>
|
||||
<input type="radio" name="isStart" id="isStart-2" value="false" readonly/>
|
||||
</p>
|
||||
|
||||
<hr />
|
||||
<button type="submit">Start Download</button>
|
||||
<button onclick="$('#tbp_proxy_torrent_add_dialog').dialog('close')">Cancel</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!--
|
||||
The bar injected at the top of the page
|
||||
The bar injected at the top of the page
|
||||
-->
|
||||
|
||||
<div id="tbp_proxy_header_right">
|
||||
<span id="tbp_proxy_torrent_dialog_opener" class="tbp_proxy_is_authed">
|
||||
<img src="/__static/img/Transmission_Icon.svg" height="22" width="22" style="margin-right: .3em;" />
|
||||
<span jq-repeat="tbp_proxy_torrent_dialog_opener_status">
|
||||
<b> <span class="ui-icon ui-icon-arrowthick-1-n"></span>{{downloadSpeed}} <span class="ui-icon ui-icon-arrowthick-1-s"></span>{{uploadSpeed}}</b>
|
||||
</span>
|
||||
</span>
|
||||
<button id="tbp_proxy_login_dialog_opener" class="tbp_proxy_not_authed ui-button ui-corner-all ui-widget">Login</button>
|
||||
<button class="tbp_proxy_is_authed ui-button ui-corner-all ui-widget"
|
||||
onclick="app.auth.logOut(e => window.location.href='/')">Logout</button>
|
||||
<span id="tbp_proxy_torrent_dialog_opener" class="tbp_proxy_is_authed">
|
||||
<img src="/__static/img/Transmission_Icon.svg" height="22" width="22" style="margin-right: .3em;" />
|
||||
<span jq-repeat="tbp_proxy_torrent_dialog_opener_status">
|
||||
<b> <span class="ui-icon ui-icon-arrowthick-1-s"></span>{{downloadSpeed}} <span class="ui-icon ui-icon-arrowthick-1-n"></span>{{uploadSpeed}}</b>
|
||||
</span>
|
||||
</span>
|
||||
<button id="tbp_proxy_login_dialog_opener" class="tbp_proxy_not_authed ui-button ui-corner-all ui-widget">Login</button>
|
||||
<button class="tbp_proxy_is_authed ui-button ui-corner-all ui-widget"
|
||||
onclick="app.auth.logOut(e => window.location.href='/')">Logout</button>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$( document ).ready(function() {
|
||||
var commonDialogOptions = {
|
||||
position: { my: "left top", at: "left bottom", of: '#tbp_proxy_header_right' },
|
||||
autoOpen: false,
|
||||
resizable: false,
|
||||
closeOnEscape: true,
|
||||
draggable: false,
|
||||
width: 'auto',
|
||||
};
|
||||
$( document ).ready(function() {
|
||||
var commonDialogOptions = {
|
||||
position: { my: "left top", at: "left bottom", of: '#tbp_proxy_header_right' },
|
||||
autoOpen: false,
|
||||
resizable: false,
|
||||
closeOnEscape: true,
|
||||
draggable: false,
|
||||
width: 'auto',
|
||||
};
|
||||
|
||||
/* Login Button and dialog*/
|
||||
$( "#tbp_proxy_login_dialog" ).dialog(commonDialogOptions);
|
||||
/* Login Button and dialog*/
|
||||
$( "#tbp_proxy_login_dialog" ).dialog(commonDialogOptions);
|
||||
|
||||
$( "#tbp_proxy_login_dialog_opener" ).on( "click", function() {
|
||||
// https://stackoverflow.com/a/6500385
|
||||
$( "#tbp_proxy_login_dialog" ).parent().css({position:"fixed", 'margin-right': "2em", 'margin-top': '3em'}).end().dialog( "open" );
|
||||
});
|
||||
$( "#tbp_proxy_login_dialog_opener" ).on( "click", function() {
|
||||
// https://stackoverflow.com/a/6500385
|
||||
$( "#tbp_proxy_login_dialog" ).parent().css({position:"fixed", 'margin-right': "2em", 'margin-top': '3em'}).end().dialog( "open" );
|
||||
});
|
||||
|
||||
|
||||
/* Torrent list button and dialog */
|
||||
$( "#tbp_proxy_torrent_dialog" ).dialog(commonDialogOptions);
|
||||
/* Torrent list button and dialog */
|
||||
$( "#tbp_proxy_torrent_dialog" ).dialog(commonDialogOptions);
|
||||
|
||||
$( "#tbp_proxy_torrent_dialog_opener" ).on( "click", function() {
|
||||
$( "#tbp_proxy_torrent_dialog" ).parent().css({position:"fixed", 'margin-right': "2em", 'margin-top': '3em'}).end().dialog( "open" );
|
||||
});
|
||||
$( "#tbp_proxy_torrent_dialog_opener" ).on( "click", function() {
|
||||
$( "#tbp_proxy_torrent_dialog" ).parent().css({position:"fixed", 'margin-right': "2em", 'margin-top': '3em'}).end().dialog( "open" );
|
||||
});
|
||||
|
||||
|
||||
/* Torrent add button and dialog */
|
||||
$( "#tbp_proxy_torrent_add_dialog" ).dialog({
|
||||
modal: true,
|
||||
height: 300,
|
||||
...commonDialogOptions
|
||||
});
|
||||
|
||||
$("body").on('click', 'img.718link', function(el){
|
||||
// magnetLink
|
||||
$.scope.torrentAdd.update({
|
||||
magnetLink: $(this).data('link'),
|
||||
name: (new URLSearchParams($(this).data('link'))).get('dn')
|
||||
});
|
||||
$('#tbp_proxy_torrent_add_dialog').parent().css({position:"fixed", 'margin-right': "2em", 'margin-top': '3em'}).end().dialog('open');
|
||||
});
|
||||
|
||||
$('a').each(function(idx, el){
|
||||
var $el = $(el);
|
||||
if($el.attr('href') && $el.attr('href').match("magnet:?")){
|
||||
$el.before('<img class="tbp_proxy_is_authed 718link" src="/__static/img/Transmission_Icon.svg" height=24 width=24 data-link="'+$el.attr('href')+'"/>')
|
||||
}
|
||||
});
|
||||
|
||||
/* Enable tooltips*/
|
||||
$( '#tbp_proxy_header' ).tooltip({
|
||||
track: true
|
||||
});
|
||||
|
||||
app.subscribe('torrent:add', function(data, topic){
|
||||
console.log('sub', topic, data)
|
||||
$.scope.tbp_proxy_torrent_dialog_torrents.unshift(app.torrent.parseTorrnetItem(data))
|
||||
});
|
||||
|
||||
app.subscribe('torrent:server:status', function(data, topic){
|
||||
app.torrent.isDown = false
|
||||
$('#tbp_proxy_torrent_dialog_opener').css('background', "lightseagreen")
|
||||
$.scope.tbp_proxy_torrent_dialog_opener_status.update(app.torrent.parseServerStatus(data));
|
||||
});
|
||||
|
||||
app.subscribe(`app:api:error:555`, function(data, topics){
|
||||
console.log('we down')
|
||||
app.torrent.isDown = true
|
||||
$('#tbp_proxy_torrent_dialog_opener').css('background', "red")
|
||||
});
|
||||
|
||||
app.subscribe('torrent:server:status:down', function(data, topic){
|
||||
app.torrent.isDown = true
|
||||
$('#tbp_proxy_torrent_dialog_opener').css('background', "red")
|
||||
});
|
||||
|
||||
listTorrents();
|
||||
setInterval(refreshTorrents, 5000)
|
||||
});
|
||||
|
||||
function humanFileSize(size) {
|
||||
var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
|
||||
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
|
||||
}
|
||||
|
||||
function openDialog($el){
|
||||
$el.parent().css({
|
||||
position:"fixed", 'margin-right': "2em", 'margin-top': '3em'
|
||||
}).end().dialog('open');
|
||||
}
|
||||
|
||||
function listTorrents(){
|
||||
app.torrent.list(function(err, data){
|
||||
for(let torrent of data.results){
|
||||
$.scope.tbp_proxy_torrent_dialog_torrents.unshift(app.torrent.parseTorrnetItem(torrent))
|
||||
app.torrent.get(function(error, torrent){
|
||||
$.scope.tbp_proxy_torrent_dialog_torrents.update('id', torrent.result.id, app.torrent.parseTorrnetItem(torrent.result))
|
||||
} , torrent.id, true)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function refreshTorrents(){
|
||||
for(let torrent of $.scope.tbp_proxy_torrent_dialog_torrents){
|
||||
if(!torrent.isFinished){
|
||||
app.torrent.get(function(error, torrent){
|
||||
$.scope.tbp_proxy_torrent_dialog_torrents.update('id', torrent.result.id, app.torrent.parseTorrnetItem(torrent.result))
|
||||
} , torrent.id, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
app.torrent = (function(app){
|
||||
let isDown = false;
|
||||
|
||||
$( document ).on( "ajaxSend", function(event, ajax, res, ...args) {
|
||||
console.log('right?', res.url, res.url.startsWith('/__api/torrent'), app.torrent.isDown)
|
||||
if(res.url.startsWith('/__api/torrent') && isDown){
|
||||
ajax.abort()
|
||||
}
|
||||
// $( ".log" ).text( "Triggered ajaxStart handler." );
|
||||
// throw new Error('go')
|
||||
} );
|
||||
|
||||
statusMap = [
|
||||
'Inactive', // 0
|
||||
'CHECK_WAIT', // 1
|
||||
'Verifying', // 2
|
||||
'DOWNLOAD_WAIT', // 3
|
||||
'Downloading', // 4
|
||||
'SEED_WAIT', // 5
|
||||
'Seeding', // 6
|
||||
'ISOLATED', // 7
|
||||
'Unknown', // 8
|
||||
];
|
||||
/* Torrent add button and dialog */
|
||||
$( "#tbp_proxy_torrent_add_dialog" ).dialog({
|
||||
modal: true,
|
||||
height: 300,
|
||||
...commonDialogOptions
|
||||
});
|
||||
|
||||
|
||||
function list(callback, username) {
|
||||
app.api.get('torrent', function(error, data){
|
||||
if(error) return;
|
||||
callback(null, data)
|
||||
});
|
||||
}
|
||||
/* Enable tooltips*/
|
||||
$( '#tbp_proxy_header' ).tooltip({
|
||||
track: true
|
||||
});
|
||||
|
||||
function get(callback, id, forceUpdate){
|
||||
app.api.get(`torrent/${id}?${forceUpdate ? 'latest': '' }`, function(error, data){
|
||||
if(error) return;
|
||||
callback(null, data)
|
||||
});
|
||||
}
|
||||
app.auth.isLoggedIn(function(error, data){
|
||||
if(data){
|
||||
|
||||
function start(id, callback){
|
||||
app.api.post(`torrent/${id}/start`, function(error, data){
|
||||
if(error) return;
|
||||
callback(null, data)
|
||||
});
|
||||
}
|
||||
$("body").on('click', 'img.718link', function(el){
|
||||
// magnetLink
|
||||
let magnetLinkParams = new URLSearchParams($(this).data('link'));
|
||||
|
||||
function stop(id, callback){
|
||||
app.api.post(`torrent/${id}/stop`, function(error, data){
|
||||
if(error) return;
|
||||
callback(null, data)
|
||||
});
|
||||
}
|
||||
$.scope.torrentAdd.update({
|
||||
magnetLink: $(this).data('link'),
|
||||
name: magnetLinkParams.get('dn'),
|
||||
hashString: magnetLinkParams.get('magnet:?xt').split(':').pop().toLowerCase(),
|
||||
});
|
||||
|
||||
function destroy(id, callback){
|
||||
app.api.delete(`torrent/${id}`, function(error, data){
|
||||
if(error) return;
|
||||
callback(null, data)
|
||||
});
|
||||
}
|
||||
$('#tbp_proxy_torrent_add_dialog').parent().css({position:"fixed", 'margin-right': "2em", 'margin-top': '3em'}).end().dialog('open');
|
||||
});
|
||||
|
||||
// Look for
|
||||
$('a').each(function(idx, el){
|
||||
var $el = $(el);
|
||||
if($el.attr('href') && $el.attr('href').match("magnet:?")){
|
||||
$el.replaceWith('<img class="tbp_proxy_is_authed 718link" src="/__static/img/Transmission_Icon.svg" height=24 width=24 data-link="'+$el.attr('href')+'"/>')
|
||||
}
|
||||
});
|
||||
|
||||
function parseServerStatus(data){
|
||||
return {
|
||||
...data,
|
||||
"downloadSpeed": humanFileSize(data.downloadSpeed)+'/s',
|
||||
"uploadSpeed": humanFileSize(data.uploadSpeed)+'/s',
|
||||
/* "activeTorrentCount": 11,
|
||||
"cumulative-stats": {
|
||||
"downloadedBytes": 2925927098021,
|
||||
"filesAdded": 80609,
|
||||
"secondsActive": 12136579,
|
||||
"sessionCount": 21,
|
||||
"uploadedBytes": 107123787853
|
||||
},
|
||||
"current-stats": {
|
||||
"downloadedBytes": 48440590262,
|
||||
"filesAdded": 544,
|
||||
"secondsActive": 111907,
|
||||
"sessionCount": 1,
|
||||
"uploadedBytes": 461874022
|
||||
},
|
||||
"pausedTorrentCount": 462,
|
||||
"torrentCount": 473,
|
||||
"__noSocket": true*/
|
||||
}
|
||||
}
|
||||
app.subscribe('torrent:add', function(data, topic){
|
||||
$.scope.tbp_proxy_torrent_dialog_torrents.unshift(app.torrent.parseTorrnetItem(data))
|
||||
});
|
||||
|
||||
function parseTorrnetItem(torrent){
|
||||
let percentDone = (torrent.percentDone || 0)*100;
|
||||
return {
|
||||
...torrent,
|
||||
"eta": torrent.eta > 0 ? moment().seconds(torrent.eta).fromNow() : 'Unknown',
|
||||
"rateDownload": `${humanFileSize(torrent.rateDownload)}/s`,
|
||||
"sizeWhenDone": humanFileSize(torrent.sizeWhenDone),
|
||||
"percentDone": percentDone,
|
||||
"statusText": statusMap[torrent.status],
|
||||
"isActive": [3, 4, 5, 6].includes(torrent.status), // DOWNLOAD_WAIT ,DOWNLOAD, SEED_WAIT, SEED
|
||||
"isFinished": torrent.isFinished || percentDone === 100,
|
||||
"createdAtString": moment(torrent.createdAt).fromNow(),
|
||||
|
||||
// "isFinished": false,
|
||||
// "isStalled": false,
|
||||
// "name": "reacher.s02e06.1080p.web.h264-successfulcrab[EZTVx.to].mkv",
|
||||
// "hashString": "4794a0915cada6c491eb5c910e1f4a0da727cac8",
|
||||
// "status": 4,
|
||||
// "id": 1,
|
||||
app.subscribe('torrent:server:status', function(data, topic){
|
||||
app.torrent.isDown = false
|
||||
$('#tbp_proxy_torrent_dialog_opener').css('background', "lightseagreen")
|
||||
$.scope.tbp_proxy_torrent_dialog_opener_status.update(app.torrent.parseServerStatus(data));
|
||||
});
|
||||
|
||||
// "peersConnected": 50,
|
||||
// "added_by": "wmantly",
|
||||
// "errorString": "",
|
||||
app.subscribe(`app:api:error:555`, function(data, topics){
|
||||
app.torrent.isDown = true
|
||||
$('#tbp_proxy_torrent_dialog_opener').css('background', "red")
|
||||
});
|
||||
|
||||
// "downloadDir": "/media/torrents",
|
||||
// "files": [],
|
||||
// "peers": [],
|
||||
// "magnetLink": "magnet:?xt=urn:btih:4794A0915CADA6C491EB5C910E1F4A0DA727CAC8&dn=Reacher+S02E06+1080p+WEB+H264-SuccessfulCrab&tr=http%3A%2F%2Fp4p.arenabg.com%3A1337%2Fannounce&tr=udp%3A%2F%2F47.ip-51-68-199.eu%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2780%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2710%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2730%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2920%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.cyberia.is%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.dler.org%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=udp%3A%2F%2Ftracker.pirateparty.gr%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.tiny-vps.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce",
|
||||
// "isPrivate": false,
|
||||
// "createdAt": "2024-01-05T21:18:30.607Z",
|
||||
// "updatedAt": "2024-01-05T21:32:54.493Z"
|
||||
// "torrent_id": "454",
|
||||
}
|
||||
}
|
||||
app.subscribe('torrent:server:status:down', function(data, topic){
|
||||
app.torrent.isDown = true
|
||||
$('#tbp_proxy_torrent_dialog_opener').css('background', "red")
|
||||
});
|
||||
|
||||
return {list, get, start, stop, destroy, parseTorrnetItem, parseServerStatus, isDown};
|
||||
})(app);
|
||||
listTorrents();
|
||||
setInterval(refreshTorrents, 5000);
|
||||
app.torrent.migrate();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function humanFileSize(size) {
|
||||
var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
|
||||
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
|
||||
}
|
||||
|
||||
function openDialog($el){
|
||||
$el.parent().css({
|
||||
position:"fixed", 'margin-right': "2em", 'margin-top': '3em'
|
||||
}).end().dialog('open');
|
||||
}
|
||||
|
||||
function listTorrents(){
|
||||
app.torrent.list(function(err, data){
|
||||
for(let torrent of data.results){
|
||||
$.scope.tbp_proxy_torrent_dialog_torrents.push(app.torrent.parseTorrnetItem(torrent))
|
||||
app.torrent.get(function(error, torrent){
|
||||
$.scope.tbp_proxy_torrent_dialog_torrents.update('hashString', torrent.result.hashString, app.torrent.parseTorrnetItem(torrent.result))
|
||||
} , torrent.hashString, true)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function refreshTorrents(){
|
||||
for(let torrent of $.scope.tbp_proxy_torrent_dialog_torrents){
|
||||
if(!torrent.isFinished){
|
||||
app.torrent.get(function(error, torrent){
|
||||
$.scope.tbp_proxy_torrent_dialog_torrents.update('hashString', torrent.result.hashString, app.torrent.parseTorrnetItem(torrent.result))
|
||||
} , torrent.hashString, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
app.torrent = (function(app){
|
||||
let isDown = false;
|
||||
|
||||
// Dont spam the server if its not online
|
||||
$( document ).on( "ajaxSend", function(event, ajax, res, ...args) {
|
||||
if(res.url.startsWith('/__api/torrent') && isDown){
|
||||
ajax.abort()
|
||||
}
|
||||
} );
|
||||
|
||||
statusMap = [
|
||||
'Inactive', // 0
|
||||
'CHECK_WAIT', // 1
|
||||
'Verifying', // 2
|
||||
'DOWNLOAD_WAIT', // 3
|
||||
'Downloading', // 4
|
||||
'SEED_WAIT', // 5
|
||||
'Seeding', // 6
|
||||
'ISOLATED', // 7
|
||||
'Unknown', // 8
|
||||
];
|
||||
|
||||
function list(callback, username) {
|
||||
app.api.get('torrent', function(error, data){
|
||||
if(error) return;
|
||||
callback(null, data)
|
||||
});
|
||||
}
|
||||
|
||||
function get(callback, hashString, forceUpdate){
|
||||
app.api.get(`torrent/${hashString}?${forceUpdate ? 'latest': '' }`, function(error, data){
|
||||
if(error) return;
|
||||
callback(null, data)
|
||||
});
|
||||
}
|
||||
|
||||
function start(hashString, callback){
|
||||
app.api.post(`torrent/${hashString}/start`, function(error, data){
|
||||
if(error) return;
|
||||
callback(null, data)
|
||||
});
|
||||
}
|
||||
|
||||
function stop(hashString, callback){
|
||||
app.api.post(`torrent/${hashString}/stop`, function(error, data){
|
||||
if(error) return;
|
||||
callback(null, data)
|
||||
});
|
||||
}
|
||||
|
||||
function destroy(hashString, callback){
|
||||
app.api.delete(`torrent/${hashString}`, function(error, data){
|
||||
if(error) return;
|
||||
callback(null, data)
|
||||
});
|
||||
}
|
||||
|
||||
function parseServerStatus(data){
|
||||
return {
|
||||
...data,
|
||||
"downloadSpeed": humanFileSize(data.downloadSpeed)+'/s',
|
||||
"uploadSpeed": humanFileSize(data.uploadSpeed)+'/s',
|
||||
/* "activeTorrentCount": 11,
|
||||
"cumulative-stats": {
|
||||
"downloadedBytes": 2925927098021,
|
||||
"filesAdded": 80609,
|
||||
"secondsActive": 12136579,
|
||||
"sessionCount": 21,
|
||||
"uploadedBytes": 107123787853
|
||||
},
|
||||
"current-stats": {
|
||||
"downloadedBytes": 48440590262,
|
||||
"filesAdded": 544,
|
||||
"secondsActive": 111907,
|
||||
"sessionCount": 1,
|
||||
"uploadedBytes": 461874022
|
||||
},
|
||||
"pausedTorrentCount": 462,
|
||||
"torrentCount": 473,
|
||||
"__noSocket": true*/
|
||||
}
|
||||
}
|
||||
|
||||
function parseTorrnetItem(torrent){
|
||||
let percentDone = (torrent.percentDone || 0)*100;
|
||||
return {
|
||||
...torrent,
|
||||
"eta": torrent.eta > 0 ? moment().seconds(torrent.eta).fromNow() : 'Unknown',
|
||||
"rateDownload": `${humanFileSize(torrent.rateDownload)}/s`,
|
||||
"sizeWhenDone": humanFileSize(torrent.sizeWhenDone),
|
||||
"percentDone": percentDone,
|
||||
"statusText": statusMap[torrent.status],
|
||||
"isActive": [3, 4, 5, 6].includes(torrent.status), // DOWNLOAD_WAIT ,DOWNLOAD, SEED_WAIT, SEED
|
||||
"isFinished": torrent.isFinished || percentDone === 100,
|
||||
"createdAtString": moment(torrent.createdAt).fromNow(),
|
||||
|
||||
// "createdAt": "2024-01-05T21:18:30.607Z",
|
||||
// "isFinished": false,
|
||||
// "isStalled": false,
|
||||
// "name": "reacher.s02e06.1080p.web.h264-successfulcrab[EZTVx.to].mkv",
|
||||
// "hashString": "4794a0915cada6c491eb5c910e1f4a0da727cac8",
|
||||
// "status": 4,
|
||||
// "id": 1,
|
||||
|
||||
// "peersConnected": 50,
|
||||
// "added_by": "wmantly",
|
||||
// "errorString": "",
|
||||
|
||||
// "downloadDir": "/media/torrents",
|
||||
// "files": [],
|
||||
// "peers": [],
|
||||
// "magnetLink": "magnet:?xt=urn:btih:4794A0915CADA6C491EB5C910E1F4A0DA727CAC8&dn=Reacher+S02E06+1080p+WEB+H264-SuccessfulCrab&tr=http%3A%2F%2Fp4p.arenabg.com%3A1337%2Fannounce&tr=udp%3A%2F%2F47.ip-51-68-199.eu%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2780%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2710%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2730%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2920%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.cyberia.is%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.dler.org%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=udp%3A%2F%2Ftracker.pirateparty.gr%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.tiny-vps.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce",
|
||||
// "isPrivate": false,
|
||||
// "updatedAt": "2024-01-05T21:32:54.493Z"
|
||||
// "torrent_id": "454",
|
||||
}
|
||||
}
|
||||
|
||||
function migrate(){
|
||||
let torrents = JSON.parse(window.localStorage.getItem('torrents') || '{}' ).list || [];
|
||||
|
||||
if(torrents.length){
|
||||
console.log(`Migrating ${torrents.length}`)
|
||||
for(let torrent of torrents){
|
||||
app.api.post(`torrent/${torrent.hashString}`, {}, function(error, torrent) {
|
||||
if(Object.keys(torrent).length){
|
||||
$.scope.tbp_proxy_torrent_dialog_torrents.unshift(app.torrent.parseTorrnetItem(torrent))
|
||||
}
|
||||
});
|
||||
}
|
||||
localStorage.clear('torrents');
|
||||
}
|
||||
}
|
||||
|
||||
return {list, get, start, stop, destroy, migrate, parseTorrnetItem, parseServerStatus, isDown};
|
||||
})(app);
|
||||
|
||||
</script>
|
||||
|
@ -8,7 +8,10 @@ router.get('/', async function(req, res, next){
|
||||
res.json({results: await Torrent.findAll({
|
||||
where:{added_by: req.query.username || req.user.username},
|
||||
limit: req.query.limit,
|
||||
offset: req.query.offset
|
||||
offset: req.query.offset,
|
||||
order: [
|
||||
['createdAt', 'DESC'],
|
||||
],
|
||||
})});
|
||||
}catch(error){
|
||||
next(error);
|
||||
@ -23,6 +26,14 @@ router.post("/", async function(req, res, next){
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/:hashString", async function(req, res, next){
|
||||
try{
|
||||
res.json(await Torrent.migrate(req.params.hashString, req.user.username))
|
||||
}catch(error){
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/server', async function(req, res, next){
|
||||
try{
|
||||
res.json(await Torrent.trClient.sessionStats())
|
||||
@ -31,9 +42,9 @@ router.get('/server', async function(req, res, next){
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/:id", async function(req, res, next){
|
||||
router.get("/:hashString", async function(req, res, next){
|
||||
try{
|
||||
let torrent = await Torrent.findByPk(req.params.id);
|
||||
let torrent = await Torrent.findByPk(req.params.hashString);
|
||||
if('latest' in req.query){
|
||||
torrent = await torrent.getTorrentData();
|
||||
}
|
||||
@ -43,9 +54,9 @@ router.get("/:id", async function(req, res, next){
|
||||
}
|
||||
});
|
||||
|
||||
router.delete("/:id", async function(req, res, next){
|
||||
router.delete("/:hashString", async function(req, res, next){
|
||||
try{
|
||||
let torrent = await Torrent.findByPk(req.params.id);
|
||||
let torrent = await Torrent.findByPk(req.params.hashString);
|
||||
|
||||
res.json({result: torrent, activity: await torrent.destroy()});
|
||||
}catch(error){
|
||||
@ -53,9 +64,9 @@ router.delete("/:id", async function(req, res, next){
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/:id/stop", async function(req, res, next){
|
||||
router.post("/:hashString/stop", async function(req, res, next){
|
||||
try{
|
||||
let torrent = await Torrent.findByPk(req.params.id);
|
||||
let torrent = await Torrent.findByPk(req.params.hashString);
|
||||
|
||||
res.json({result: torrent, activity: await torrent.stop()});
|
||||
}catch(error){
|
||||
@ -63,9 +74,9 @@ router.post("/:id/stop", async function(req, res, next){
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/:id/start", async function(req, res, next){
|
||||
router.post("/:hashString/start", async function(req, res, next){
|
||||
try{
|
||||
let torrent = await Torrent.findByPk(req.params.id);
|
||||
let torrent = await Torrent.findByPk(req.params.hashString);
|
||||
|
||||
res.json({result: torrent, activity: await torrent.start()});
|
||||
}catch(error){
|
||||
|
Loading…
x
Reference in New Issue
Block a user