mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Add static files, encryption
This commit is contained in:
parent
21cd7d092c
commit
5a923ae11a
51
main.go
51
main.go
@ -5,12 +5,14 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/gin-contrib/static"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
router.LoadHTMLGlob("templates/*")
|
router.LoadHTMLGlob("templates/*")
|
||||||
|
router.Use(static.Serve("/static/", static.LocalFile("./static", true)))
|
||||||
|
|
||||||
router.GET("/", func(c *gin.Context) {
|
router.GET("/", func(c *gin.Context) {
|
||||||
c.Redirect(302, "/"+randomAlliterateCombo())
|
c.Redirect(302, "/"+randomAlliterateCombo())
|
||||||
@ -23,6 +25,7 @@ func main() {
|
|||||||
router.POST("/update", handlePageUpdate)
|
router.POST("/update", handlePageUpdate)
|
||||||
router.POST("/prime", handlePrime)
|
router.POST("/prime", handlePrime)
|
||||||
router.POST("/lock", handleLock)
|
router.POST("/lock", handleLock)
|
||||||
|
router.POST("/encrypt", handleEncrypt)
|
||||||
|
|
||||||
router.Run(":8050")
|
router.Run(":8050")
|
||||||
}
|
}
|
||||||
@ -78,13 +81,17 @@ func handlePageUpdate(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
log.Trace("Update: %v", json)
|
log.Trace("Update: %v", json)
|
||||||
p := Open(json.Page)
|
p := Open(json.Page)
|
||||||
if !p.IsLocked {
|
var message string
|
||||||
|
if p.IsLocked {
|
||||||
|
message = "Locked"
|
||||||
|
} else if p.IsEncrypted {
|
||||||
|
message = "Encrypted"
|
||||||
|
} else {
|
||||||
p.Update(json.NewText)
|
p.Update(json.NewText)
|
||||||
p.Save()
|
p.Save()
|
||||||
c.JSON(http.StatusOK, gin.H{"success": true, "message": "Saved"})
|
message = "Saved"
|
||||||
} else {
|
|
||||||
c.JSON(http.StatusOK, gin.H{"success": false, "message": "Locked"})
|
|
||||||
}
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{"success": false, "message": message})
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePrime(c *gin.Context) {
|
func handlePrime(c *gin.Context) {
|
||||||
@ -132,3 +139,39 @@ func handleLock(c *gin.Context) {
|
|||||||
p.Save()
|
p.Save()
|
||||||
c.JSON(http.StatusOK, gin.H{"success": true, "message": message})
|
c.JSON(http.StatusOK, gin.H{"success": true, "message": message})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleEncrypt(c *gin.Context) {
|
||||||
|
type QueryJSON struct {
|
||||||
|
Page string `json:"page"`
|
||||||
|
Passphrase string `json:"passphrase"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var json QueryJSON
|
||||||
|
if c.BindJSON(&json) != nil {
|
||||||
|
c.String(http.StatusBadRequest, "Problem binding keys")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p := Open(json.Page)
|
||||||
|
var message string
|
||||||
|
if p.IsEncrypted {
|
||||||
|
decrypted, err2 := DecryptString(p.Text.GetCurrent(), json.Passphrase)
|
||||||
|
if err2 != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"success": false, "message": "Wrong password"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p.IsEncrypted = false
|
||||||
|
p.Erase()
|
||||||
|
p = Open(json.Page)
|
||||||
|
p.Update(decrypted)
|
||||||
|
message = "Decrypted"
|
||||||
|
} else {
|
||||||
|
p.IsEncrypted = true
|
||||||
|
p.Erase()
|
||||||
|
p = Open(json.Page)
|
||||||
|
encrypted, _ := EncryptString(p.Text.GetCurrent(), json.Passphrase)
|
||||||
|
p.Update(encrypted)
|
||||||
|
message = "Encrypted"
|
||||||
|
}
|
||||||
|
p.Save()
|
||||||
|
c.JSON(http.StatusOK, gin.H{"success": true, "message": message})
|
||||||
|
}
|
||||||
|
11
static/css/base-min.css
vendored
Normal file
11
static/css/base-min.css
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/*!
|
||||||
|
Pure v0.6.2
|
||||||
|
Copyright 2013 Yahoo!
|
||||||
|
Licensed under the BSD License.
|
||||||
|
https://github.com/yahoo/pure/blob/master/LICENSE.md
|
||||||
|
*/
|
||||||
|
/*!
|
||||||
|
normalize.css v^3.0 | MIT License | git.io/normalize
|
||||||
|
Copyright (c) Nicolas Gallagher and Jonathan Neal
|
||||||
|
*/
|
||||||
|
/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */img,legend{border:0}legend,td,th{padding:0}html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,optgroup,strong{font-weight:700}dfn{font-style:italic}h1{font-size:2em;margin:.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-.5em}sub{bottom:-.25em}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{box-sizing:content-box;height:0}pre,textarea{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type=button],input[type=reset],input[type=submit]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input{line-height:normal}input[type=checkbox],input[type=radio]{box-sizing:border-box;padding:0}input[type=number]::-webkit-inner-spin-button,input[type=number]::-webkit-outer-spin-button{height:auto}input[type=search]{-webkit-appearance:textfield;box-sizing:content-box}input[type=search]::-webkit-search-cancel-button,input[type=search]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}table{border-collapse:collapse;border-spacing:0}.hidden,[hidden]{display:none!important}.pure-img{max-width:100%;height:auto;display:block}
|
1
static/css/github-markdown.css
Normal file
1
static/css/github-markdown.css
Normal file
File diff suppressed because one or more lines are too long
7
static/css/menus-min.css
vendored
Normal file
7
static/css/menus-min.css
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
/*!
|
||||||
|
Pure v0.6.2
|
||||||
|
Copyright 2013 Yahoo!
|
||||||
|
Licensed under the BSD License.
|
||||||
|
https://github.com/yahoo/pure/blob/master/LICENSE.md
|
||||||
|
*/
|
||||||
|
.pure-menu{box-sizing:border-box}.pure-menu-fixed{position:fixed;left:0;top:0;z-index:3}.pure-menu-item,.pure-menu-list{position:relative}.pure-menu-list{list-style:none;margin:0;padding:0}.pure-menu-item{padding:0;margin:0;height:100%}.pure-menu-heading,.pure-menu-link{display:block;text-decoration:none;white-space:nowrap}.pure-menu-horizontal{width:100%;white-space:nowrap}.pure-menu-horizontal .pure-menu-list{display:inline-block}.pure-menu-horizontal .pure-menu-heading,.pure-menu-horizontal .pure-menu-item,.pure-menu-horizontal .pure-menu-separator{display:inline-block;zoom:1;vertical-align:middle}.pure-menu-item .pure-menu-item{display:block}.pure-menu-children{display:none;position:absolute;left:100%;top:0;margin:0;padding:0;z-index:3}.pure-menu-horizontal .pure-menu-children{left:0;top:auto;width:inherit}.pure-menu-active>.pure-menu-children,.pure-menu-allow-hover:hover>.pure-menu-children{display:block;position:absolute}.pure-menu-has-children>.pure-menu-link:after{padding-left:.5em;content:"\25B8";font-size:small}.pure-menu-horizontal .pure-menu-has-children>.pure-menu-link:after{content:"\25BE"}.pure-menu-scrollable{overflow-y:scroll;overflow-x:hidden}.pure-menu-scrollable .pure-menu-list{display:block}.pure-menu-horizontal.pure-menu-scrollable .pure-menu-list{display:inline-block}.pure-menu-horizontal.pure-menu-scrollable{white-space:nowrap;overflow-y:hidden;overflow-x:auto;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;padding:.5em 0}.pure-menu-horizontal.pure-menu-scrollable::-webkit-scrollbar{display:none}.pure-menu-horizontal .pure-menu-children .pure-menu-separator,.pure-menu-separator{background-color:#ccc;height:1px;margin:.3em 0}.pure-menu-horizontal .pure-menu-separator{width:1px;height:1.3em;margin:0 .3em}.pure-menu-horizontal .pure-menu-children .pure-menu-separator{display:block;width:auto}.pure-menu-heading{text-transform:uppercase;color:#565d64}.pure-menu-link{color:#777}.pure-menu-children{background-color:#fff}.pure-menu-disabled,.pure-menu-heading,.pure-menu-link{padding:.5em 1em}.pure-menu-disabled{opacity:.5}.pure-menu-disabled .pure-menu-link:hover{background-color:transparent}.pure-menu-active>.pure-menu-link,.pure-menu-link:focus,.pure-menu-link:hover{background-color:#eee}.pure-menu-selected .pure-menu-link,.pure-menu-selected .pure-menu-link:visited{color:#000}
|
9472
static/js/jquery-1.8.3.js
vendored
Normal file
9472
static/js/jquery-1.8.3.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -5,10 +5,10 @@
|
|||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
|
||||||
<script type="text/javascript" src="//code.jquery.com/jquery-1.8.3.js"></script>
|
<script type="text/javascript" src="/static/js/jquery-1.8.3.js"></script>
|
||||||
<link rel="stylesheet" type="text/css" href="https://sindresorhus.com/github-markdown-css/github-markdown.css">
|
<link rel="stylesheet" type="text/css" href="/static/css/github-markdown.css">
|
||||||
<link rel="stylesheet" type="text/css" href="https://unpkg.com/purecss@0.6.2/build/menus-min.css">
|
<link rel="stylesheet" type="text/css" href="/static/css/menus-min.css">
|
||||||
<link rel="stylesheet" type="text/css" href="https://unpkg.com/purecss@0.6.2/build/base-min.css">
|
<link rel="stylesheet" type="text/css" href="/static/css/base-min.css">
|
||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
body {
|
body {
|
||||||
@ -162,6 +162,7 @@
|
|||||||
}),
|
}),
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$('#saveEditButton').text(data.message);
|
$('#saveEditButton').text(data.message);
|
||||||
|
window.location = "/{{ .Page }}/view";
|
||||||
},
|
},
|
||||||
error: function(xhr, error) {
|
error: function(xhr, error) {
|
||||||
$('#saveEditButton').text(error);
|
$('#saveEditButton').text(error);
|
||||||
@ -229,11 +230,11 @@
|
|||||||
<li class="pure-menu-item {{ with .EditPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/edit" class="pure-menu-link"><span id="saveEditButton">Edit</span></a></li>
|
<li class="pure-menu-item {{ with .EditPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/edit" class="pure-menu-link"><span id="saveEditButton">Edit</span></a></li>
|
||||||
<li class="pure-menu-item {{ with .ViewPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/view" class="pure-menu-link">View</a></li>
|
<li class="pure-menu-item {{ with .ViewPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/view" class="pure-menu-link">View</a></li>
|
||||||
<li class="pure-menu-item {{ with .ListPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/list" class="pure-menu-link">List</a></li>
|
<li class="pure-menu-item {{ with .ListPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/list" class="pure-menu-link">List</a></li>
|
||||||
|
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="encryptPage">{{ if .IsEncrypted }}Decrypt{{ else }}Encrypt{{end}}</a></li>
|
||||||
|
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="lockPage">{{ if .IsLocked }}Unlock{{ else }}Lock{{end}}</a></li>
|
||||||
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover">
|
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover">
|
||||||
<a href="#" id="menuLink1" class="pure-menu-link">Other</a>
|
<a href="#" id="menuLink1" class="pure-menu-link">Other</a>
|
||||||
<ul class="pure-menu-children">
|
<ul class="pure-menu-children">
|
||||||
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="encryptPage">Encrypt</a></li>
|
|
||||||
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="lockPage">{{ if .IsLocked }}Unlock{{ else }}Lock{{end}}</a></li>
|
|
||||||
<li class="pure-menu-item"><a href="/{{ .Page }}/history" class="pure-menu-link">History</a></li>
|
<li class="pure-menu-item"><a href="/{{ .Page }}/history" class="pure-menu-link">History</a></li>
|
||||||
<hr>
|
<hr>
|
||||||
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="selfDestructPage">Self-destruct</a></li>
|
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="selfDestructPage">Self-destruct</a></li>
|
||||||
@ -246,7 +247,7 @@
|
|||||||
|
|
||||||
<div id="wrap">
|
<div id="wrap">
|
||||||
{{ if .ViewPage }} {{ .RenderedPage }} {{ end }}
|
{{ if .ViewPage }} {{ .RenderedPage }} {{ end }}
|
||||||
{{ if .EditPage }} <textarea id="userInput">{{ .RawPage }}</textarea>{{ end }}
|
{{ if .EditPage }} <textarea autofocus placeholder="Start typing, it will save automatically." id="userInput">{{ .RawPage }}</textarea>{{ end }}
|
||||||
{{ if .HistoryPage }}
|
{{ if .HistoryPage }}
|
||||||
<ul>
|
<ul>
|
||||||
{{range .Versions}}
|
{{range .Versions}}
|
||||||
|
Loading…
Reference in New Issue
Block a user