Initial commit, just the basic webui layout and basic golang backend with websocket communication tested.

This commit is contained in:
2017-09-15 16:49:20 -04:00
parent 0a8bef2917
commit 5489b3d59b
26 changed files with 552 additions and 0 deletions

4
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GOROOT" path="C:\Go" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/torrent-project.iml" filepath="$PROJECT_DIR$/.idea/torrent-project.iml" />
</modules>
</component>
</project>

9
.idea/torrent-project.iml generated Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

72
main.go Normal file
View File

@@ -0,0 +1,72 @@
package main
import (
"flag"
"fmt"
"github.com/gorilla/mux"
"github.com/gorilla/websocket"
"html/template"
"log"
"net/http"
"os"
"time"
)
var (
httpAddr = flag.String("addr", ":8000", "Http server address")
baseTmpl string = "templates/base.tmpl"
APP_ID = os.Getenv("APP_ID")
APP_SECRET = os.Getenv("APP_SECRET")
)
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
}
func serveHome(w http.ResponseWriter, r *http.Request) {
s1, _ := template.ParseFiles("templates/home.tmpl")
s1.ExecuteTemplate(w, "base", map[string]string{"APP_ID": APP_ID})
}
func main() {
r := mux.NewRouter()
r.HandleFunc("/", serveHome)
http.Handle("/static/", http.FileServer(http.Dir("public")))
http.Handle("/", r)
http.HandleFunc("/websocket", func(w http.ResponseWriter, r *http.Request) {
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Println(err)
return
}
for {
msgType, msg, err := conn.ReadMessage()
if err != nil {
fmt.Println(err)
return
}
if string(msg) == "ping" {
fmt.Println("ping")
time.Sleep(2 * time.Second)
err = conn.WriteMessage(msgType, []byte("pong"))
if err != nil {
fmt.Println(err)
return
}
} else {
conn.Close()
fmt.Println(string(msg))
return
}
}
})
if err := http.ListenAndServe(*httpAddr, nil); err != nil {
log.Fatalf("Error listening, %v", err)
}
//
}

172
projectFilesBackup/.idea/workspace.xml generated Normal file
View File

@@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="057beee9-5607-4a22-8523-4af575dc8251" name="Default" comment="" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="main.go" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/main.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="459">
<caret line="27" column="4" lean-forward="false" selection-start-line="27" selection-start-column="4" selection-end-line="27" selection-end-column="4" />
<folding>
<element signature="e#14#100#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Go File" />
</list>
</option>
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/main.go" />
</list>
</option>
</component>
<component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsGulpfileManager">
<detection-done>true</detection-done>
<sorting>DEFINITION_ORDER</sorting>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="-251" />
<option name="y" value="-8" />
<option name="width" value="1934" />
<option name="height" value="1084" />
</component>
<component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1">
<flattenPackages />
<showMembers />
<showModules />
<showLibraryContents />
<hideEmptyPackages />
<abbreviatePackageNames />
<autoscrollToSource />
<autoscrollFromSource />
<sortByType />
<manualOrder />
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scratches" />
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="torrent-project" type="b2602c69:ProjectViewProjectNode" />
<item name="torrent-project" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
</panes>
</component>
<component name="PropertiesComponent">
<property name="last_opened_file_path" value="$USER_HOME$" />
<property name="go.sdk.automatically.set" value="true" />
<property name="DefaultGoTemplateProperty" value="Go File" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager" selected="Go Single File.go run main.go">
<configuration name="go run main.go" type="GoRunFileConfiguration" factoryName="Go Single File" temporary="true">
<module name="torrent-project" />
<working_directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/main.go" />
</configuration>
<recent_temporary>
<list size="1">
<item index="0" class="java.lang.String" itemvalue="Go Single File.go run main.go" />
</list>
</recent_temporary>
</component>
<component name="ShelveChangesManager" show_recycled="false">
<option name="remove_strategy" value="false" />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1096" extended-state="6" />
<layout>
<window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.25266525" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32917964" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<option name="time" value="1" />
</breakpoint-manager>
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/main.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="e#14#100#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="459">
<caret line="27" column="4" lean-forward="false" selection-start-line="27" selection-start-column="4" selection-end-line="27" selection-end-column="4" />
<folding>
<element signature="e#14#100#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
</project>

View File

