Add webserver (using gin) to socialdragon

This commit is contained in:
Marvin Scholz 2017-01-18 19:47:55 +01:00
parent 8a88af39a2
commit 9f03313d60
8 changed files with 4373 additions and 0 deletions

View file

4148
socialdragon/assets/css/foundation.css vendored Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 KiB

View file

@ -0,0 +1 @@
$(document).foundation()

View file

@ -1,11 +1,15 @@
package main
import (
"io"
"os"
"os/signal"
"syscall"
"golang.org/x/net/websocket"
"github.com/robfig/cron"
"gopkg.in/gin-gonic/gin.v1"
"git.1750studios.com/AniNite/SocialDragon/config"
"git.1750studios.com/AniNite/SocialDragon/database"
@ -27,7 +31,31 @@ func main() {
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
go setupGin()
<-ch
twitter.Stop()
}
func setupGin() {
router := gin.Default()
router.GET("/home", renderHomepage)
router.GET("/ws", websocketEndpoint)
router.LoadHTMLGlob("templates/*")
router.Static("/static", "assets")
router.Run("127.0.0.1:8000")
}
func renderHomepage(ctx *gin.Context) {
ctx.HTML(200, "index.html", gin.H{"title": "Main website"})
}
func websocketEndpoint(ctx *gin.Context) {
handler := websocket.Handler(echoHandler)
handler.ServeHTTP(ctx.Writer, ctx.Request)
}
func echoHandler(ws *websocket.Conn) {
websocket.Message.Send(ws, "Test Message from Server")
io.Copy(ws, ws)
}

View file

@ -0,0 +1,65 @@
<!doctype html>
<html class="no-js" lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Snapchat Wall Admin</title>
<meta http-equiv="refresh" content="30">
<link rel="stylesheet" href="/static/css/foundation.css">
<link rel="stylesheet" href="/static/css/app.css">
<script>
function httpGetAsync(theUrl, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
function approveSnap(myself) {
function cb(success) {
if (success == "True") {
myself.parentNode.removeChild(myself);
} else {
alert("Failed!");
}
}
url = myself.src;
filename = url.substring(url.lastIndexOf('/')+1);
if (confirm("Approve this snap?")) {
httpGetAsync("/admin/snap/approve?filename=" + filename, cb);
} else {
httpGetAsync("/admin/snap/reject?filename=" + filename, cb);
}
}
</script>
</head>
<body>
<div class="row">
<div class="large-12 columns">
<h1>Snapchat Wall &middot; Admin</h1>
<ul class="menu">
<li class="active"><a>Inbox</a></li>
<li><a>Approved</a></li>
<li><a>Rejected</a></li>
</ul>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<div class="callout">
<p>Click on snap to review:</p>
<img style="width: 30%; min-width: 15em;" onclick="approveSnap(this)" class="thumbnail" src="/snaps/inbox/IMAGE_HERE" alt="" />
</div>
</div>
</div>
<script src="/static/js/vendor/jquery.js"></script>
<script src="/static/js/vendor/what-input.js"></script>
<script src="/static/js/vendor/foundation.js"></script>
<script src="/static/js/app.js"></script>
</body>
</html>

129
socialdragon/templates/index.html Executable file
View file

@ -0,0 +1,129 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Snapchat Wall</title>
<style type="text/css">
@import 'https://fonts.googleapis.com/css?family=Roboto';
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
font-family: Roboto, "Lucida Sans Unicode", "Lucida Grande", sans-serif;
color: #FFF;
text-transform: uppercase;
background: url('/static/img/bg.gif') 50% 0 no-repeat fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#left {
/*min-width:40%;*/
width:100%;
height:100%;
float:left;
}
#right {
float:right;
width:42%;
overflow:hidden;
height:600px;
margin-top:auto;
margin-bottom:auto;
padding-top:7%;
padding-right:4%;
text-align:center;
}
#image {
vertical-align: middle;
margin-top: 0;
max-width: 100%;
overflow: hidden;
height: 100%;
}
h1 {
font-size: 60px;
}
#infotext {
font-size: 30px;
}
#othertext {
font-size: 26px;
}
</style>
</head>
<body>
<div id="left">
<div id="image">
<center>
<img style="max-height: 100%; background: green; display: inline-block; vertical-align: middle;" id="snapwall_image" src="/snaps/approved/IMAGE_HERE" alt="" />
</center>
</div>
</div><!--
<div id="right">
<div id="infos">
<center><h1>Social Wall</h1></center>
<br /><br />
<div id="infotext">
</div>
<div id="othertext">
Other text...<br />
</div>
</div>
</div>-->
<div style="clear:both"></div>
<script type="text/javascript">
var exampleSocket = new WebSocket("ws://127.0.0.1:8000/ws");
exampleSocket.onopen = function (event) {
console.log("WS: Connection open!");
console.log("Proto: " + exampleSocket.protocol);
exampleSocket.send("Here's some text that the server is urgently awaiting!");
};
exampleSocket.onmessage = function (event) {
console.log("WS Message:");
console.log(event.data);
}
</script>
<script type="text/javascript">
/*
var currentImage;
function HTTPGetRequest() {
if (!window.XMLHttpRequest) {
return;
}
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var parts = xmlhttp.responseText.split(" ");
if(parts[0] == "l") { // landscape pic
document.getElementById("image").style.marginTop = '-140px';
document.getElementById("left").style.paddingLeft = '1%';
document.getElementById("left").style.minWidth = '52%';
} else if(parts[0] == "p") { // portrait pic
document.getElementById("image").style.marginTop = '0px';
}
if(parts[1] != currentImage) { // if new image different from current image
document.getElementById("snapwall_image").src = parts[1];
currentImage = xmlhttp.responseText;
}
}
}
xmlhttp.open("GET","image.txt",true);
xmlhttp.send();
}
setInterval(function() {
HTTPGetRequest();
}, 7000); // 7 seconds
*/
</script>
</body>
</html>