Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
fa5b7a3249 | |||
60f65152cb | |||
d34b74e505 | |||
600173c959 | |||
49fd73aaf9 | |||
ffa0f07daf | |||
dc9f73961e | |||
bbcd955f28 | |||
c6cc529d54 | |||
a4094cb795 | |||
1c7e2e794e |
2
app.js
2
app.js
@ -39,7 +39,7 @@ app.onListen.push(function(){
|
|||||||
|
|
||||||
app.contollers.pubsub.subscribe(/./g, function(data, topic){
|
app.contollers.pubsub.subscribe(/./g, function(data, topic){
|
||||||
app.io.emit('P2PSub', { topic, data });
|
app.io.emit('P2PSub', { topic, data });
|
||||||
});
|
});
|
||||||
|
|
||||||
app.io.on('connection', (socket) => {
|
app.io.on('connection', (socket) => {
|
||||||
// console.log('socket', socket)
|
// console.log('socket', socket)
|
||||||
|
@ -11,10 +11,6 @@ var userLUR = new LRUCache({
|
|||||||
maxAge: 60000,
|
maxAge: 60000,
|
||||||
});
|
});
|
||||||
|
|
||||||
const client = new Client({
|
|
||||||
url: conf.url,
|
|
||||||
});
|
|
||||||
|
|
||||||
const user_parse = function(data){
|
const user_parse = function(data){
|
||||||
if(data[conf.userNameAttribute]){
|
if(data[conf.userNameAttribute]){
|
||||||
data.username = data[conf.userNameAttribute];
|
data.username = data[conf.userNameAttribute];
|
||||||
@ -31,6 +27,10 @@ User.backing = "LDAP";
|
|||||||
|
|
||||||
User.list = async function(){
|
User.list = async function(){
|
||||||
try{
|
try{
|
||||||
|
const client = new Client({
|
||||||
|
url: conf.url,
|
||||||
|
});
|
||||||
|
|
||||||
await client.bind(conf.bindDN, conf.bindPassword);
|
await client.bind(conf.bindDN, conf.bindPassword);
|
||||||
|
|
||||||
const res = await client.search(conf.userBase, {
|
const res = await client.search(conf.userBase, {
|
||||||
@ -49,6 +49,10 @@ User.list = async function(){
|
|||||||
|
|
||||||
User.listDetail = async function(){
|
User.listDetail = async function(){
|
||||||
try{
|
try{
|
||||||
|
const client = new Client({
|
||||||
|
url: conf.url,
|
||||||
|
});
|
||||||
|
|
||||||
await client.bind(conf.bindDN, conf.bindPassword);
|
await client.bind(conf.bindDN, conf.bindPassword);
|
||||||
|
|
||||||
const res = await client.search(conf.userBase, {
|
const res = await client.search(conf.userBase, {
|
||||||
@ -86,7 +90,11 @@ User.get = async function(data, key){
|
|||||||
data.searchValue = data.searchValue || data.uid;
|
data.searchValue = data.searchValue || data.uid;
|
||||||
|
|
||||||
let filter = `(&${conf.userFilter}(${data.searchKey}=${data.searchValue}))`;
|
let filter = `(&${conf.userFilter}(${data.searchKey}=${data.searchValue}))`;
|
||||||
if(userLUR.get(filter)) return userLUR.get(filter)
|
if(userLUR.get(filter)) return userLUR.get(filter);
|
||||||
|
|
||||||
|
const client = new Client({
|
||||||
|
url: conf.url,
|
||||||
|
});
|
||||||
|
|
||||||
await client.bind(conf.bindDN, conf.bindPassword);
|
await client.bind(conf.bindDN, conf.bindPassword);
|
||||||
const res = await client.search(conf.userBase, {
|
const res = await client.search(conf.userBase, {
|
||||||
@ -131,6 +139,10 @@ User.login = async function(data){
|
|||||||
|
|
||||||
let user = await this.get(data.uid || data[conf.userNameAttribute] || data.username);
|
let user = await this.get(data.uid || data[conf.userNameAttribute] || data.username);
|
||||||
|
|
||||||
|
const client = new Client({
|
||||||
|
url: conf.url,
|
||||||
|
});
|
||||||
|
|
||||||
await client.bind(user.dn, data.password);
|
await client.bind(user.dn, data.password);
|
||||||
|
|
||||||
await client.unbind();
|
await client.unbind();
|
||||||
|
@ -3,13 +3,9 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
async up(queryInterface, Sequelize) {
|
async up(queryInterface, Sequelize) {
|
||||||
await queryInterface.createTable('Torrents', {
|
await queryInterface.createTable('Torrents', {
|
||||||
id: {
|
|
||||||
allowNull: false,
|
|
||||||
autoIncrement: true,
|
|
||||||
primaryKey: true,
|
|
||||||
type: Sequelize.INTEGER
|
|
||||||
},
|
|
||||||
hashString: {
|
hashString: {
|
||||||
|
primaryKey: true,
|
||||||
|
allowNull: false,
|
||||||
type: Sequelize.STRING
|
type: Sequelize.STRING
|
||||||
},
|
},
|
||||||
magnetLink: {
|
magnetLink: {
|
||||||
|
@ -53,12 +53,21 @@ module.exports = (sequelize, DataTypes, Model) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTorrentData(noUpdate){
|
static async migrate(hashString, username){
|
||||||
try{
|
try{
|
||||||
let res = ( await tr_client.get(this.hashString, [
|
let exists = await this.findByPk(hashString);
|
||||||
"eta", "percentDone", "status", "rateDownload",
|
|
||||||
|
if(exists){
|
||||||
|
console.log('torrent in DB, skipping')
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
|
let res = ( await tr_client.get(hashString, [
|
||||||
|
"eta", "percentDone", "status", "rateDownload",
|
||||||
"errorString", "hashString", 'name',
|
"errorString", "hashString", 'name',
|
||||||
'downloadDir',
|
'downloadDir',
|
||||||
|
'addedDate',
|
||||||
|
'magnetLink',
|
||||||
'files', //array of files
|
'files', //array of files
|
||||||
'filesStats', // array of files with status
|
'filesStats', // array of files with status
|
||||||
'isFinished',
|
'isFinished',
|
||||||
@ -68,9 +77,38 @@ module.exports = (sequelize, DataTypes, Model) => {
|
|||||||
'sizeWhenDone',
|
'sizeWhenDone',
|
||||||
]) ).torrents[0];
|
]) ).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{
|
||||||
|
|
||||||
if(this.percentDone === 1) return this.dataValues
|
if(this.percentDone === 1) return this.dataValues
|
||||||
|
|
||||||
|
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',
|
||||||
|
'isStalled',
|
||||||
|
'peers',
|
||||||
|
'peersConnected', // array of peers,
|
||||||
|
'sizeWhenDone',
|
||||||
|
]) ).torrents[0];
|
||||||
|
|
||||||
await this.update(res);
|
await this.update(res);
|
||||||
if(noUpdate) await this.save();
|
if(noUpdate) await this.save();
|
||||||
|
|
||||||
return {...res, ...this.dataValues};
|
return {...res, ...this.dataValues};
|
||||||
}catch(error){
|
}catch(error){
|
||||||
if(error.code === 'ECONNREFUSED'){
|
if(error.code === 'ECONNREFUSED'){
|
||||||
@ -100,6 +138,11 @@ module.exports = (sequelize, DataTypes, Model) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Torrent.init({
|
Torrent.init({
|
||||||
|
hashString: {
|
||||||
|
type: DataTypes.STRING,
|
||||||
|
allowNull: false,
|
||||||
|
primaryKey: true
|
||||||
|
},
|
||||||
magnetLink: {
|
magnetLink: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
@ -112,7 +155,6 @@ module.exports = (sequelize, DataTypes, Model) => {
|
|||||||
type: DataTypes.BOOLEAN,
|
type: DataTypes.BOOLEAN,
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
},
|
},
|
||||||
hashString: DataTypes.STRING,
|
|
||||||
name: DataTypes.STRING,
|
name: DataTypes.STRING,
|
||||||
added_by: {
|
added_by: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
@ -137,6 +179,9 @@ module.exports = (sequelize, DataTypes, Model) => {
|
|||||||
type: DataTypes.NUMBER,
|
type: DataTypes.NUMBER,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
},
|
},
|
||||||
|
createdAt: {
|
||||||
|
type: DataTypes.DATE
|
||||||
|
},
|
||||||
}, {
|
}, {
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'Torrent',
|
modelName: 'Torrent',
|
||||||
|
445
public/js/app.js
445
public/js/app.js
@ -1,56 +1,419 @@
|
|||||||
// socket
|
var app = {};
|
||||||
|
|
||||||
// api
|
app.pubsub = (function(){
|
||||||
|
app.topics = {};
|
||||||
|
|
||||||
// auth
|
app.subscribe = function(topic, listener) {
|
||||||
|
if(topic instanceof RegExp){
|
||||||
|
listener.match = topic;
|
||||||
|
topic = "__REGEX__";
|
||||||
|
}
|
||||||
|
|
||||||
// user
|
// create the topic if not yet created
|
||||||
|
if(!app.topics[topic]) app.topics[topic] = [];
|
||||||
|
|
||||||
// group
|
// add the listener
|
||||||
|
app.topics[topic].push(listener);
|
||||||
|
}
|
||||||
|
|
||||||
"use strict";
|
app.matchTopics = function(topic){
|
||||||
/* globals jQuery, Mustache, XRegExp, $, app */
|
topic = topic || '';
|
||||||
var app = app || {};
|
var matches = [... app.topics[topic] ? app.topics[topic] : []];
|
||||||
|
|
||||||
( function($){
|
if(!app.topics['__REGEX__']) return matches;
|
||||||
|
|
||||||
/*
|
for(var listener of app.topics['__REGEX__']){
|
||||||
delay calling document.ready until app is loaded.
|
if(topic.match(listener.match)) matches.push(listener);
|
||||||
*/
|
}
|
||||||
jQuery.holdReady(true);
|
|
||||||
|
|
||||||
app.includeScrip = function(path, base){
|
return matches;
|
||||||
path = (base || JQapp_BASE_PATH || '') + path;
|
}
|
||||||
|
|
||||||
jQuery.ajax({
|
app.publish = function(topic, data) {
|
||||||
url: path,
|
|
||||||
dataType: 'script',
|
// send the event to all listeners
|
||||||
async: false
|
app.matchTopics(topic).forEach(function(listener) {
|
||||||
|
setTimeout(function(data, topic){
|
||||||
|
listener(data || {}, topic);
|
||||||
|
}, 0, data, topic);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
app.include = function(scripts, base){
|
return this;
|
||||||
scripts = $.isArray(scripts) ? scripts : [scripts];
|
})(app);
|
||||||
for(let script of scripts){
|
|
||||||
app.includeScrip(script, base)
|
app.socket = (function(app){
|
||||||
|
// $.getScript('/socket.io/socket.io.js')
|
||||||
|
// <script type="text/javascript" src="/socket.io/socket.io.js"></script>
|
||||||
|
|
||||||
|
var socket;
|
||||||
|
$(document).ready(function(){
|
||||||
|
socket = io({
|
||||||
|
auth: {
|
||||||
|
token: app.auth.getToken()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// socket.emit('chat message', $('#m').val());
|
||||||
|
socket.on('P2PSub', function(msg){
|
||||||
|
msg.data.__noSocket = true;
|
||||||
|
app.publish(msg.topic, msg.data);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.subscribe(/./g, function(data, topic){
|
||||||
|
// console.log('local_pubs', data, topic)
|
||||||
|
if(data.__noSocket) return;
|
||||||
|
// console.log('local_pubs 2', data, topic)
|
||||||
|
|
||||||
|
socket.emit('P2PSub', { topic, data });
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
return socket;
|
||||||
|
|
||||||
|
})(app);
|
||||||
|
|
||||||
|
app.api = (function(app){
|
||||||
|
var baseURL = '/__api/'
|
||||||
|
|
||||||
|
|
||||||
|
$( document ).on( "ajaxError", function(event, res, req) {
|
||||||
|
console.log('bad!', `app:api:error:`, res.status);
|
||||||
|
app.publish(`app:api:error:${res.status}`, {res, res});
|
||||||
|
} );
|
||||||
|
|
||||||
|
function post(url, data, callback){
|
||||||
|
callback = callback || app.util.emptyFuction;
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: baseURL+url,
|
||||||
|
headers:{
|
||||||
|
'auth-token': app.auth.getToken()
|
||||||
|
},
|
||||||
|
data: JSON.stringify(data),
|
||||||
|
contentType: "application/json; charset=utf-8",
|
||||||
|
dataType: "json",
|
||||||
|
complete: function(res, text){
|
||||||
|
callback(
|
||||||
|
text !== 'success' ? res.statusText : null,
|
||||||
|
JSON.parse(res.responseText),
|
||||||
|
res.status
|
||||||
|
)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function put(url, data, callback){
|
||||||
|
$.ajax({
|
||||||
|
type: 'PUT',
|
||||||
|
url: baseURL+url,
|
||||||
|
headers:{
|
||||||
|
'auth-token': app.auth.getToken()
|
||||||
|
},
|
||||||
|
data: JSON.stringify(data),
|
||||||
|
contentType: "application/json; charset=utf-8",
|
||||||
|
dataType: "json",
|
||||||
|
complete: function(res, text){
|
||||||
|
callback(
|
||||||
|
text !== 'success' ? res.statusText : null,
|
||||||
|
JSON.parse(res.responseText),
|
||||||
|
res.status
|
||||||
|
)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove(url, callback, callback2){
|
||||||
|
if(!$.isFunction(callback)) callback = callback2;
|
||||||
|
$.ajax({
|
||||||
|
type: 'delete',
|
||||||
|
url: baseURL+url,
|
||||||
|
headers:{
|
||||||
|
'auth-token': app.auth.getToken()
|
||||||
|
},
|
||||||
|
contentType: "application/json; charset=utf-8",
|
||||||
|
dataType: "json",
|
||||||
|
complete: function(res, text){
|
||||||
|
callback(
|
||||||
|
text !== 'success' ? res.statusText : null,
|
||||||
|
JSON.parse(res.responseText),
|
||||||
|
res.status
|
||||||
|
)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function get(url, callback){
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: baseURL+url,
|
||||||
|
headers:{
|
||||||
|
'auth-token': app.auth.getToken()
|
||||||
|
},
|
||||||
|
contentType: "application/json; charset=utf-8",
|
||||||
|
dataType: "json",
|
||||||
|
complete: function(res, text){
|
||||||
|
callback(
|
||||||
|
text !== 'success' ? res.statusText : null,
|
||||||
|
JSON.parse(res.responseText),
|
||||||
|
res.status
|
||||||
|
)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {post: post, get: get, put: put, delete: remove}
|
||||||
|
})(app)
|
||||||
|
|
||||||
|
app.auth = (function(app) {
|
||||||
|
var user = {}
|
||||||
|
function setToken(token){
|
||||||
|
localStorage.setItem('APIToken', token);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getToken(){
|
||||||
|
return localStorage.getItem('APIToken');
|
||||||
|
}
|
||||||
|
|
||||||
|
function isLoggedIn(callback){
|
||||||
|
if(getToken()){
|
||||||
|
return app.api.get('user/me', function(error, data){
|
||||||
|
if(error === 'Unauthorized') logOut();
|
||||||
|
if(!error) app.auth.user = data;
|
||||||
|
return callback(error, data);
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
callback(null, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})(jQuery);
|
|
||||||
|
|
||||||
app.include([
|
function logIn(args, callback){
|
||||||
'/utils.js',
|
app.api.post('auth/login', args, function(error, data){
|
||||||
'/pubsub.js',
|
if(data.login){
|
||||||
'/api.js',
|
setToken(data.token);
|
||||||
'/socket.js',
|
}
|
||||||
'/user.js',
|
callback(error, !!data.token);
|
||||||
'/group.js',
|
});
|
||||||
'/auth.js',
|
}
|
||||||
], JQapp_BASE_PATH)
|
|
||||||
|
|
||||||
/*
|
function logOut(callback){
|
||||||
when the DOM is finished, start the app
|
callback = callback || app.util.emptyFuction;
|
||||||
*/
|
localStorage.removeItem('APIToken');
|
||||||
jQuery(document).on("DOMContentLoaded", function(event) {
|
callback();
|
||||||
app.publish("__dom-content-loaded-start");
|
}
|
||||||
app.publish("__dom-content-loaded-end");
|
|
||||||
});
|
function makeUserFromInvite(args, callback){
|
||||||
|
app.api.post('auth/invite/'+ args.token, args, function(error, data){
|
||||||
|
if(data.login){
|
||||||
|
callback(null, data);
|
||||||
|
setToken(data.token);
|
||||||
|
}
|
||||||
|
callback(error, !!data.token);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function forceLogin(){
|
||||||
|
$.holdReady( true );
|
||||||
|
app.auth.isLoggedIn(function(error, isLoggedIn){
|
||||||
|
if(error || !isLoggedIn){
|
||||||
|
app.auth.logOut(function(){})
|
||||||
|
location.replace(`/login${location.href.replace(location.origin, '')}`);
|
||||||
|
}else{
|
||||||
|
$.holdReady( false );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function logInRedirect(){
|
||||||
|
window.location.href = location.href.replace(location.origin+'/login', '') || '/'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$( document ).ready( function(){
|
||||||
|
isLoggedIn(function(error, isLoggedIn){
|
||||||
|
if(!error && isLoggedIn){
|
||||||
|
$('.tbp_proxy_is_authed').show();
|
||||||
|
$('.tbp_proxy_not_authed').hide();
|
||||||
|
}else{
|
||||||
|
$('.tbp_proxy_is_authed').hide();
|
||||||
|
$('.tbp_proxy_not_authed').show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
getToken: getToken,
|
||||||
|
setToken: setToken,
|
||||||
|
isLoggedIn: isLoggedIn,
|
||||||
|
logIn: logIn,
|
||||||
|
logOut: logOut,
|
||||||
|
makeUserFromInvite: makeUserFromInvite,
|
||||||
|
forceLogin,
|
||||||
|
logInRedirect,
|
||||||
|
}
|
||||||
|
|
||||||
|
})(app);
|
||||||
|
|
||||||
|
app.util = (function(app){
|
||||||
|
|
||||||
|
function getUrlParameter(name) {
|
||||||
|
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
||||||
|
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
|
||||||
|
var results = regex.exec(location.search);
|
||||||
|
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
|
||||||
|
};
|
||||||
|
|
||||||
|
function actionMessage(message, $target, type, callback){
|
||||||
|
message = message || '';
|
||||||
|
$target = $target.closest('div.card').find('.actionMessage');
|
||||||
|
type = type || 'info';
|
||||||
|
callback = callback || function(){};
|
||||||
|
|
||||||
|
if($target.html() === message) return;
|
||||||
|
|
||||||
|
if($target.html()){
|
||||||
|
$target.slideUp('fast', function(){
|
||||||
|
$target.html('')
|
||||||
|
$target.removeClass (function (index, className) {
|
||||||
|
return (className.match (/(^|\s)ui-\S+/g) || []).join(' ');
|
||||||
|
});
|
||||||
|
if(message) return actionMessage(message, $target, type, callback);
|
||||||
|
$target.hide()
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
if(type) $target.addClass('ui-' + type);
|
||||||
|
$target.html(message).slideDown('fast');
|
||||||
|
}
|
||||||
|
setTimeout(callback,10)
|
||||||
|
}
|
||||||
|
|
||||||
|
$.fn.serializeObject = function() {
|
||||||
|
var
|
||||||
|
arr = $(this).serializeArray(),
|
||||||
|
obj = {};
|
||||||
|
|
||||||
|
for(var i = 0; i < arr.length; i++) {
|
||||||
|
if(obj[arr[i].name] === undefined) {
|
||||||
|
obj[arr[i].name] = arr[i].value;
|
||||||
|
} else {
|
||||||
|
if(!(obj[arr[i].name] instanceof Array)) {
|
||||||
|
obj[arr[i].name] = [obj[arr[i].name]];
|
||||||
|
}
|
||||||
|
obj[arr[i].name].push(arr[i].value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
getUrlParameter: getUrlParameter,
|
||||||
|
actionMessage: actionMessage,
|
||||||
|
emptyFuction: function(){},
|
||||||
|
|
||||||
|
}
|
||||||
|
})(app);
|
||||||
|
|
||||||
|
|
||||||
|
app.user = (function(app){
|
||||||
|
function list(callback){
|
||||||
|
app.api.get('user/?detail=true', function(error, data){
|
||||||
|
callback(error, data);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function add(args, callback){
|
||||||
|
app.api.post('user/', args, function(error, data){
|
||||||
|
callback(error, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove(args, callback){
|
||||||
|
if(!confirm('Delete '+ args.uid+ 'user?')) return false;
|
||||||
|
app.api.delete('user/'+ args.uid, function(error, data){
|
||||||
|
callback(error, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function changePassword(args, callback){
|
||||||
|
app.api.put('users/'+ arg.uid || '', args, function(error, data){
|
||||||
|
callback(error, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function createInvite(callback){
|
||||||
|
app.api.post('user/invite', {}, function(error, data, status){
|
||||||
|
callback(error, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function consumeInvite(args){
|
||||||
|
app.api.post('/auth/invite/'+args.token, args, function(error, data){
|
||||||
|
if(data.token){
|
||||||
|
app.auth.setToken(data.token)
|
||||||
|
return callback(null, true)
|
||||||
|
}
|
||||||
|
callback(error)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {list, remove, createInvite};
|
||||||
|
|
||||||
|
})(app);
|
||||||
|
|
||||||
|
app.group = (function(app){
|
||||||
|
function list(callback){
|
||||||
|
app.api.get('group?detail=true', function(error, data){
|
||||||
|
callback(error, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove(args, callback){
|
||||||
|
app.api.delete('group/'+args.cn, function(error, data){
|
||||||
|
callback(error, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {list, remove}
|
||||||
|
})(app);
|
||||||
|
|
||||||
|
$( document ).ready( function () {
|
||||||
|
|
||||||
|
$( 'div.row' ).fadeIn( 'slow' ); //show the page
|
||||||
|
|
||||||
|
//panel button's
|
||||||
|
$( '.fa-arrows-v' ).click( function () {
|
||||||
|
$( this ).closest( '.card' ).find( '.card-body' ).slideToggle( 'fast' );
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.actionMessage').on('click', 'button.action-close', function(event){
|
||||||
|
app.util.actionMessage(null, $(this));
|
||||||
|
})
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
//ajax form submit
|
||||||
|
function formAJAX( btn, del ) {
|
||||||
|
event.preventDefault(); // avoid to execute the actual submit of the form.
|
||||||
|
var $form = $(btn).closest( '[action]' ); // gets the 'form' parent
|
||||||
|
var formData = $form.find( '[name]' ).serializeObject(); // builds query formDataing
|
||||||
|
var method = $form.attr('method') || 'post';
|
||||||
|
|
||||||
|
// if( !$form.validate()) {
|
||||||
|
// app.util.actionMessage('Please fix the form errors.', $form, 'danger')
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
app.util.actionMessage(
|
||||||
|
'<div class="spinner-border" role="status"><span class="sr-only">Loading...</span></div>',
|
||||||
|
$form,
|
||||||
|
'state-highlight'
|
||||||
|
);
|
||||||
|
|
||||||
|
app.api[method]($form.attr('action'), formData, function(error, data){
|
||||||
|
app.util.actionMessage(data.message, $form, error ? 'state-error' : 'priority-primary'); //re-populate table
|
||||||
|
if(!error){
|
||||||
|
$form.trigger("reset");
|
||||||
|
eval($form.attr('evalAJAX')); //gets JS to run after completion
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,91 +0,0 @@
|
|||||||
app.api = (function(app){
|
|
||||||
var baseURL = '/__api/'
|
|
||||||
|
|
||||||
|
|
||||||
$( document ).on( "ajaxError", function(event, res, req) {
|
|
||||||
console.log('bad!', `app:api:error:`, res.status);
|
|
||||||
app.publish(`app:api:error:${res.status}`, {res, res});
|
|
||||||
} );
|
|
||||||
|
|
||||||
function post(url, data, callback){
|
|
||||||
callback = callback || app.util.emptyFuction;
|
|
||||||
$.ajax({
|
|
||||||
type: 'POST',
|
|
||||||
url: baseURL+url,
|
|
||||||
headers:{
|
|
||||||
'auth-token': app.auth.getToken()
|
|
||||||
},
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
contentType: "application/json; charset=utf-8",
|
|
||||||
dataType: "json",
|
|
||||||
complete: function(res, text){
|
|
||||||
callback(
|
|
||||||
text !== 'success' ? res.statusText : null,
|
|
||||||
JSON.parse(res.responseText),
|
|
||||||
res.status
|
|
||||||
)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function put(url, data, callback){
|
|
||||||
$.ajax({
|
|
||||||
type: 'PUT',
|
|
||||||
url: baseURL+url,
|
|
||||||
headers:{
|
|
||||||
'auth-token': app.auth.getToken()
|
|
||||||
},
|
|
||||||
data: JSON.stringify(data),
|
|
||||||
contentType: "application/json; charset=utf-8",
|
|
||||||
dataType: "json",
|
|
||||||
complete: function(res, text){
|
|
||||||
callback(
|
|
||||||
text !== 'success' ? res.statusText : null,
|
|
||||||
JSON.parse(res.responseText),
|
|
||||||
res.status
|
|
||||||
)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function remove(url, callback, callback2){
|
|
||||||
if(!$.isFunction(callback)) callback = callback2;
|
|
||||||
$.ajax({
|
|
||||||
type: 'delete',
|
|
||||||
url: baseURL+url,
|
|
||||||
headers:{
|
|
||||||
'auth-token': app.auth.getToken()
|
|
||||||
},
|
|
||||||
contentType: "application/json; charset=utf-8",
|
|
||||||
dataType: "json",
|
|
||||||
complete: function(res, text){
|
|
||||||
callback(
|
|
||||||
text !== 'success' ? res.statusText : null,
|
|
||||||
JSON.parse(res.responseText),
|
|
||||||
res.status
|
|
||||||
)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function get(url, callback){
|
|
||||||
$.ajax({
|
|
||||||
type: 'GET',
|
|
||||||
url: baseURL+url,
|
|
||||||
headers:{
|
|
||||||
'auth-token': app.auth.getToken()
|
|
||||||
},
|
|
||||||
contentType: "application/json; charset=utf-8",
|
|
||||||
dataType: "json",
|
|
||||||
complete: function(res, text){
|
|
||||||
callback(
|
|
||||||
text !== 'success' ? res.statusText : null,
|
|
||||||
JSON.parse(res.responseText),
|
|
||||||
res.status
|
|
||||||
)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return {post: post, get: get, put: put, delete: remove}
|
|
||||||
})(app);
|
|
@ -1,87 +0,0 @@
|
|||||||
app.auth = (function(app) {
|
|
||||||
var user = {}
|
|
||||||
function setToken(token){
|
|
||||||
localStorage.setItem('APIToken', token);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getToken(){
|
|
||||||
return localStorage.getItem('APIToken');
|
|
||||||
}
|
|
||||||
|
|
||||||
function isLoggedIn(callback){
|
|
||||||
if(getToken()){
|
|
||||||
return app.api.get('user/me', function(error, data){
|
|
||||||
if(error === 'Unauthorized') logOut();
|
|
||||||
if(!error) app.auth.user = data;
|
|
||||||
return callback(error, data);
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
callback(null, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function logIn(args, callback){
|
|
||||||
app.api.post('auth/login', args, function(error, data){
|
|
||||||
if(data.login){
|
|
||||||
setToken(data.token);
|
|
||||||
}
|
|
||||||
callback(error, !!data.token);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function logOut(callback){
|
|
||||||
callback = callback || app.util.emptyFuction;
|
|
||||||
localStorage.removeItem('APIToken');
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeUserFromInvite(args, callback){
|
|
||||||
app.api.post('auth/invite/'+ args.token, args, function(error, data){
|
|
||||||
if(data.login){
|
|
||||||
callback(null, data);
|
|
||||||
setToken(data.token);
|
|
||||||
}
|
|
||||||
callback(error, !!data.token);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function forceLogin(){
|
|
||||||
$.holdReady( true );
|
|
||||||
app.auth.isLoggedIn(function(error, isLoggedIn){
|
|
||||||
if(error || !isLoggedIn){
|
|
||||||
app.auth.logOut(function(){})
|
|
||||||
location.replace(`/login${location.href.replace(location.origin, '')}`);
|
|
||||||
}else{
|
|
||||||
$.holdReady( false );
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function logInRedirect(){
|
|
||||||
window.location.href = location.href.replace(location.origin+'/login', '') || '/'
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$( document ).ready( function(){
|
|
||||||
isLoggedIn(function(error, isLoggedIn){
|
|
||||||
if(!error && isLoggedIn){
|
|
||||||
$('.tbp_proxy_is_authed').show();
|
|
||||||
$('.tbp_proxy_not_authed').hide();
|
|
||||||
}else{
|
|
||||||
$('.tbp_proxy_is_authed').hide();
|
|
||||||
$('.tbp_proxy_not_authed').show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
getToken: getToken,
|
|
||||||
setToken: setToken,
|
|
||||||
isLoggedIn: isLoggedIn,
|
|
||||||
logIn: logIn,
|
|
||||||
logOut: logOut,
|
|
||||||
makeUserFromInvite: makeUserFromInvite,
|
|
||||||
forceLogin,
|
|
||||||
logInRedirect,
|
|
||||||
}
|
|
||||||
})(app);
|
|
@ -1,15 +0,0 @@
|
|||||||
app.group = (function(app){
|
|
||||||
function list(callback){
|
|
||||||
app.api.get('group?detail=true', function(error, data){
|
|
||||||
callback(error, data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function remove(args, callback){
|
|
||||||
app.api.delete('group/'+args.cn, function(error, data){
|
|
||||||
callback(error, data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return {list, remove}
|
|
||||||
})(app);
|
|
@ -1,41 +0,0 @@
|
|||||||
app.pubsub = (function(){
|
|
||||||
app.topics = {};
|
|
||||||
|
|
||||||
app.subscribe = function(topic, listener) {
|
|
||||||
if(topic instanceof RegExp){
|
|
||||||
listener.match = topic;
|
|
||||||
topic = "__REGEX__";
|
|
||||||
}
|
|
||||||
|
|
||||||
// create the topic if not yet created
|
|
||||||
if(!app.topics[topic]) app.topics[topic] = [];
|
|
||||||
|
|
||||||
// add the listener
|
|
||||||
app.topics[topic].push(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
app.matchTopics = function(topic){
|
|
||||||
topic = topic || '';
|
|
||||||
var matches = [... app.topics[topic] ? app.topics[topic] : []];
|
|
||||||
|
|
||||||
if(!app.topics['__REGEX__']) return matches;
|
|
||||||
|
|
||||||
for(var listener of app.topics['__REGEX__']){
|
|
||||||
if(topic.match(listener.match)) matches.push(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
return matches;
|
|
||||||
}
|
|
||||||
|
|
||||||
app.publish = function(topic, data) {
|
|
||||||
|
|
||||||
// send the event to all listeners
|
|
||||||
app.matchTopics(topic).forEach(function(listener) {
|
|
||||||
setTimeout(function(data, topic){
|
|
||||||
listener(data || {}, topic);
|
|
||||||
}, 0, data, topic);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
})(app);
|
|
@ -1,28 +0,0 @@
|
|||||||
app.socket = (function(app){
|
|
||||||
// $.getScript('/socket.io/socket.io.js')
|
|
||||||
// <script type="text/javascript" src="/socket.io/socket.io.js"></script>
|
|
||||||
|
|
||||||
var socket;
|
|
||||||
$(document).ready(function(){
|
|
||||||
socket = io({
|
|
||||||
auth: {
|
|
||||||
token: app.auth.getToken()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// socket.emit('chat message', $('#m').val());
|
|
||||||
socket.on('P2PSub', function(msg){
|
|
||||||
msg.data.__noSocket = true;
|
|
||||||
app.publish(msg.topic, msg.data);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.subscribe(/./g, function(data, topic){
|
|
||||||
// console.log('local_pubs', data, topic)
|
|
||||||
if(data.__noSocket) return;
|
|
||||||
// console.log('local_pubs 2', data, topic)
|
|
||||||
|
|
||||||
socket.emit('P2PSub', { topic, data });
|
|
||||||
});
|
|
||||||
})
|
|
||||||
|
|
||||||
return socket;
|
|
||||||
})(app);
|
|
@ -1,122 +0,0 @@
|
|||||||
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
|
|
||||||
];
|
|
||||||
|
|
||||||
function list(callback, username) {
|
|
||||||
app.api.get('torrent', function(error, data){
|
|
||||||
if(error) return;
|
|
||||||
callback(null, data)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function get(callback, id, forceUpdate){
|
|
||||||
app.api.get(`torrent/${id}?${forceUpdate ? 'latest': '' }`, function(error, data){
|
|
||||||
if(error) return;
|
|
||||||
callback(null, data)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function start(id, callback){
|
|
||||||
app.api.post(`torrent/${id}/start`, function(error, data){
|
|
||||||
if(error) return;
|
|
||||||
callback(null, data)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function stop(id, callback){
|
|
||||||
app.api.post(`torrent/${id}/stop`, function(error, data){
|
|
||||||
if(error) return;
|
|
||||||
callback(null, data)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function destroy(id, callback){
|
|
||||||
app.api.delete(`torrent/${id}`, 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(),
|
|
||||||
|
|
||||||
// "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,
|
|
||||||
// "createdAt": "2024-01-05T21:18:30.607Z",
|
|
||||||
// "updatedAt": "2024-01-05T21:32:54.493Z"
|
|
||||||
// "torrent_id": "454",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {list, get, start, stop, destroy, parseTorrnetItem, parseServerStatus, isDown};
|
|
||||||
})(app);
|
|
@ -1,44 +0,0 @@
|
|||||||
app.user = (function(app){
|
|
||||||
function list(callback){
|
|
||||||
app.api.get('user/?detail=true', function(error, data){
|
|
||||||
callback(error, data);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function add(args, callback){
|
|
||||||
app.api.post('user/', args, function(error, data){
|
|
||||||
callback(error, data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function remove(args, callback){
|
|
||||||
if(!confirm('Delete '+ args.uid+ 'user?')) return false;
|
|
||||||
app.api.delete('user/'+ args.uid, function(error, data){
|
|
||||||
callback(error, data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function changePassword(args, callback){
|
|
||||||
app.api.put('users/'+ arg.uid || '', args, function(error, data){
|
|
||||||
callback(error, data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function createInvite(callback){
|
|
||||||
app.api.post('user/invite', {}, function(error, data, status){
|
|
||||||
callback(error, data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function consumeInvite(args){
|
|
||||||
app.api.post('/auth/invite/'+args.token, args, function(error, data){
|
|
||||||
if(data.token){
|
|
||||||
app.auth.setToken(data.token)
|
|
||||||
return callback(null, true)
|
|
||||||
}
|
|
||||||
callback(error)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return {list, remove, createInvite};
|
|
||||||
})(app);
|
|
@ -1,96 +0,0 @@
|
|||||||
app.util = (function(app){
|
|
||||||
|
|
||||||
function getUrlParameter(name) {
|
|
||||||
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
|
||||||
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
|
|
||||||
var results = regex.exec(location.search);
|
|
||||||
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
|
|
||||||
};
|
|
||||||
|
|
||||||
function actionMessage(message, $target, type, callback){
|
|
||||||
message = message || '';
|
|
||||||
$target = $target.closest('div.card').find('.actionMessage');
|
|
||||||
type = type || 'info';
|
|
||||||
callback = callback || function(){};
|
|
||||||
|
|
||||||
if($target.html() === message) return;
|
|
||||||
|
|
||||||
if($target.html()){
|
|
||||||
$target.slideUp('fast', function(){
|
|
||||||
$target.html('')
|
|
||||||
$target.removeClass (function (index, className) {
|
|
||||||
return (className.match (/(^|\s)ui-\S+/g) || []).join(' ');
|
|
||||||
});
|
|
||||||
if(message) return actionMessage(message, $target, type, callback);
|
|
||||||
$target.hide()
|
|
||||||
})
|
|
||||||
}else{
|
|
||||||
if(type) $target.addClass('ui-' + type);
|
|
||||||
$target.html(message).slideDown('fast');
|
|
||||||
}
|
|
||||||
setTimeout(callback,10)
|
|
||||||
}
|
|
||||||
|
|
||||||
$( document ).ready( function () {
|
|
||||||
$('.actionMessage').on('click', 'button.action-close', function(event){
|
|
||||||
app.util.actionMessage(null, $(this));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$.fn.serializeObject = function() {
|
|
||||||
var
|
|
||||||
arr = $(this).serializeArray(),
|
|
||||||
obj = {};
|
|
||||||
|
|
||||||
for(var i = 0; i < arr.length; i++) {
|
|
||||||
if(obj[arr[i].name] === undefined) {
|
|
||||||
obj[arr[i].name] = arr[i].value;
|
|
||||||
} else {
|
|
||||||
if(!(obj[arr[i].name] instanceof Array)) {
|
|
||||||
obj[arr[i].name] = [obj[arr[i].name]];
|
|
||||||
}
|
|
||||||
obj[arr[i].name].push(arr[i].value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
};
|
|
||||||
|
|
||||||
function formAJAX( btn, del ) {
|
|
||||||
event.preventDefault(); // avoid to execute the actual submit of the form.
|
|
||||||
var $form = $(btn).closest( '[action]' ); // gets the 'form' parent
|
|
||||||
var formData = $form.find( '[name]' ).serializeObject(); // builds query formDataing
|
|
||||||
var method = $form.attr('method') || 'post';
|
|
||||||
|
|
||||||
// if( !$form.validate()) {
|
|
||||||
// app.util.actionMessage('Please fix the form errors.', $form, 'danger')
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
app.util.actionMessage(
|
|
||||||
'<div class="spinner-border" role="status"><span class="sr-only">Loading...</span></div>',
|
|
||||||
$form,
|
|
||||||
'state-highlight'
|
|
||||||
);
|
|
||||||
|
|
||||||
app.api[method]($form.attr('action'), formData, function(error, data){
|
|
||||||
app.util.actionMessage(data.message, $form, error ? 'state-error' : 'priority-primary'); //re-populate table
|
|
||||||
if(!error){
|
|
||||||
$form.trigger("reset");
|
|
||||||
eval($form.attr('evalAJAX')); //gets JS to run after completion
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
emptyFuction: function(){},
|
|
||||||
getUrlParameter,
|
|
||||||
actionMessage,
|
|
||||||
humanFileSize,
|
|
||||||
formAJAX,
|
|
||||||
}
|
|
||||||
})(app);
|
|
@ -7,7 +7,7 @@
|
|||||||
var make = function( element ){
|
var make = function( element ){
|
||||||
|
|
||||||
//construct array
|
//construct array
|
||||||
function makeArray( input ){
|
function makeArray( input , index ){
|
||||||
|
|
||||||
var result = [];
|
var result = [];
|
||||||
|
|
||||||
@ -25,6 +25,20 @@
|
|||||||
configurable: true
|
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){
|
result.splice = function(inputValue, ...args){
|
||||||
//splice does all the heavy lifting by interacting with the DOM elements.
|
//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 there are fields to add to the array, add them
|
||||||
if( toAdd.length > 0 ){
|
if( toAdd.length > 0 ){
|
||||||
|
removeEmpty()
|
||||||
|
|
||||||
//$.each( toAdd, function( key, value ){
|
//$.each( toAdd, function( key, value ){
|
||||||
for(var I = 0; I < toAdd.length; I++){
|
for(var I = 0; I < toAdd.length; I++){
|
||||||
@ -176,7 +191,7 @@
|
|||||||
result.indexOf = function( key, value ){
|
result.indexOf = function( key, value ){
|
||||||
if( !value ){
|
if( !value ){
|
||||||
value = arguments[0];
|
value = arguments[0];
|
||||||
key = this.__index;
|
key = this.__jq_index;
|
||||||
}
|
}
|
||||||
for ( var index = 0; index < this.length; ++index ) {
|
for ( var index = 0; index < this.length; ++index ) {
|
||||||
if( this[index][key] === value ){
|
if( this[index][key] === value ){
|
||||||
@ -200,7 +215,7 @@
|
|||||||
if( !update ){
|
if( !update ){
|
||||||
update = arguments[1];
|
update = arguments[1];
|
||||||
value = arguments[0];
|
value = arguments[0];
|
||||||
key = this.__index;
|
key = this.__jq_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
var index = this.indexOf( key, value );
|
var index = this.indexOf( key, value );
|
||||||
@ -226,7 +241,7 @@
|
|||||||
if( type === 'object' ){
|
if( type === 'object' ){
|
||||||
result.push( value );
|
result.push( value );
|
||||||
}else if( type === 'string' ){
|
}else if( type === 'string' ){
|
||||||
Object.defineProperty( result, "__index", {
|
Object.defineProperty( result, "__jq_index", {
|
||||||
value: value,
|
value: value,
|
||||||
writable: true,
|
writable: true,
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
@ -248,19 +263,23 @@
|
|||||||
|
|
||||||
var $this = $( element );
|
var $this = $( element );
|
||||||
var repeatId = $this.attr( 'jq-repeat' );
|
var repeatId = $this.attr( 'jq-repeat' );
|
||||||
|
var index = $this.attr( 'jq-repeat-index' );
|
||||||
var tempId = repeatId + 'Template';
|
var tempId = repeatId + 'Template';
|
||||||
var templateId = $( '#' + tempId ).html();
|
var templateId = $( '#' + tempId ).html();
|
||||||
|
var empty = $(`[jq-repeat-defualt="${repeatId}"]`);
|
||||||
|
|
||||||
|
|
||||||
$this.removeAttr( 'jq-repeat' );
|
$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>' );
|
$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
|
Mustache.parse(templateId); // optional, speeds up future uses
|
||||||
|
|
||||||
|
$.scope[repeatId] = makeArray($.scope[repeatId], index);
|
||||||
$.scope[repeatId] = makeArray($.scope[repeatId]);
|
$.scope[repeatId].__rq_template = template;
|
||||||
$.scope[repeatId].__rq_template = template
|
$.scope[repeatId].__jq_empty = empty;
|
||||||
};
|
};
|
||||||
|
|
||||||
$( document ).ready( function(){
|
$( document ).ready( function(){
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
<script type="text/javascript">
|
|
||||||
var JQapp_BASE_PATH = '/__static/js/app';
|
|
||||||
</script>
|
|
||||||
<link rel="stylesheet" href="/__static-modules/jquery-ui/dist/themes/smoothness/jquery-ui.css">
|
<link rel="stylesheet" href="/__static-modules/jquery-ui/dist/themes/smoothness/jquery-ui.css">
|
||||||
|
|
||||||
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
|
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
|
||||||
@ -9,355 +6,542 @@
|
|||||||
<script src="/__static-modules/moment/min/moment-with-locales.min.js"></script>
|
<script src="/__static-modules/moment/min/moment-with-locales.min.js"></script>
|
||||||
<script src="/__static-modules/jquery-ui/dist/jquery-ui.min.js"></script>
|
<script src="/__static-modules/jquery-ui/dist/jquery-ui.min.js"></script>
|
||||||
<script src="/__static/js/app.js"></script>
|
<script src="/__static/js/app.js"></script>
|
||||||
<script>
|
|
||||||
console.log("here", app)
|
|
||||||
app.include('/torrent.js');
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
.ui-dialog .ui-dialog-title{
|
.ui-dialog{
|
||||||
width: unset;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
.ui-dialog .ui-dialog-title{
|
||||||
|
width: unset;
|
||||||
|
}
|
||||||
|
|
||||||
#tbp_proxy_header {
|
#tbp_proxy_header {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
z-index: 95;
|
z-index: 95;
|
||||||
background: lightblue;
|
background: lightblue;
|
||||||
height: 3em;
|
height: 3em;
|
||||||
text-align: initial;
|
text-align: initial;
|
||||||
padding-top: .5em;
|
padding-top: .5em;
|
||||||
padding-right: 1em;
|
padding-right: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#tbp_proxy_header_right{
|
#tbp_proxy_header_right{
|
||||||
margin-right: 2em;
|
margin-right: 2em;
|
||||||
float: right;
|
float: right;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items:center;
|
align-items:center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#tbp_proxy_torrent_dialog_opener{
|
#tbp_proxy_torrent_dialog_opener{
|
||||||
border-radius: 25px;
|
border-radius: 25px;
|
||||||
background: lightseagreen;
|
background: lightseagreen;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items:center;
|
align-items:center;
|
||||||
|
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
padding-top: .3em;
|
padding-top: .3em;
|
||||||
padding-bottom: .3em;
|
padding-bottom: .3em;
|
||||||
|
|
||||||
margin-right: .5em;
|
margin-right: .5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#header {
|
#header {
|
||||||
padding-top: 3.5em;
|
padding-top: 3.5em;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Dialog boxes to be displayed
|
Dialog boxes to be displayed
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<div id="tbp_proxy_login_dialog" title="SSO Login">
|
<div id="tbp_proxy_login_dialog" title="SSO Login">
|
||||||
<div class="shadow-lg card">
|
<div class="shadow-lg card">
|
||||||
<div class="card-header shadow actionMessage" style="display:none"></div>
|
<div class="card-header shadow actionMessage" style="display:none"></div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form action="auth/login" onsubmit="formAJAX(this)" evalAJAX="
|
<form action="auth/login" onsubmit="formAJAX(this)" evalAJAX="
|
||||||
app.auth.setToken(data.token);
|
app.auth.setToken(data.token);
|
||||||
app.auth.logInRedirect();
|
app.auth.logInRedirect();
|
||||||
">
|
">
|
||||||
<input type="hidden" name="redirect" value="<%= redirect %>">
|
<input type="hidden" name="redirect" value="<%= redirect %>">
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label">User name</label>
|
<label class="control-label">User name</label>
|
||||||
<div class="input-group mb-3 shadow">
|
<div class="input-group mb-3 shadow">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<span class="input-group-text" ><i class="fa-solid fa-user-tie"></i></span>
|
<span class="input-group-text" ><i class="fa-solid fa-user-tie"></i></span>
|
||||||
</div>
|
</div>
|
||||||
<input type="text" name="uid" class="form-control" placeholder="jsmith" />
|
<input type="text" name="uid" class="form-control" placeholder="jsmith" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label">Password</label>
|
<label class="control-label">Password</label>
|
||||||
<div class="input-group mb-3 shadow">
|
<div class="input-group mb-3 shadow">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<span class="input-group-text" ><i class="fa-solid fa-key"></i></span>
|
<span class="input-group-text" ><i class="fa-solid fa-key"></i></span>
|
||||||
</div>
|
</div>
|
||||||
<input type="password" name="password" class="form-control" placeholder="hunter123!"/>
|
<input type="password" name="password" class="form-control" placeholder="hunter123!"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" class="btn btn-outline-dark"><i class="fa-solid fa-right-to-bracket"></i> Log in</button>
|
<button type="submit" class="btn btn-outline-dark"><i class="fa-solid fa-right-to-bracket"></i> Log in</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Torrent List Dialog
|
Torrent List Dialog
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
#tbp_proxy_torrent_dialog{
|
#tbp_proxy_torrent_dialog{
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
#tbp_proxy_torrent_dialog progress{
|
|
||||||
width: 100%;
|
#tbp_proxy_torrent_dialog progress{
|
||||||
height: 2em;
|
width: 100%;
|
||||||
}
|
height: 2em;
|
||||||
#tbp_proxy_torrent_dialog ul{
|
}
|
||||||
max-height: 400px;
|
|
||||||
overflow-y: scroll;
|
#tbp_proxy_torrent_dialog ul{
|
||||||
list-style-type: none;
|
height: 400px;
|
||||||
padding-left: 0;
|
overflow-y: scroll;
|
||||||
margin-bottom: 0;
|
list-style-type: none;
|
||||||
}
|
padding-left: 0;
|
||||||
#tbp_proxy_torrent_dialog li{
|
margin-top: 0;
|
||||||
padding-left: 1em;
|
margin-bottom: 0;
|
||||||
padding-right: 1em;
|
}
|
||||||
}
|
|
||||||
|
#tbp_proxy_torrent_dialog li{
|
||||||
|
padding-left: 1em;
|
||||||
|
padding-right: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#tbp_proxy_torrent_dialog li p{
|
||||||
|
margin: .3em;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div id="tbp_proxy_torrent_dialog" title="Torrents">
|
<div id="tbp_proxy_torrent_dialog" title="Torrents">
|
||||||
<ul>
|
<ul>
|
||||||
<li jq-repeat="tbp_proxy_torrent_dialog_torrents">{{name}}
|
<li jq-repeat="tbp_proxy_torrent_dialog_torrents" jq-repeat-index="hashString">
|
||||||
<br />
|
<p>
|
||||||
{{^isFinished}}
|
<b>{{name}}</b> - <i>{{statusText}}</i>
|
||||||
<progress id="file" max="100" value="{{percentDone}}">{{percentDone}}%</progress>
|
</p>
|
||||||
<br />
|
<p>
|
||||||
<b>{{statusText}}</b> @ <b>{{rateDownload}}</b> finishing <b>{{eta}}</b>
|
Is <b>{{sizeWhenDone}}</b>
|
||||||
<br />
|
saved to <b>{{downloadDir}}</b>
|
||||||
{{^isActive}}
|
added by <b>{{added_by}}</b>
|
||||||
<button class="ui-button ui-widget ui-corner-all" onclick="app.torrent.start({{id}})">
|
<b>{{createdAtString}}</b>
|
||||||
<span class="ui-icon ui-icon-play"></span> Start
|
</p>
|
||||||
</button>
|
|
||||||
{{/isActive}}
|
|
||||||
|
|
||||||
{{#isActive}}
|
{{^isFinished}}
|
||||||
<button class="ui-button ui-widget ui-corner-all" onclick="app.torrent.stop({{id}})">
|
<p>
|
||||||
<span class="ui-icon ui-icon-pause"></span>Pause
|
<progress id="file" max="100" value="{{percentDone}}">{{percentDone}}%</progress>
|
||||||
</button>
|
</p>
|
||||||
{{/isActive}}
|
|
||||||
|
|
||||||
<button class="ui-button ui-widget ui-corner-all" onclick="
|
{{#isActive}}
|
||||||
app.torrent.destroy({{id}}, function(error, data){
|
<p>
|
||||||
$.scope.tbp_proxy_torrent_dialog_torrents.splice({{__id}}, 1);
|
<b>{{rateDownload}}</b>
|
||||||
});
|
Finishing <b>{{eta}}</b>
|
||||||
">
|
From <b>{{peersConnected}}</b> Peers
|
||||||
<span class="ui-icon ui-icon-closethick"></span>Delete
|
</p>
|
||||||
</button>
|
|
||||||
|
|
||||||
{{/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}}
|
{{^isActive}}
|
||||||
<br /> Done! <a href="https://stuff.718it.biz/torrents/{{name}}" target="_blank"> HTTP Link</a>
|
<button class="ui-button ui-widget ui-corner-all" onclick="app.torrent.start({{hashString}})">
|
||||||
{{/isFinished}}
|
<span class="ui-icon ui-icon-play"></span> Start
|
||||||
<hr />
|
</button>
|
||||||
</li>
|
{{/isActive}}
|
||||||
</ul>
|
|
||||||
|
<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>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Torrent Add Dialog
|
Torrent Add Dialog
|
||||||
-->
|
-->
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
#tbp_proxy_torrent_add_dialog_container{
|
#tbp_proxy_torrent_add_dialog_container{
|
||||||
width: 32em;
|
width: 32em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#tbp_proxy_torrent_add_dialog input[type="text"]{
|
#tbp_proxy_torrent_add_dialog input[type="text"]{
|
||||||
width: 90%;
|
width: 90%;
|
||||||
}
|
}
|
||||||
#tbp_proxy_torrent_add_dialog label,legend{
|
#tbp_proxy_torrent_add_dialog label,legend{
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div id="tbp_proxy_torrent_add_dialog" title="Add torrent">
|
<div id="tbp_proxy_torrent_add_dialog" title="Add torrent">
|
||||||
<div id="tbp_proxy_torrent_add_dialog_container" class='card'>
|
<div id="tbp_proxy_torrent_add_dialog_container" class='card'>
|
||||||
<div class="card-header shadow actionMessage" style="display:none"></div>
|
<div class="card-header shadow actionMessage" style="display:none"></div>
|
||||||
<div jq-repeat="torrentAdd">
|
<div jq-repeat="torrentAdd">
|
||||||
<form action="torrent" method="post" onsubmit="formAJAX(this)" evalAJAX="
|
<form action="torrent" method="post" onsubmit="formAJAX(this)" evalAJAX="
|
||||||
app.publish('torrent:add', {...data, __noSocket: true});
|
app.publish('torrent:add', {...data, __noSocket: true});
|
||||||
$('#tbp_proxy_torrent_add_dialog').dialog('close');
|
$('#tbp_proxy_torrent_add_dialog').dialog('close');
|
||||||
openDialog($('#tbp_proxy_torrent_dialog'))
|
openDialog($('#tbp_proxy_torrent_dialog'))
|
||||||
">
|
">
|
||||||
<p>
|
<p>
|
||||||
<label for="_name">Name:</label>
|
<label for="_name">Name:</label>
|
||||||
<br />
|
<br />
|
||||||
<input type="text" name="_name" value="{{{name}}}" readonly/>
|
<input type="text" name="_name" value="{{{name}}}" readonly/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<label for="magnetLink">Magnet Link:</label>
|
<label for="magnetLink">Magnet Link:</label>
|
||||||
<br />
|
<br />
|
||||||
<input type="text" name="magnetLink" value="{{{magnetLink}}}" readonly/>
|
<input type="text" name="magnetLink" value="{{{magnetLink}}}" readonly/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<legend>Public Download:</legend>
|
<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>
|
<p style="display:none">
|
||||||
<input type="radio" name="isPrivate" id="radio-1" value="true" checked readonly/>
|
<legend>Public Download:</legend>
|
||||||
|
|
||||||
<label for="radio-2" title="Only you(and the admins) will be able to see this download">Private</label>
|
<label for="radio-1" title="The download will appare in the communal download folder">Public</label>
|
||||||
<input type="radio" name="isPrivate" id="radio-2" value="false" readonly/>
|
<input type="radio" name="isPrivate" id="radio-1" value="true" checked readonly/>
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
<label for="radio-2" title="Only you(and the admins) will be able to see this download">Private</label>
|
||||||
<legend>Start on add:</legend>
|
<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>
|
<p style="display:none">
|
||||||
<input type="radio" name="isStart" id="isStart-1" value="true" checked readonly/>
|
<legend>Start on add:</legend>
|
||||||
|
|
||||||
<label for="isStart-2" title="Only you(and the admins) will be able to see this download">No</label>
|
<label for="isStart-1" title="The download will appare in the communal download folder">Yes</label>
|
||||||
<input type="radio" name="isStart" id="isStart-2" value="false" readonly/>
|
<input type="radio" name="isStart" id="isStart-1" value="true" checked readonly/>
|
||||||
</p>
|
|
||||||
|
|
||||||
<hr />
|
<label for="isStart-2" title="Only you(and the admins) will be able to see this download">No</label>
|
||||||
<button type="submit">Start Download</button>
|
<input type="radio" name="isStart" id="isStart-2" value="false" readonly/>
|
||||||
<button onclick="$('#tbp_proxy_torrent_add_dialog').dialog('close')">Cancel</button>
|
</p>
|
||||||
</form>
|
|
||||||
</div>
|
<hr />
|
||||||
</div>
|
<button type="submit">Start Download</button>
|
||||||
|
<button onclick="$('#tbp_proxy_torrent_add_dialog').dialog('close')">Cancel</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</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">
|
<div id="tbp_proxy_header_right">
|
||||||
<span id="tbp_proxy_torrent_dialog_opener" class="tbp_proxy_is_authed">
|
<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;" />
|
<img src="/__static/img/Transmission_Icon.svg" height="22" width="22" style="margin-right: .3em;" />
|
||||||
<span jq-repeat="tbp_proxy_torrent_dialog_opener_status">
|
<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>
|
<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>
|
||||||
</span>
|
</span>
|
||||||
<button id="tbp_proxy_login_dialog_opener" class="tbp_proxy_not_authed ui-button ui-corner-all ui-widget">Login</button>
|
<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"
|
<button class="tbp_proxy_is_authed ui-button ui-corner-all ui-widget"
|
||||||
onclick="app.auth.logOut(e => window.location.href='/')">Logout</button>
|
onclick="app.auth.logOut(e => window.location.href='/')">Logout</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$( document ).ready(function() {
|
$( document ).ready(function() {
|
||||||
var commonDialogOptions = {
|
var commonDialogOptions = {
|
||||||
position: { my: "left top", at: "left bottom", of: '#tbp_proxy_header_right' },
|
position: { my: "left top", at: "left bottom", of: '#tbp_proxy_header_right' },
|
||||||
autoOpen: false,
|
autoOpen: false,
|
||||||
resizable: false,
|
resizable: false,
|
||||||
closeOnEscape: true,
|
closeOnEscape: true,
|
||||||
draggable: false,
|
draggable: false,
|
||||||
width: 'auto',
|
width: 'auto',
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Login Button and dialog*/
|
/* Login Button and dialog*/
|
||||||
$( "#tbp_proxy_login_dialog" ).dialog(commonDialogOptions);
|
$( "#tbp_proxy_login_dialog" ).dialog(commonDialogOptions);
|
||||||
|
|
||||||
$( "#tbp_proxy_login_dialog_opener" ).on( "click", function() {
|
$( "#tbp_proxy_login_dialog_opener" ).on( "click", function() {
|
||||||
// https://stackoverflow.com/a/6500385
|
// 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" ).parent().css({position:"fixed", 'margin-right': "2em", 'margin-top': '3em'}).end().dialog( "open" );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/* Torrent list button and dialog */
|
/* Torrent list button and dialog */
|
||||||
$( "#tbp_proxy_torrent_dialog" ).dialog(commonDialogOptions);
|
$( "#tbp_proxy_torrent_dialog" ).dialog(commonDialogOptions);
|
||||||
|
|
||||||
$( "#tbp_proxy_torrent_dialog_opener" ).on( "click", function() {
|
$( "#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" ).parent().css({position:"fixed", 'margin-right': "2em", 'margin-top': '3em'}).end().dialog( "open" );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/* Torrent add button and dialog */
|
/* Torrent add button and dialog */
|
||||||
$( "#tbp_proxy_torrent_add_dialog" ).dialog({
|
$( "#tbp_proxy_torrent_add_dialog" ).dialog({
|
||||||
modal: true,
|
modal: true,
|
||||||
height: 300,
|
height: 300,
|
||||||
...commonDialogOptions
|
...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*/
|
/* Enable tooltips*/
|
||||||
$( '#tbp_proxy_header' ).tooltip({
|
$( '#tbp_proxy_header' ).tooltip({
|
||||||
track: true
|
track: true
|
||||||
});
|
});
|
||||||
|
|
||||||
app.subscribe('torrent:add', function(data, topic){
|
app.auth.isLoggedIn(function(error, data){
|
||||||
console.log('sub', topic, data)
|
if(data){
|
||||||
$.scope.tbp_proxy_torrent_dialog_torrents.unshift(app.torrent.parseTorrnetItem(data))
|
|
||||||
});
|
|
||||||
|
|
||||||
app.subscribe('torrent:server:status', function(data, topic){
|
$("body").on('click', 'img.718link', function(el){
|
||||||
app.torrent.isDown = false
|
// magnetLink
|
||||||
$('#tbp_proxy_torrent_dialog_opener').css('background', "lightseagreen")
|
let magnetLinkParams = new URLSearchParams($(this).data('link'));
|
||||||
$.scope.tbp_proxy_torrent_dialog_opener_status.update(app.torrent.parseServerStatus(data));
|
|
||||||
});
|
|
||||||
|
|
||||||
app.subscribe(`app:api:error:555`, function(data, topics){
|
$.scope.torrentAdd.update({
|
||||||
console.log('we down')
|
magnetLink: $(this).data('link'),
|
||||||
app.torrent.isDown = true
|
name: magnetLinkParams.get('dn'),
|
||||||
$('#tbp_proxy_torrent_dialog_opener').css('background', "red")
|
hashString: magnetLinkParams.get('magnet:?xt').split(':').pop().toLowerCase(),
|
||||||
});
|
});
|
||||||
|
|
||||||
app.subscribe('torrent:server:status:down', function(data, topic){
|
$('#tbp_proxy_torrent_add_dialog').parent().css({position:"fixed", 'margin-right': "2em", 'margin-top': '3em'}).end().dialog('open');
|
||||||
app.torrent.isDown = true
|
});
|
||||||
$('#tbp_proxy_torrent_dialog_opener').css('background', "red")
|
|
||||||
});
|
// 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')+'"/>')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
listTorrents();
|
app.subscribe('torrent:add', function(data, topic){
|
||||||
setInterval(refreshTorrents, 5000)
|
$.scope.tbp_proxy_torrent_dialog_torrents.unshift(app.torrent.parseTorrnetItem(data))
|
||||||
});
|
});
|
||||||
|
|
||||||
function humanFileSize(size) {
|
app.subscribe('torrent:server:status', function(data, topic){
|
||||||
var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
|
app.torrent.isDown = false
|
||||||
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
|
$('#tbp_proxy_torrent_dialog_opener').css('background', "lightseagreen")
|
||||||
}
|
$.scope.tbp_proxy_torrent_dialog_opener_status.update(app.torrent.parseServerStatus(data));
|
||||||
|
});
|
||||||
|
|
||||||
function openDialog($el){
|
app.subscribe(`app:api:error:555`, function(data, topics){
|
||||||
$el.parent().css({
|
app.torrent.isDown = true
|
||||||
position:"fixed", 'margin-right': "2em", 'margin-top': '3em'
|
$('#tbp_proxy_torrent_dialog_opener').css('background', "red")
|
||||||
}).end().dialog('open');
|
});
|
||||||
}
|
|
||||||
|
|
||||||
function listTorrents(){
|
app.subscribe('torrent:server:status:down', function(data, topic){
|
||||||
app.torrent.list(function(err, data){
|
app.torrent.isDown = true
|
||||||
for(let torrent of data.results){
|
$('#tbp_proxy_torrent_dialog_opener').css('background', "red")
|
||||||
$.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(){
|
listTorrents();
|
||||||
for(let torrent of $.scope.tbp_proxy_torrent_dialog_torrents){
|
setInterval(refreshTorrents, 5000);
|
||||||
if(!torrent.isFinished){
|
app.torrent.migrate();
|
||||||
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 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))
|
||||||
|
if(torrent.percentDone !== 1) 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.removeItem('torrents',);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {list, get, start, stop, destroy, migrate, parseTorrnetItem, parseServerStatus, isDown};
|
||||||
|
})(app);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
115
routes/proxy.js
115
routes/proxy.js
@ -13,16 +13,21 @@ const mainjs = fs.readFileSync('./static/main.js', 'utf8');
|
|||||||
// app.all("/*.js", function(req, res){res.send('')});
|
// app.all("/*.js", function(req, res){res.send('')});
|
||||||
|
|
||||||
router.all('/static/main.js', function(req,res){
|
router.all('/static/main.js', function(req,res){
|
||||||
res.write(mainjs);
|
res.write(mainjs);
|
||||||
});
|
});
|
||||||
|
|
||||||
const proxyTarget = {
|
const proxyTarget = {
|
||||||
// target: "https://wtfismyip.com",
|
// target: "https://wtfismyip.com",
|
||||||
// host: "wtfismyip.com",
|
// host: "wtfismyip.com",
|
||||||
target: 'https://piratebay.party',
|
target: 'https://piratebay.party',
|
||||||
host: 'piratebay.party',
|
host: 'piratebay.party',
|
||||||
// target: 'http://172.16.0.1',
|
// target: 'http://172.16.0.1',
|
||||||
// host: 'piratebayo3klnzokct3wt5yyxb2vpebbuyjl7m623iaxmqhsd52coid.onion'
|
// target: 'http://piratebayo3klnzokct3wt5yyxb2vpebbuyjl7m623iaxmqhsd52coid.onion',
|
||||||
|
// host: 'piratebayo3klnzokct3wt5yyxb2vpebbuyjl7m623iaxmqhsd52coid.onion'
|
||||||
|
// target: 'https://thepiratebay.org',
|
||||||
|
// host: 'thepiratebay.org',
|
||||||
|
// target: 'https://www2.thepiratebay3.to',
|
||||||
|
// host: 'www2.thepiratebay3.to'
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateRegexForDomain(domain) {
|
function generateRegexForDomain(domain) {
|
||||||
@ -36,60 +41,62 @@ function generateRegexForDomain(domain) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
router.all("/*", proxy({
|
router.all("/*", proxy({
|
||||||
target: proxyTarget.target,
|
target: proxyTarget.target,
|
||||||
agent: proxyTarget.target.startsWith('https') ? https.globalAgent : http.globalAgent,
|
agent: proxyTarget.target.startsWith('https') ? https.globalAgent : http.globalAgent,
|
||||||
secure: false,
|
secure: true,
|
||||||
autoRewrite: true,
|
autoRewrite: true,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
followRedirects: true,
|
followRedirects: true,
|
||||||
headers: {
|
headers: {
|
||||||
host: proxyTarget.host
|
host: proxyTarget.host,
|
||||||
},
|
'Accept-Encoding': 'gzip',
|
||||||
selfHandleResponse: true, // so that the onProxyRes takes care of sending the response
|
},
|
||||||
onProxyRes: function(proxyRes, req, res){
|
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'] &&
|
if(proxyRes.statusCode === 403 && proxyRes.headers['content-type'] &&
|
||||||
proxyRes.headers['content-type'].match('html')
|
proxyRes.headers['content-type'].match('html')
|
||||||
){
|
){
|
||||||
console.log('403')
|
console.log('403')
|
||||||
var url = (req.protocol + '://' + req.get('host') + req.originalUrl);
|
var url = (req.protocol + '://' + req.get('host') + req.originalUrl);
|
||||||
proxyRes.headers['location'] = url.replace(/\??ckattempt\=\d+/, '');
|
proxyRes.headers['location'] = url.replace(/\??ckattempt\=\d+/, '');
|
||||||
proxyRes.statusCode == 307
|
proxyRes.statusCode = 307;
|
||||||
|
|
||||||
return res.end()
|
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://'))
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = new Buffer('');
|
let body = new Buffer('');
|
||||||
proxyRes.on('error', function(e){
|
proxyRes.on('error', function(e){
|
||||||
console.error('ERROR!', e)
|
console.error('ERROR!', e)
|
||||||
});
|
});
|
||||||
|
|
||||||
proxyRes.on('data', function(data){
|
proxyRes.on('data', function(data){
|
||||||
body = Buffer.concat([body, data]);
|
body = Buffer.concat([body, data]);
|
||||||
});
|
});
|
||||||
|
|
||||||
proxyRes.on('end', function(){
|
proxyRes.on('end', function(){
|
||||||
body = proxyRes.headers['content-encoding'] === 'gzip' ? zlib.gunzipSync(body).toString('utf8') : body;
|
// console.log("proxyRes.headers['content-encoding']", proxyRes.headers['content-encoding']);
|
||||||
body = proxyRes.headers['content-encoding'] === 'br' ? zlib.brotliDecompressSync(body).toString('utf8') : body;
|
body = proxyRes.headers['content-encoding'] === 'gzip' ? zlib.gunzipSync(body).toString('utf8') : body;
|
||||||
if(proxyRes.statusCode === 200 &&
|
body = proxyRes.headers['content-encoding'] === 'br' ? zlib.brotliDecompressSync(body).toString('utf8') : body;
|
||||||
proxyRes.headers['content-type'] &&
|
if(proxyRes.statusCode === 200 &&
|
||||||
proxyRes.headers['content-type'].match('html')
|
proxyRes.headers['content-type'] &&
|
||||||
){
|
proxyRes.headers['content-type'].match('html')
|
||||||
body = body.toString().replace(/<\s*script[^]*?script>/igm, '');
|
){
|
||||||
body = body.replace(generateRegexForDomain(proxyTarget.host), '');
|
body = body.toString().replace(/<\s*script[^]*?script>/igm, '');
|
||||||
body = body.replace(/<\s*iframe[^]*?iframe>/igm, '');
|
body = body.replace(generateRegexForDomain(proxyTarget.host), '');
|
||||||
body = body.replace("</html>", '');
|
body = body.replace(/<\s*iframe[^]*?iframe>/igm, '');
|
||||||
body = body+inject+"</html>";
|
body = body.replace("</html>", '');
|
||||||
}
|
body = body+inject+"</html>";
|
||||||
res.status(proxyRes.statusCode).end(body);
|
}
|
||||||
});
|
res.status(proxyRes.statusCode).end(body);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
@ -7,10 +7,11 @@ router.get('/', async function(req, res, next){
|
|||||||
try{
|
try{
|
||||||
res.json({results: await Torrent.findAll({
|
res.json({results: await Torrent.findAll({
|
||||||
where:{added_by: req.query.username || req.user.username},
|
where:{added_by: req.query.username || req.user.username},
|
||||||
// limit: req.query.limit,
|
limit: req.query.limit,
|
||||||
// offset: req.query.offset,
|
offset: req.query.offset,
|
||||||
// order: [[req.query.orderKey || "created_at", (req.query.asc && "ASC")]],
|
order: [
|
||||||
// from: {$between: [startDate, endDate]}
|
['createdAt', 'DESC'],
|
||||||
|
],
|
||||||
})});
|
})});
|
||||||
}catch(error){
|
}catch(error){
|
||||||
next(error);
|
next(error);
|
||||||
@ -25,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){
|
router.get('/server', async function(req, res, next){
|
||||||
try{
|
try{
|
||||||
res.json(await Torrent.trClient.sessionStats())
|
res.json(await Torrent.trClient.sessionStats())
|
||||||
@ -33,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{
|
try{
|
||||||
let torrent = await Torrent.findByPk(req.params.id);
|
let torrent = await Torrent.findByPk(req.params.hashString);
|
||||||
if('latest' in req.query){
|
if('latest' in req.query){
|
||||||
torrent = await torrent.getTorrentData();
|
torrent = await torrent.getTorrentData();
|
||||||
}
|
}
|
||||||
@ -45,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{
|
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()});
|
res.json({result: torrent, activity: await torrent.destroy()});
|
||||||
}catch(error){
|
}catch(error){
|
||||||
@ -55,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{
|
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()});
|
res.json({result: torrent, activity: await torrent.stop()});
|
||||||
}catch(error){
|
}catch(error){
|
||||||
@ -65,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{
|
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()});
|
res.json({result: torrent, activity: await torrent.start()});
|
||||||
}catch(error){
|
}catch(error){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user