mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
174 lines
5.0 KiB
Go
174 lines
5.0 KiB
Go
package templates
|
|
|
|
import (
|
|
"server/version"
|
|
)
|
|
|
|
var cachePage = `
|
|
<!DOCTYPE html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link href="` + faviconB64 + `" rel="icon" type="image/x-icon">
|
|
<script src="/js/api.js"></script>
|
|
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
|
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
|
|
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
|
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
|
|
<title>TorrServer ` + version.Version + `</title>
|
|
</head>
|
|
<body>
|
|
<style>
|
|
.wrap {
|
|
white-space: normal;
|
|
word-wrap: break-word;
|
|
word-break: break-all;
|
|
}
|
|
.content {
|
|
margin: 1%;
|
|
}
|
|
.cache {
|
|
padding-left:6px;
|
|
padding-right:2px;
|
|
line-height:11px
|
|
}
|
|
.piece {
|
|
width:10px;
|
|
height:10px;
|
|
background-color:#eef2f4;
|
|
border:1px solid #dee2e5;
|
|
display:inline-block;
|
|
margin-right:1px
|
|
}
|
|
.piece-complete{
|
|
background-color:#b8dd69;
|
|
border-color:#b8dd69
|
|
}
|
|
.piece-loading{
|
|
background-color:#66cbff;
|
|
border-color:#66cbff
|
|
}
|
|
</style>
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
|
<a class="btn navbar-btn pull-left" href="/"><i class="fas fa-arrow-left"></i></a>
|
|
<span class="navbar-brand mx-auto">
|
|
TorrServer ` + version.Version + `
|
|
</span>
|
|
</nav>
|
|
<div class="content">
|
|
<div id="torrents"></div>
|
|
<div id="cacheInfo"></div>
|
|
<div class="cache" id="cache"></div>
|
|
</div>
|
|
<footer class="page-footer navbar-dark bg-dark">
|
|
<span class="navbar-brand d-flex justify-content-center">
|
|
<a rel="external" style="text-decoration: none;" href="/about">Описание</a>
|
|
</span>
|
|
</footer>
|
|
</body>
|
|
<script>
|
|
$( document ).ready(function() {
|
|
setInterval(updateState, 500);
|
|
});
|
|
|
|
var cacheHash = "";
|
|
var hashTorrents = "";
|
|
|
|
function updateTorrents(){
|
|
listTorrent(function(data){
|
|
var currHashTorrs = "";
|
|
for(var key in data) {
|
|
var tor = data[key];
|
|
currHashTorrs += tor.Hash;
|
|
}
|
|
if (currHashTorrs != hashTorrents){
|
|
hashTorrents = currHashTorrs;
|
|
var html = "";
|
|
html += '<div class="btn-group-vertical d-flex" role="group">';
|
|
for(var key in data) {
|
|
var tor = data[key];
|
|
html += '<button type="button" class="btn btn-secondary wrap w-100" onclick="setCache(\''+tor.Hash+'\')">'+tor.Name+'</button>';
|
|
}
|
|
html += '</div>'
|
|
$("#torrents").empty();
|
|
$(html).appendTo($("#torrents"));
|
|
}
|
|
});
|
|
}
|
|
|
|
function updateCache(){
|
|
var cache = $("#cache");
|
|
if (cacheHash!=""){
|
|
cacheTorrent(cacheHash, function(data){
|
|
var html = "";
|
|
var st = data;
|
|
html += '<span>Hash: '+st.Hash+'</span><br>';
|
|
html += '<span>Capacity: '+humanizeSize(st.Capacity)+'</span><br>';
|
|
html += '<span>Filled: '+humanizeSize(st.Filled)+'</span><br>';
|
|
html += '<span>Pieces length: '+humanizeSize(st.PiecesLength)+'</span><br>';
|
|
html += '<span>Pieces count: '+st.PiecesCount+'</span><br>';
|
|
$("#cacheInfo").html(html);
|
|
makePieces(st.PiecesCount);
|
|
for(var i = 0; i < st.PiecesCount; i++) {
|
|
var piece = st.Pieces[i];
|
|
if (piece){
|
|
if (piece.Completed && piece.BufferSize >= st.PiecesLength){
|
|
$("#p"+i).addClass("piece-complete");
|
|
$("#p"+i).removeClass("piece-loading");
|
|
}else if (!piece.Completed && piece.BufferSize > 0){
|
|
$("#p"+i).removeClass("piece-complete");
|
|
$("#p"+i).addClass("piece-loading");
|
|
}
|
|
}
|
|
if (!piece || piece.Completed && piece.BufferSize == 0){
|
|
$("#p"+i).removeClass("piece-complete");
|
|
$("#p"+i).removeClass("piece-loading");
|
|
}
|
|
}
|
|
},function(){
|
|
$("#cacheInfo").empty();
|
|
cache.empty();
|
|
});
|
|
}
|
|
}
|
|
|
|
function makePieces(len){
|
|
var cache = $("#cache");
|
|
if (cache.children().length==len)
|
|
return;
|
|
var html = "";
|
|
for(var i = 0; i < len; i++) {
|
|
html += '<span class="piece" id="p'+i+'" title="'+i+'" ></span>';
|
|
}
|
|
cache.html(html);
|
|
}
|
|
|
|
function contains(arr, elem) {
|
|
for (var i = 0; i < arr.length; i++) {
|
|
if (arr[i].Id === elem) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function updateState(){
|
|
updateTorrents();
|
|
updateCache();
|
|
}
|
|
|
|
function setCache(hash){
|
|
cacheHash = hash;
|
|
updateCache();
|
|
}
|
|
</script>
|
|
</html>
|
|
`
|
|
|
|
func (t *Template) parseCachePage() {
|
|
parsePage(t, "cachePage", cachePage)
|
|
}
|