@@ -0,0 +1,120 @@
* {box-sizing: border-box;}
.wrapper {
display: grid;
grid-gap: 10px;
width: 100%;
height: 100%;
background-color: #F8F9F9;
grid-template-columns: 200px 1fr;
}
.box {
background-color: #F2F3F4;
border-radius: 1px;
}
.navcolumn {
grid-column: 1;
grid-row: 2 / span 2;
border-style: double;
}
.navcolumnImage {
padding-right: 10%;
vertical-align: middle;
}
.liNavcolumn {
padding: 0;
}
.liNavcolumn:hover {
background-color: grey;
}
.navsettings {
grid-column: 1 / span 2;
grid-row: 1;
border-style: double;
max-height: 80px;
}
.imagezoom {
height: 50px;
}
.imagezoom:hover {
background-color: grey;
}
.torrentlist {
grid-column: 2;
grid-row: 2;
border-style: double;
min-height: 400px;
}
.torrentdetails {
grid-column: 2;
grid-row: 3;
border-style: double;
min-height: 100px;
}
ul.none {
list-style-type: none;
padding: 0 2% 0 0;
}
ul.navsettingsUl {
list-style-type: none;
margin: 0;
padding-left: 0;
}
li.top {
display: inline;
}
hr {
border-width: 2px;
padding: 0;
}
.verticalLine {
border-left: solid grey;
}
table {
width: 100%;
border-collapse: collapse;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
background-color: #3B83CB;
}
tr:nth-child(even) {
background-color: #dddddd;
}
.activeButton {
background-color: red;
}
.tab {
display: none;
}
.defaultTab {
display: initial;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 546 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 913 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 527 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 794 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 753 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 787 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 850 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 565 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 524 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 219 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1014 B

161
templates/home.tmpl Normal file
View File

@@ -0,0 +1,161 @@
{{define "base"}}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="/static/css/gridbase.css" type="text/css" />
<title>torrent-project</title>
<script>
function openTab(evt, tabName) {
var i, x, tablinks;
x = document.getElementsByClassName("tab");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablink");
for (i = 0; i < x.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" activeButton", "");
}
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " activeButton";
}
</script>
<script type="text/javascript">
function myWebsocketStart()
{
var ws = new WebSocket("ws://192.168.1.141:8000/websocket");
ws.onopen = function()
{
// Web Socket is connected, send data using send()
ws.send("ping");
var myTextArea = document.getElementById("loggerData");
myTextArea.innerHTML = myTextArea.innerHTML + "\n" + "First message sent";
};
ws.onmessage = function (evt)
{
var myTextArea = document.getElementById("loggerData");
myTextArea.innerHTML = myTextArea.innerHTML + "\n" + evt.data
if(evt.data == "pong") {
setTimeout(function(){ws.send("ping");}, 2000);
}
};
ws.onclose = function()
{
var myTextArea = document.getElementById("loggerData");
myTextArea.innerHTML = myTextArea.innerHTML + "\n" + "Connection closed";
};
}
</script>
</head>
<body onload="javascript:myWebsocketStart()">
<div class="wrapper">
<div class="box navcolumn">
<hr>
<ul class="none">
<li class="liNavcolumn" id="allTorrents"><img class="navcolumnImage" src="/static/images/iconTorrent.png">All Torrents</li><hr>
<li class="liNavcolumn" id="downloading"><img class="navcolumnImage" src="/static/images/iconDownload.png">Downloading</li><hr>
<li class="liNavcolumn" id="uploading"><img class="navcolumnImage" src="/static/images/iconUpload.png">Uploading</li><hr>
<li class="liNavcolumn" id="active"><img class="navcolumnImage" src="/static/images/iconActiveTorrents.png">Active</li><hr>
<li class="liNavcolumn" id="inactive"><img class="navcolumnImage" src="/static/images/iconInactiveTorrents.png">Inactive</li>
</ul>
<hr>
</div>
<div class="box navsettings">
<ul class="navsettingsUl">
<li class="top" id="addTorrent"><img class="imagezoom" src="/static/images/iconAddTorrent.png"></li>
<li class="top" id="addTorrentLink"><img class="imagezoom" src="/static/images/iconAddTorrentLink.png"></li>
<li class="top verticalLine" id="deleteTorrent"><img class="imagezoom" src="/static/images/iconDelete.png"></li>
<li class="top verticalLine" id="startTorrent"><img class="imagezoom" src="/static/images/iconStart.png"></li>
<li class="top" id="pauseTorrent"><img class="imagezoom" src="/static/images/iconPause.png"></li>
<li class="top" id="stopTorrent"><img class="imagezoom" src="/static/images/iconStop.png"></li>
<li class="top verticalLine" id="upTorrent"><img class="imagezoom" src="/static/images/iconScrollUp.png"></li>
<li class="top" id="downTorrent"><img class="imagezoom" src="/static/images/iconScrollDown.png"></li>
<li class="top verticalLine" id="rssTorrent"><img class="imagezoom" src="/static/images/iconRss.png"></li>
<li class="top verticalLine" id="settingsIcon"><img class="imagezoom" src="/static/images/iconSettings.png"></li>
</div>
<div class="box torrentlist">
<table>
<tr>
<th>Name</th>
<th>Size</th>
<th>Done</th>
<th>Status</th>
<th>Seeds</th>
<th>Peers</th>
<th>Down Speed</th>
<th>Up Speed</th>
<th>ETA</th>
<th>Ratio</th>
<th>Avail.</th>
</tr>
</table>
</div>
<div class="box torrentdetails">
<div>
<button class="tablink activeButton" onclick="openTab(event, 'General')">General</button>
<button class="tablink" onclick="openTab(event, 'Peers')">Peers</button>
<button class="tablink" onclick="openTab(event, 'Files')">Files</button>
<button class="tablink" onclick="openTab(event, 'Speed')">Speed</button>
<button class="tablink" onclick="openTab(event, 'Logger')">Logger</button>
</div>
<div id="General" class="tab defaultTab">
<h2>General</h2>
<p>General Information</p>
</div>
<div id="Peers" class="tab">
<h2>Peers</h2>
<table>
<tr>
<th>IP</th>
<th>Client</th>
<th>Flags</th>
<th>Percent</th>
<th>Down Speed</th>
<th>Up Speed</th>
<th>Reqs</th>
<th>Uploaded</th>
<th>Downloaded</th>
<th>Peer dl.</th>
</tr>
</table>
</div>
<div id="Files" class="tab">
<h2>Files</h2>
<table>
<tr>
<th>Name</th>
<th>Size</th>
<th>Done</th>
<th>Percent</th>
<th>Priority</th>
</tr>
</table>
</div>
<div id="Speed" class="tab">
<h2>Speed</h2>
<p>Speed Graph Here</p>
</div>
<div id="Logger" class="tab">
<h2>Logger</h2>
<p id="loggerData">Logger lines here</p>
</div>
</div>
</div>
</body>
<footer>Icons by <a href="https://icons8.com">icons8</a>
</html>
{{end}}