This commit is contained in:
YouROK
2020-11-11 20:17:13 +03:00
parent 3f2bd4fa5f
commit 851e0bde57
8 changed files with 74 additions and 19 deletions

View File

@@ -1,9 +0,0 @@
package pages
import (
"github.com/gin-gonic/gin"
)
func mainPage(c *gin.Context) {
c.HTML(200, "mainPage", nil)
}

View File

@@ -0,0 +1,17 @@
package pages
import (
"github.com/gin-gonic/gin"
)
func mainPage(c *gin.Context) {
c.HTML(200, "mainPage", nil)
}
func apijsPage(c *gin.Context) {
c.HTML(200, "apijsPage", nil)
}
func mainjsPage(c *gin.Context) {
c.HTML(200, "mainjsPage", nil)
}

View File

@@ -1,8 +1,9 @@
package pages package pages
import ( import (
"github.com/gin-gonic/gin"
"server/web/pages/template" "server/web/pages/template"
"github.com/gin-gonic/gin"
) )
var temp *template.Template var temp *template.Template
@@ -11,5 +12,6 @@ func SetupRoute(route *gin.Engine) {
temp = template.InitTemplate(route) temp = template.InitTemplate(route)
route.GET("/", mainPage) route.GET("/", mainPage)
route.GET("/api.js", apijsPage)
route.GET("/main.js", mainjsPage)
} }

View File

@@ -1,6 +1,6 @@
package template package template
const apijs = ` const apiJS = `
// Torrents // Torrents
function addTorrent(link, title, poster, save, done, fail){ function addTorrent(link, title, poster, save, done, fail){
torrent("add",link,null,title,poster,save,done,fail); torrent("add",link,null,title,poster,save,done,fail);
@@ -37,10 +37,34 @@ function torrent(action, link, hash, title, poster, save, done, fail){
// //
// Settings // Settings
function getSettings(done, fail){
sendApi("get",null,"/settings",done,fail);
}
function setSettings(sets, done, fail){
sendApi("set",sets,"/settings",done,fail);
}
//
// Viewed
function listViewed(done, fail){
sendApi("list",null,"/viewed",done,fail);
}
function setViewed(hash, index, done, fail){
var obj = {"hash":hash, "file_index":index};
sendApi("set",obj,"/viewed",done,fail);
}
function remViewed(hash, index, done, fail){
var obj = {"hash":hash, "file_index":index};
sendApi("rem",obj,"/viewed",done,fail);
}
// //
function sendApi(action, obj, path, done, fail){ function sendApi(action, obj, path, done, fail){
if (obj==null)
obj={};
obj[action]=action; obj[action]=action;
var req = JSON.stringify(obj); var req = JSON.stringify(obj);
$.post(path,req) $.post(path,req)

View File

@@ -12,7 +12,7 @@ const header = `
<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://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha256-4+XzXVhsDmqanXGHaHvgh1gMQKX40OUvDEBTu8JcmNs=" crossorigin="anonymous"></script> <script src="https://code.jquery.com/jquery-3.5.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/2.5.4/umd/popper.min.js" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/2.5.4/umd/popper.min.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">

View File

@@ -13,7 +13,9 @@ const mainPage = `
<html lang="ru"> <html lang="ru">
` + header + ` ` + header + `
<body> <body>
<script src="/api.js"></script>
<script src="/main.js"></script> <script src="/main.js"></script>
<style> <style>
.wrap { .wrap {
white-space: normal; white-space: normal;

View File

@@ -1,6 +1,6 @@
package template package template
const mainjs = ` const mainJS = `
$(document).ready(function() { $(document).ready(function() {
watchInfo(); watchInfo();
}); });
@@ -8,13 +8,32 @@ $(document).ready(function() {
var lastTorrHtml = ''; var lastTorrHtml = '';
function watchInfo(){ function watchInfo(){
reloadTorrents();
setInterval(function() { setInterval(function() {
}, 1000); }, 1000);
} }
function reloadTorretns(){
var torrents = $("#torrents");
torrents.empty();
}
function loadTorrentInfoHtml(){ function loadTorrentInfoHtml(){
} }
const torrElem =
`
var torrElem = `"""
<div class="btn-group d-flex" role="group">
<button type="button" class="btn btn-secondary wrap w-100" data-toggle="collapse" data-target="#info_'+tor.Hash+'"></button>';
<a role="button" class="btn btn-secondary" href="'+tor.Playlist+'"><i class="fas fa-th-list"></i> Плейлист</a>';
<button type="button" class="btn btn-secondary"><i class="fas fa-info"></i></a>';
<button type="button" class="btn btn-secondary"><i class="fas fa-trash-alt"></i> Удалить</button>';
</div>
"""
` `

View File

@@ -33,10 +33,10 @@ type Template struct {
func InitTemplate(c *gin.Engine) *Template { func InitTemplate(c *gin.Engine) *Template {
temp := new(Template) temp := new(Template)
temp.parseMainPage() temp.parsePage("mainPage", mainPage)
// temp.parseSettingsPage() temp.parsePage("apijsPage", apiJS)
// temp.parseAboutPage() temp.parsePage("mainjsPage", mainJS)
// temp.parseCachePage()
c.SetHTMLTemplate(temp.templates) c.SetHTMLTemplate(temp.templates)
return temp return temp
} }