This commit is contained in:
parent
d7e9865c91
commit
342a4d1d7c
@ -3,9 +3,7 @@
|
|||||||
# Fast Pastebin
|
# Fast Pastebin
|
||||||
|
|
||||||
Easy-to-use-and-install pastebin software written in Go. No bells or
|
Easy-to-use-and-install pastebin software written in Go. No bells or
|
||||||
whistles, no websockets and even NO JAVASCRIPT!(*)
|
whistles, no websockets and even NO JAVASCRIPT!
|
||||||
|
|
||||||
(*) Except fontawesome, because it's awesome :).
|
|
||||||
|
|
||||||
# Current functionality.
|
# Current functionality.
|
||||||
|
|
||||||
|
@ -27,11 +27,10 @@ package http
|
|||||||
import (
|
import (
|
||||||
// stdlib
|
// stdlib
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
|
||||||
// local
|
// local
|
||||||
"github.com/pztrn/fastpastebin/api/http/static"
|
|
||||||
"github.com/pztrn/fastpastebin/captcha"
|
"github.com/pztrn/fastpastebin/captcha"
|
||||||
|
"github.com/pztrn/fastpastebin/templater"
|
||||||
|
|
||||||
// other
|
// other
|
||||||
"github.com/alecthomas/chroma/lexers"
|
"github.com/alecthomas/chroma/lexers"
|
||||||
@ -40,11 +39,6 @@ import (
|
|||||||
|
|
||||||
// Index of this site.
|
// Index of this site.
|
||||||
func indexGet(ec echo.Context) error {
|
func indexGet(ec echo.Context) error {
|
||||||
htmlRaw, err := static.ReadFile("index.html")
|
|
||||||
if err != nil {
|
|
||||||
return ec.String(http.StatusNotFound, "index.html wasn't found!")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate list of available languages to highlight.
|
// Generate list of available languages to highlight.
|
||||||
availableLexers := lexers.Names(false)
|
availableLexers := lexers.Names(false)
|
||||||
|
|
||||||
@ -53,11 +47,10 @@ func indexGet(ec echo.Context) error {
|
|||||||
availableLexersSelectOpts += "<option value='" + availableLexers[i] + "'>" + availableLexers[i] + "</option>"
|
availableLexersSelectOpts += "<option value='" + availableLexers[i] + "'>" + availableLexers[i] + "</option>"
|
||||||
}
|
}
|
||||||
|
|
||||||
html := strings.Replace(string(htmlRaw), "{lexers}", availableLexersSelectOpts, 1)
|
|
||||||
|
|
||||||
// Captcha.
|
// Captcha.
|
||||||
captchaString := captcha.NewCaptcha()
|
captchaString := captcha.NewCaptcha()
|
||||||
html = strings.Replace(html, "{captchaString}", captchaString, -1)
|
|
||||||
|
|
||||||
return ec.HTML(http.StatusOK, html)
|
htmlData := templater.GetTemplate(ec, "index.html", map[string]string{"lexers": availableLexersSelectOpts, "captchaString": captchaString})
|
||||||
|
|
||||||
|
return ec.HTML(http.StatusOK, htmlData)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Code generated by fileb0x at "2018-05-18 22:25:13.180720675 +0500 +05 m=+0.030971779" from config file "fileb0x.yml" DO NOT EDIT.
|
// Code generated by fileb0x at "2018-05-26 13:49:35.047444828 +0500 +05 m=+0.010624405" from config file "fileb0x.yml" DO NOT EDIT.
|
||||||
// modification hash(1679c5529785a2e624071b2679319ecb.608888160ddb195ed89fce5ab290ff92)
|
// modification hash(1e92ae0f57fceda0c71705d184cfd4d6.522a9cc525fa984df98098d4c3992752)
|
||||||
|
|
||||||
package static
|
package static
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Code generaTed by fileb0x at "2018-05-01 18:35:23.702577304 +0500 +05 m=+0.047872409" from config file "fileb0x.yml" DO NOT EDIT.
|
// Code generaTed by fileb0x at "2018-05-26 13:29:06.05698436 +0500 +05 m=+0.013970976" from config file "fileb0x.yml" DO NOT EDIT.
|
||||||
// modified(2018-05-01 18:35:02 +0500 +05)
|
// modified(2018-05-26 13:29:04.002355958 +0500 +05)
|
||||||
// original path: assets/error.html
|
// original path: assets/error.html
|
||||||
|
|
||||||
package static
|
package static
|
||||||
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// FileErrorHTML is "/error.html"
|
// FileErrorHTML is "/error.html"
|
||||||
var FileErrorHTML = []byte("\x3c\x21\x44\x4f\x43\x54\x59\x50\x45\x20\x68\x74\x6d\x6c\x3e\x0a\x3c\x68\x74\x6d\x6c\x3e\x0a\x0a\x3c\x68\x65\x61\x64\x3e\x0a\x20\x20\x20\x20\x3c\x6d\x65\x74\x61\x20\x63\x68\x61\x72\x73\x65\x74\x3d\x22\x75\x74\x66\x2d\x38\x22\x3e\x0a\x20\x20\x20\x20\x3c\x6d\x65\x74\x61\x20\x6e\x61\x6d\x65\x3d\x22\x76\x69\x65\x77\x70\x6f\x72\x74\x22\x20\x63\x6f\x6e\x74\x65\x6e\x74\x3d\x22\x77\x69\x64\x74\x68\x3d\x64\x65\x76\x69\x63\x65\x2d\x77\x69\x64\x74\x68\x2c\x20\x69\x6e\x69\x74\x69\x61\x6c\x2d\x73\x63\x61\x6c\x65\x3d\x31\x22\x3e\x0a\x20\x20\x20\x20\x3c\x74\x69\x74\x6c\x65\x3e\x46\x61\x73\x74\x20\x50\x61\x73\x74\x65\x20\x42\x69\x6e\x20\x2d\x20\x45\x52\x52\x4f\x52\x21\x3c\x2f\x74\x69\x74\x6c\x65\x3e\x0a\x20\x20\x20\x20\x3c\x6c\x69\x6e\x6b\x20\x72\x65\x6c\x3d\x22\x73\x74\x79\x6c\x65\x73\x68\x65\x65\x74\x22\x20\x68\x72\x65\x66\x3d\x22\x2f\x73\x74\x61\x74\x69\x63\x2f\x63\x73\x73\x2f\x62\x75\x6c\x6d\x61\x2d\x30\x2e\x37\x2e\x30\x2e\x6d\x69\x6e\x2e\x63\x73\x73\x22\x3e\x0a\x20\x20\x20\x20\x3c\x73\x63\x72\x69\x70\x74\x20\x64\x65\x66\x65\x72\x20\x73\x72\x63\x3d\x22\x2f\x73\x74\x61\x74\x69\x63\x2f\x6a\x73\x2f\x66\x6f\x6e\x74\x61\x77\x65\x73\x6f\x6d\x65\x2d\x35\x2e\x30\x2e\x37\x2e\x6a\x73\x22\x3e\x3c\x2f\x73\x63\x72\x69\x70\x74\x3e\x0a\x20\x20\x20\x20\x3c\x6c\x69\x6e\x6b\x20\x72\x65\x6c\x3d\x22\x73\x74\x79\x6c\x65\x73\x68\x65\x65\x74\x22\x20\x68\x72\x65\x66\x3d\x22\x2f\x73\x74\x61\x74\x69\x63\x2f\x63\x73\x73\x2f\x73\x74\x79\x6c\x65\x2e\x63\x73\x73\x22\x3e\x0a\x3c\x2f\x68\x65\x61\x64\x3e\x0a\x0a\x3c\x62\x6f\x64\x79\x3e\x0a\x20\x20\x20\x20\x3c\x6e\x61\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x20\x69\x73\x2d\x64\x61\x72\x6b\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x62\x72\x61\x6e\x64\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x61\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x69\x74\x65\x6d\x22\x20\x68\x72\x65\x66\x3d\x22\x2f\x22\x3e\x46\x61\x73\x74\x20\x50\x61\x73\x74\x65\x20\x42\x69\x6e\x3c\x2f\x61\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x61\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x69\x74\x65\x6d\x22\x20\x68\x72\x65\x66\x3d\x22\x2f\x70\x61\x73\x74\x65\x73\x2f\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x50\x61\x73\x74\x65\x73\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x61\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x62\x75\x72\x67\x65\x72\x20\x62\x75\x72\x67\x65\x72\x22\x20\x64\x61\x74\x61\x2d\x74\x61\x72\x67\x65\x74\x3d\x22\x6e\x61\x76\x62\x61\x72\x49\x74\x65\x6d\x73\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x73\x70\x61\x6e\x3e\x3c\x2f\x73\x70\x61\x6e\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x73\x70\x61\x6e\x3e\x3c\x2f\x73\x70\x61\x6e\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x73\x70\x61\x6e\x3e\x3c\x2f\x73\x70\x61\x6e\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x69\x64\x3d\x22\x6e\x61\x76\x62\x61\x72\x49\x74\x65\x6d\x73\x22\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x6d\x65\x6e\x75\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x73\x74\x61\x72\x74\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x65\x6e\x64\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x3c\x2f\x6e\x61\x76\x3e\x0a\x20\x20\x20\x20\x3c\x73\x65\x63\x74\x69\x6f\x6e\x20\x63\x6c\x61\x73\x73\x3d\x22\x73\x65\x63\x74\x69\x6f\x6e\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x70\x3e\x7b\x65\x72\x72\x6f\x72\x7d\x3c\x2f\x70\x3e\x0a\x20\x20\x20\x20\x3c\x2f\x73\x65\x63\x74\x69\x6f\x6e\x3e\x0a\x3c\x2f\x62\x6f\x64\x79\x3e\x0a\x0a\x3c\x2f\x68\x74\x6d\x6c\x3e")
|
var FileErrorHTML = []byte("\x3c\x73\x65\x63\x74\x69\x6f\x6e\x20\x63\x6c\x61\x73\x73\x3d\x22\x73\x65\x63\x74\x69\x6f\x6e\x22\x3e\x0a\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x62\x6f\x78\x20\x68\x61\x73\x2d\x62\x61\x63\x6b\x67\x72\x6f\x75\x6e\x64\x2d\x77\x61\x72\x6e\x69\x6e\x67\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x70\x3e\x7b\x65\x72\x72\x6f\x72\x7d\x3c\x2f\x70\x3e\x0a\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x3c\x2f\x73\x65\x63\x74\x69\x6f\x6e\x3e")
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
|
35
api/http/static/b0xfile__footer.html.go
Normal file
35
api/http/static/b0xfile__footer.html.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Code generaTed by fileb0x at "2018-05-26 12:55:42.087956217 +0500 +05 m=+0.009637095" from config file "fileb0x.yml" DO NOT EDIT.
|
||||||
|
// modified(2018-05-26 12:54:22.9990735 +0500 +05)
|
||||||
|
// original path: assets/footer.html
|
||||||
|
|
||||||
|
package static
|
||||||
|
|
||||||
|
import (
|
||||||
|
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FileFooterHTML is "/footer.html"
|
||||||
|
var FileFooterHTML = []byte("\x3c\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x63\x6f\x6e\x74\x61\x69\x6e\x65\x72\x22\x3e\x0a\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x63\x6f\x6e\x74\x65\x6e\x74\x20\x68\x61\x73\x2d\x74\x65\x78\x74\x2d\x63\x65\x6e\x74\x65\x72\x65\x64\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x70\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x73\x74\x72\x6f\x6e\x67\x3e\x46\x61\x73\x74\x20\x70\x61\x73\x74\x65\x20\x62\x69\x6e\x3c\x2f\x73\x74\x72\x6f\x6e\x67\x3e\x20\x76\x65\x72\x73\x69\x6f\x6e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x73\x74\x72\x6f\x6e\x67\x3e\x7b\x76\x65\x72\x73\x69\x6f\x6e\x7d\x3c\x2f\x73\x74\x72\x6f\x6e\x67\x3e\x20\x62\x79\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x61\x20\x68\x72\x65\x66\x3d\x22\x68\x74\x74\x70\x73\x3a\x2f\x2f\x70\x7a\x74\x72\x6e\x2e\x6e\x61\x6d\x65\x22\x3e\x53\x74\x61\x6e\x69\x73\x6c\x61\x76\x20\x4e\x2e\x20\x61\x6b\x61\x20\x70\x7a\x74\x72\x6e\x3c\x2f\x61\x3e\x2e\x20\x54\x68\x65\x20\x73\x6f\x75\x72\x63\x65\x20\x63\x6f\x64\x65\x20\x69\x73\x20\x6c\x69\x63\x65\x6e\x73\x65\x64\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x61\x20\x68\x72\x65\x66\x3d\x22\x68\x74\x74\x70\x3a\x2f\x2f\x6f\x70\x65\x6e\x73\x6f\x75\x72\x63\x65\x2e\x6f\x72\x67\x2f\x6c\x69\x63\x65\x6e\x73\x65\x73\x2f\x6d\x69\x74\x2d\x6c\x69\x63\x65\x6e\x73\x65\x2e\x70\x68\x70\x22\x3e\x4d\x49\x54\x3c\x2f\x61\x3e\x2e\x20\x47\x65\x74\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x61\x20\x68\x72\x65\x66\x3d\x22\x68\x74\x74\x70\x73\x3a\x2f\x2f\x67\x69\x74\x68\x75\x62\x2e\x63\x6f\x6d\x2f\x70\x7a\x74\x72\x6e\x2f\x66\x61\x73\x74\x70\x61\x73\x74\x65\x62\x69\x6e\x22\x3e\x73\x6f\x75\x72\x63\x65\x20\x6f\x72\x20\x62\x69\x6e\x61\x72\x79\x20\x72\x65\x6c\x65\x61\x73\x65\x73\x20\x68\x65\x72\x65\x3c\x2f\x61\x3e\x21\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x70\x3e\x0a\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x3c\x2f\x64\x69\x76\x3e")
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
|
||||||
|
|
||||||
|
f, err := FS.OpenFile(CTX, "/footer.html", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_, err = f.Write(FileFooterHTML)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
35
api/http/static/b0xfile__main.html.go
Normal file
35
api/http/static/b0xfile__main.html.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Code generaTed by fileb0x at "2018-05-26 12:42:22.452857215 +0500 +05 m=+0.054711585" from config file "fileb0x.yml" DO NOT EDIT.
|
||||||
|
// modified(2018-05-26 12:41:36.015758918 +0500 +05)
|
||||||
|
// original path: assets/main.html
|
||||||
|
|
||||||
|
package static
|
||||||
|
|
||||||
|
import (
|
||||||
|
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FileMainHTML is "/main.html"
|
||||||
|
var FileMainHTML = []byte("\x3c\x21\x44\x4f\x43\x54\x59\x50\x45\x20\x68\x74\x6d\x6c\x3e\x0a\x3c\x68\x74\x6d\x6c\x3e\x0a\x0a\x3c\x68\x65\x61\x64\x3e\x0a\x20\x20\x20\x20\x3c\x6d\x65\x74\x61\x20\x63\x68\x61\x72\x73\x65\x74\x3d\x22\x75\x74\x66\x2d\x38\x22\x3e\x0a\x20\x20\x20\x20\x3c\x6d\x65\x74\x61\x20\x6e\x61\x6d\x65\x3d\x22\x76\x69\x65\x77\x70\x6f\x72\x74\x22\x20\x63\x6f\x6e\x74\x65\x6e\x74\x3d\x22\x77\x69\x64\x74\x68\x3d\x64\x65\x76\x69\x63\x65\x2d\x77\x69\x64\x74\x68\x2c\x20\x69\x6e\x69\x74\x69\x61\x6c\x2d\x73\x63\x61\x6c\x65\x3d\x31\x22\x3e\x0a\x20\x20\x20\x20\x3c\x74\x69\x74\x6c\x65\x3e\x46\x61\x73\x74\x20\x50\x61\x73\x74\x65\x20\x42\x69\x6e\x3c\x2f\x74\x69\x74\x6c\x65\x3e\x0a\x20\x20\x20\x20\x3c\x6c\x69\x6e\x6b\x20\x72\x65\x6c\x3d\x22\x73\x74\x79\x6c\x65\x73\x68\x65\x65\x74\x22\x20\x68\x72\x65\x66\x3d\x22\x2f\x73\x74\x61\x74\x69\x63\x2f\x63\x73\x73\x2f\x62\x75\x6c\x6d\x61\x2d\x30\x2e\x37\x2e\x30\x2e\x6d\x69\x6e\x2e\x63\x73\x73\x22\x3e\x0a\x20\x20\x20\x20\x3c\x6c\x69\x6e\x6b\x20\x72\x65\x6c\x3d\x22\x73\x74\x79\x6c\x65\x73\x68\x65\x65\x74\x22\x20\x68\x72\x65\x66\x3d\x22\x2f\x73\x74\x61\x74\x69\x63\x2f\x63\x73\x73\x2f\x62\x75\x6c\x6d\x61\x2d\x74\x6f\x6f\x6c\x74\x69\x70\x2d\x31\x2e\x30\x2e\x34\x2e\x6d\x69\x6e\x2e\x63\x73\x73\x22\x3e\x0a\x20\x20\x20\x20\x3c\x6c\x69\x6e\x6b\x20\x72\x65\x6c\x3d\x22\x73\x74\x79\x6c\x65\x73\x68\x65\x65\x74\x22\x20\x68\x72\x65\x66\x3d\x22\x2f\x73\x74\x61\x74\x69\x63\x2f\x63\x73\x73\x2f\x73\x74\x79\x6c\x65\x2e\x63\x73\x73\x22\x3e\x0a\x3c\x2f\x68\x65\x61\x64\x3e\x0a\x0a\x3c\x62\x6f\x64\x79\x3e\x0a\x20\x20\x20\x20\x7b\x6e\x61\x76\x69\x67\x61\x74\x69\x6f\x6e\x7d\x20\x7b\x64\x6f\x63\x75\x6d\x65\x6e\x74\x42\x6f\x64\x79\x7d\x0a\x3c\x2f\x62\x6f\x64\x79\x3e\x0a\x3c\x66\x6f\x6f\x74\x65\x72\x20\x63\x6c\x61\x73\x73\x3d\x22\x66\x6f\x6f\x74\x65\x72\x22\x3e\x0a\x20\x20\x20\x20\x7b\x66\x6f\x6f\x74\x65\x72\x7d\x0a\x3c\x2f\x66\x6f\x6f\x74\x65\x72\x3e\x0a\x0a\x3c\x2f\x68\x74\x6d\x6c\x3e")
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
|
||||||
|
|
||||||
|
f, err := FS.OpenFile(CTX, "/main.html", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_, err = f.Write(FileMainHTML)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
35
api/http/static/b0xfile__navigation.html.go
Normal file
35
api/http/static/b0xfile__navigation.html.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Code generaTed by fileb0x at "2018-05-26 12:42:22.451535628 +0500 +05 m=+0.053390017" from config file "fileb0x.yml" DO NOT EDIT.
|
||||||
|
// modified(2018-05-26 12:39:34.429095224 +0500 +05)
|
||||||
|
// original path: assets/navigation.html
|
||||||
|
|
||||||
|
package static
|
||||||
|
|
||||||
|
import (
|
||||||
|
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FileNavigationHTML is "/navigation.html"
|
||||||
|
var FileNavigationHTML = []byte("\x3c\x6e\x61\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x20\x69\x73\x2d\x64\x61\x72\x6b\x22\x3e\x0a\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x62\x72\x61\x6e\x64\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x61\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x69\x74\x65\x6d\x22\x20\x68\x72\x65\x66\x3d\x22\x2f\x22\x3e\x46\x61\x73\x74\x20\x50\x61\x73\x74\x65\x20\x42\x69\x6e\x3c\x2f\x61\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x61\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x69\x74\x65\x6d\x22\x20\x68\x72\x65\x66\x3d\x22\x2f\x70\x61\x73\x74\x65\x73\x2f\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x50\x61\x73\x74\x65\x73\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x61\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x62\x75\x72\x67\x65\x72\x20\x62\x75\x72\x67\x65\x72\x22\x20\x64\x61\x74\x61\x2d\x74\x61\x72\x67\x65\x74\x3d\x22\x6e\x61\x76\x62\x61\x72\x49\x74\x65\x6d\x73\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x73\x70\x61\x6e\x3e\x3c\x2f\x73\x70\x61\x6e\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x73\x70\x61\x6e\x3e\x3c\x2f\x73\x70\x61\x6e\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x73\x70\x61\x6e\x3e\x3c\x2f\x73\x70\x61\x6e\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x0a\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x69\x64\x3d\x22\x6e\x61\x76\x62\x61\x72\x49\x74\x65\x6d\x73\x22\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x6d\x65\x6e\x75\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x73\x74\x61\x72\x74\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x65\x6e\x64\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x3c\x2f\x6e\x61\x76\x3e")
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
|
||||||
|
|
||||||
|
f, err := FS.OpenFile(CTX, "/navigation.html", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_, err = f.Write(FileNavigationHTML)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,5 +1,5 @@
|
|||||||
// Code generaTed by fileb0x at "2018-05-18 22:25:13.191256649 +0500 +05 m=+0.041507879" from config file "fileb0x.yml" DO NOT EDIT.
|
// Code generaTed by fileb0x at "2018-05-26 13:47:21.417964779 +0500 +05 m=+0.019030606" from config file "fileb0x.yml" DO NOT EDIT.
|
||||||
// modified(2018-05-18 22:17:55.447214662 +0500 +05)
|
// modified(2018-05-26 13:41:01.75233841 +0500 +05)
|
||||||
// original path: assets/pastelist_list.html
|
// original path: assets/pastelist_list.html
|
||||||
|
|
||||||
package static
|
package static
|
||||||
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// FilePastelistListHTML is "/pastelist_list.html"
|
// FilePastelistListHTML is "/pastelist_list.html"
|
||||||
var FilePastelistListHTML = []byte("\x3c\x21\x44\x4f\x43\x54\x59\x50\x45\x20\x68\x74\x6d\x6c\x3e\x0a\x3c\x68\x74\x6d\x6c\x3e\x0a\x0a\x3c\x68\x65\x61\x64\x3e\x0a\x20\x20\x20\x20\x3c\x6d\x65\x74\x61\x20\x63\x68\x61\x72\x73\x65\x74\x3d\x22\x75\x74\x66\x2d\x38\x22\x3e\x0a\x20\x20\x20\x20\x3c\x6d\x65\x74\x61\x20\x6e\x61\x6d\x65\x3d\x22\x76\x69\x65\x77\x70\x6f\x72\x74\x22\x20\x63\x6f\x6e\x74\x65\x6e\x74\x3d\x22\x77\x69\x64\x74\x68\x3d\x64\x65\x76\x69\x63\x65\x2d\x77\x69\x64\x74\x68\x2c\x20\x69\x6e\x69\x74\x69\x61\x6c\x2d\x73\x63\x61\x6c\x65\x3d\x31\x22\x3e\x0a\x20\x20\x20\x20\x3c\x74\x69\x74\x6c\x65\x3e\x46\x61\x73\x74\x20\x50\x61\x73\x74\x65\x20\x42\x69\x6e\x20\x2d\x20\x50\x61\x73\x74\x65\x73\x3c\x2f\x74\x69\x74\x6c\x65\x3e\x0a\x20\x20\x20\x20\x3c\x6c\x69\x6e\x6b\x20\x72\x65\x6c\x3d\x22\x73\x74\x79\x6c\x65\x73\x68\x65\x65\x74\x22\x20\x68\x72\x65\x66\x3d\x22\x2f\x73\x74\x61\x74\x69\x63\x2f\x63\x73\x73\x2f\x62\x75\x6c\x6d\x61\x2d\x30\x2e\x37\x2e\x30\x2e\x6d\x69\x6e\x2e\x63\x73\x73\x22\x3e\x0a\x20\x20\x20\x20\x3c\x73\x63\x72\x69\x70\x74\x20\x64\x65\x66\x65\x72\x20\x73\x72\x63\x3d\x22\x2f\x73\x74\x61\x74\x69\x63\x2f\x6a\x73\x2f\x66\x6f\x6e\x74\x61\x77\x65\x73\x6f\x6d\x65\x2d\x35\x2e\x30\x2e\x37\x2e\x6a\x73\x22\x3e\x3c\x2f\x73\x63\x72\x69\x70\x74\x3e\x0a\x20\x20\x20\x20\x3c\x6c\x69\x6e\x6b\x20\x72\x65\x6c\x3d\x22\x73\x74\x79\x6c\x65\x73\x68\x65\x65\x74\x22\x20\x68\x72\x65\x66\x3d\x22\x2f\x73\x74\x61\x74\x69\x63\x2f\x63\x73\x73\x2f\x73\x74\x79\x6c\x65\x2e\x63\x73\x73\x22\x3e\x0a\x3c\x2f\x68\x65\x61\x64\x3e\x0a\x0a\x3c\x62\x6f\x64\x79\x3e\x0a\x20\x20\x20\x20\x3c\x6e\x61\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x20\x69\x73\x2d\x64\x61\x72\x6b\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x62\x72\x61\x6e\x64\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x61\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x69\x74\x65\x6d\x22\x20\x68\x72\x65\x66\x3d\x22\x2f\x22\x3e\x46\x61\x73\x74\x20\x50\x61\x73\x74\x65\x20\x42\x69\x6e\x3c\x2f\x61\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x61\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x69\x74\x65\x6d\x22\x20\x68\x72\x65\x66\x3d\x22\x2f\x70\x61\x73\x74\x65\x73\x2f\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x50\x61\x73\x74\x65\x73\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x61\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x62\x75\x72\x67\x65\x72\x20\x62\x75\x72\x67\x65\x72\x22\x20\x64\x61\x74\x61\x2d\x74\x61\x72\x67\x65\x74\x3d\x22\x6e\x61\x76\x62\x61\x72\x49\x74\x65\x6d\x73\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x73\x70\x61\x6e\x3e\x3c\x2f\x73\x70\x61\x6e\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x73\x70\x61\x6e\x3e\x3c\x2f\x73\x70\x61\x6e\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x73\x70\x61\x6e\x3e\x3c\x2f\x73\x70\x61\x6e\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x69\x64\x3d\x22\x6e\x61\x76\x62\x61\x72\x49\x74\x65\x6d\x73\x22\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x6d\x65\x6e\x75\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x73\x74\x61\x72\x74\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\x6e\x61\x76\x62\x61\x72\x2d\x65\x6e\x64\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x3c\x2f\x6e\x61\x76\x3e\x0a\x20\x20\x20\x20\x3c\x73\x65\x63\x74\x69\x6f\x6e\x20\x63\x6c\x61\x73\x73\x3d\x22\x73\x65\x63\x74\x69\x6f\x6e\x22\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x7b\x70\x61\x67\x69\x6e\x61\x74\x69\x6f\x6e\x7d\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x7b\x70\x61\x73\x74\x65\x73\x7d\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x7b\x70\x61\x67\x69\x6e\x61\x74\x69\x6f\x6e\x7d\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x3c\x2f\x73\x65\x63\x74\x69\x6f\x6e\x3e\x0a\x3c\x2f\x62\x6f\x64\x79\x3e\x0a\x0a\x3c\x2f\x68\x74\x6d\x6c\x3e")
|
var FilePastelistListHTML = []byte("\x3c\x73\x65\x63\x74\x69\x6f\x6e\x20\x63\x6c\x61\x73\x73\x3d\x22\x73\x65\x63\x74\x69\x6f\x6e\x22\x3e\x0a\x20\x20\x20\x20\x3c\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x7b\x70\x61\x67\x69\x6e\x61\x74\x69\x6f\x6e\x7d\x0a\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x3c\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x7b\x70\x61\x73\x74\x65\x73\x7d\x0a\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x3c\x64\x69\x76\x3e\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x7b\x70\x61\x67\x69\x6e\x61\x74\x69\x6f\x6e\x7d\x0a\x20\x20\x20\x20\x3c\x2f\x64\x69\x76\x3e\x0a\x3c\x2f\x73\x65\x63\x74\x69\x6f\x6e\x3e")
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
|
@ -1,40 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<section class="section">
|
||||||
<html>
|
<div class="box has-background-warning">
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<title>Fast Paste Bin - ERROR!</title>
|
|
||||||
<link rel="stylesheet" href="/static/css/bulma-0.7.0.min.css">
|
|
||||||
<script defer src="/static/js/fontawesome-5.0.7.js"></script>
|
|
||||||
<link rel="stylesheet" href="/static/css/style.css">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<nav class="navbar is-dark">
|
|
||||||
<div class="navbar-brand">
|
|
||||||
<a class="navbar-item" href="/">Fast Paste Bin</a>
|
|
||||||
<a class="navbar-item" href="/pastes/">
|
|
||||||
Pastes
|
|
||||||
</a>
|
|
||||||
<div class="navbar-burger burger" data-target="navbarItems">
|
|
||||||
<span></span>
|
|
||||||
<span></span>
|
|
||||||
<span></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="navbarItems" class="navbar-menu">
|
|
||||||
<div class="navbar-start">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="navbar-end">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
<section class="section">
|
|
||||||
<p>{error}</p>
|
<p>{error}</p>
|
||||||
</section>
|
</div>
|
||||||
</body>
|
</section>
|
||||||
|
|
||||||
</html>
|
|
11
assets/footer.html
Normal file
11
assets/footer.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<div class="container">
|
||||||
|
<div class="content has-text-centered">
|
||||||
|
<p>
|
||||||
|
<strong>Fast paste bin</strong> version
|
||||||
|
<strong>{version}</strong> by
|
||||||
|
<a href="https://pztrn.name">Stanislav N. aka pztrn</a>. The source code is licensed
|
||||||
|
<a href="http://opensource.org/licenses/mit-license.php">MIT</a>. Get
|
||||||
|
<a href="https://github.com/pztrn/fastpastebin">source or binary releases here</a>!
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -1,120 +1,82 @@
|
|||||||
<!DOCTYPE html>
|
<section class="section">
|
||||||
<html>
|
<form action="/paste/" method="POST" autocomplete="off">
|
||||||
|
<div class="columns">
|
||||||
<head>
|
<div class="column is-8 field">
|
||||||
<meta charset="utf-8">
|
<div class="control">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<textarea class="textarea" placeholder="Paste contents" name="paste-contents" id="paste-contents"></textarea>
|
||||||
<title>Fast Paste Bin</title>
|
</div>
|
||||||
<link rel="stylesheet" href="/static/css/bulma-0.7.0.min.css">
|
|
||||||
<link rel="stylesheet" href="/static/css/bulma-tooltip-1.0.4.min.css">
|
|
||||||
<script defer src="/static/js/fontawesome-5.0.7.js"></script>
|
|
||||||
<link rel="stylesheet" href="/static/css/style.css">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<nav class="navbar is-dark">
|
|
||||||
<div class="navbar-brand">
|
|
||||||
<a class="navbar-item" href="/">Fast Paste Bin</a>
|
|
||||||
<a class="navbar-item" href="/pastes/">
|
|
||||||
Pastes
|
|
||||||
</a>
|
|
||||||
<div class="navbar-burger burger" data-target="navbarItems">
|
|
||||||
<span></span>
|
|
||||||
<span></span>
|
|
||||||
<span></span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="column is-4">
|
||||||
|
<div class="field">
|
||||||
<div id="navbarItems" class="navbar-menu">
|
|
||||||
<div class="navbar-start">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="navbar-end">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
<section class="section">
|
|
||||||
<form action="/paste/" method="POST" autocomplete="off">
|
|
||||||
<div class="columns">
|
|
||||||
<div class="column is-8 field">
|
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<textarea class="textarea" placeholder="Paste contents" name="paste-contents" id="paste-contents"></textarea>
|
<input class="input" type="text" placeholder="Paste title" name="paste-title" id="paste-title">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-4">
|
<div class="field">
|
||||||
<div class="field">
|
<label for="paste-keep-for">Paste should be available for:</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input class="input" type="text" placeholder="Paste title" name="paste-title" id="paste-title">
|
<div class="select">
|
||||||
|
<select id="paste-keep-for" name="paste-keep-for">
|
||||||
|
<option value="30M">30 minutes</option>
|
||||||
|
<option value="1h">1 hour</option>
|
||||||
|
<option value="3h">3 hours</option>
|
||||||
|
<option value="6h">6 hours</option>
|
||||||
|
<option value="12h">12 hours</option>
|
||||||
|
<option value="1d">1 day</option>
|
||||||
|
<option value="2d">2 days</option>
|
||||||
|
<option value="3d">3 days</option>
|
||||||
|
<option value="4d">4 days</option>
|
||||||
|
<option value="5d">5 days</option>
|
||||||
|
<option value="7d">7 days</option>
|
||||||
|
<option value="14d">14 days</option>
|
||||||
|
<option value="21d">21 days</option>
|
||||||
|
<option value="1m">1 monts</option>
|
||||||
|
<option value="3m">3 months</option>
|
||||||
|
<option value="6m">6 months</option>
|
||||||
|
<option value="forever">Forever</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
</div>
|
||||||
<label for="paste-keep-for">Paste should be available for:</label>
|
<div class="field tooltip is-tooltip-bottom is-tooltip-multiline" data-tooltip="Should this paste be accessible only with special URL and not shown in pastes list? WARNING: If you'll enter password into 'Password for paste' field this checkbox will be assumed as checked!">
|
||||||
<div class="control">
|
<label class="checkbox">
|
||||||
<div class="select">
|
<input type="checkbox" name="paste-private" id="paste-private"> Private paste with unique URL?
|
||||||
<select id="paste-keep-for" name="paste-keep-for">
|
</label>
|
||||||
<option value="30M">30 minutes</option>
|
</div>
|
||||||
<option value="1h">1 hour</option>
|
<div>OR</div>
|
||||||
<option value="3h">3 hours</option>
|
<div class="field tooltip is-tooltip-bottom is-tooltip-multiline" data-tooltip="If you'll enter password here - 'Private
|
||||||
<option value="6h">6 hours</option>
|
|
||||||
<option value="12h">12 hours</option>
|
|
||||||
<option value="1d">1 day</option>
|
|
||||||
<option value="2d">2 days</option>
|
|
||||||
<option value="3d">3 days</option>
|
|
||||||
<option value="4d">4 days</option>
|
|
||||||
<option value="5d">5 days</option>
|
|
||||||
<option value="7d">7 days</option>
|
|
||||||
<option value="14d">14 days</option>
|
|
||||||
<option value="21d">21 days</option>
|
|
||||||
<option value="1m">1 monts</option>
|
|
||||||
<option value="3m">3 months</option>
|
|
||||||
<option value="6m">6 months</option>
|
|
||||||
<option value="forever">Forever</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="field tooltip is-tooltip-bottom is-tooltip-multiline" data-tooltip="Should this paste be accessible only with special URL and not shown in pastes list? WARNING: If you'll enter password into 'Password for paste' field this checkbox will be assumed as checked!">
|
|
||||||
<label class="checkbox">
|
|
||||||
<input type="checkbox" name="paste-private" id="paste-private"> Private paste with unique URL?
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div>OR</div>
|
|
||||||
<div class="field tooltip is-tooltip-bottom is-tooltip-multiline" data-tooltip="If you'll enter password here - 'Private
|
|
||||||
paste with unique URL' checkbox will be assumed as checked.">
|
paste with unique URL' checkbox will be assumed as checked.">
|
||||||
<label for="paste-password">Password for paste:</label>
|
<label for="paste-password">Password for paste:</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input class="input" type="text" placeholder="Enter password." name="paste-password" id="paste-password">
|
<input class="input" type="text" placeholder="Enter password." name="paste-password" id="paste-password">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="paste-language">Language:</label>
|
||||||
|
<div class="control">
|
||||||
|
<div class="select">
|
||||||
|
<select id="paste-language" name="paste-language">
|
||||||
|
{lexers}
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
</div>
|
||||||
<label for="paste-language">Language:</label>
|
<div class="field">
|
||||||
<div class="control">
|
<label for="paste-captcha">Captcha:</label>
|
||||||
<div class="select">
|
<div class="control">
|
||||||
<select id="paste-language" name="paste-language">
|
<p>
|
||||||
{lexers}
|
<img id=image src="/captcha/{captchaString}.png" alt="Captcha image">
|
||||||
</select>
|
</p>
|
||||||
</div>
|
<input class="input" type="text" placeholder="Captcha solution" name="paste-captcha-solution" id="paste-captcha-solution">
|
||||||
</div>
|
<input class="input is-hidden" type="text" name="paste-captcha-id" id="paste-captcha-id" readonly value="{captchaString}">
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
</div>
|
||||||
<label for="paste-captcha">Captcha:</label>
|
<div class="field">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<p>
|
<input class="button is-success" type="submit" value="Paste!">
|
||||||
<img id=image src="/captcha/{captchaString}.png" alt="Captcha image">
|
|
||||||
</p>
|
|
||||||
<input class="input" type="text" placeholder="Captcha solution" name="paste-captcha-solution" id="paste-captcha-solution">
|
|
||||||
<input class="input is-hidden" type="text" name="paste-captcha-id" id="paste-captcha-id" readonly value="{captchaString}">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="field">
|
|
||||||
<div class="control">
|
|
||||||
<input class="button is-success" type="submit" value="Paste!">
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
</section>
|
</form>
|
||||||
</body>
|
</section>
|
||||||
|
|
||||||
</html>
|
|
20
assets/main.html
Normal file
20
assets/main.html
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Fast Paste Bin</title>
|
||||||
|
<link rel="stylesheet" href="/static/css/bulma-0.7.0.min.css">
|
||||||
|
<link rel="stylesheet" href="/static/css/bulma-tooltip-1.0.4.min.css">
|
||||||
|
<link rel="stylesheet" href="/static/css/style.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
{navigation} {documentBody}
|
||||||
|
</body>
|
||||||
|
<footer class="footer">
|
||||||
|
{footer}
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
</html>
|
21
assets/navigation.html
Normal file
21
assets/navigation.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<nav class="navbar is-dark">
|
||||||
|
<div class="navbar-brand">
|
||||||
|
<a class="navbar-item" href="/">Fast Paste Bin</a>
|
||||||
|
<a class="navbar-item" href="/pastes/">
|
||||||
|
Pastes
|
||||||
|
</a>
|
||||||
|
<div class="navbar-burger burger" data-target="navbarItems">
|
||||||
|
<span></span>
|
||||||
|
<span></span>
|
||||||
|
<span></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="navbarItems" class="navbar-menu">
|
||||||
|
<div class="navbar-start">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="navbar-end">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
@ -1,69 +1,32 @@
|
|||||||
<!DOCTYPE html>
|
<section class="section">
|
||||||
<html>
|
<div class="content">
|
||||||
|
<div class="columns">
|
||||||
<head>
|
<div class="column is-4 is-offset-4">
|
||||||
<meta charset="utf-8">
|
<form action="/paste/{pasteID}/{pasteTimestamp}/verify" method="POST" autocomplete="off">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<div class="card">
|
||||||
<title>Fast Paste Bin - Paste is protected with password</title>
|
<header class="card-header">
|
||||||
<link rel="stylesheet" href="/static/css/bulma-0.7.0.min.css">
|
<p class="card-header-title">
|
||||||
<script defer src="/static/js/fontawesome-5.0.7.js"></script>
|
This paste is protected with password
|
||||||
<link rel="stylesheet" href="/static/css/style.css">
|
</p>
|
||||||
</head>
|
</header>
|
||||||
|
<div class="card-content">
|
||||||
<body>
|
<div class="content">
|
||||||
<nav class="navbar is-dark">
|
<div class="field tooltip is-tooltip-bottom is-tooltip-multiline" data-tooltip="If you'll enter password here - 'Private paste with unique URL' checkbox will be assumed as checked.">
|
||||||
<div class="navbar-brand">
|
<label for="paste-password">Password for paste:</label>
|
||||||
<a class="navbar-item" href="/">Fast Paste Bin</a>
|
|
||||||
<a class="navbar-item" href="/pastes/">
|
|
||||||
Pastes
|
|
||||||
</a>
|
|
||||||
<div class="navbar-burger burger" data-target="navbarItems">
|
|
||||||
<span></span>
|
|
||||||
<span></span>
|
|
||||||
<span></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="navbarItems" class="navbar-menu">
|
|
||||||
<div class="navbar-start">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="navbar-end">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
<section class="section">
|
|
||||||
<div class="content">
|
|
||||||
<div class="columns">
|
|
||||||
<div class="column is-4 is-offset-4">
|
|
||||||
<form action="/paste/{pasteID}/{pasteTimestamp}/verify" method="POST" autocomplete="off">
|
|
||||||
<div class="card">
|
|
||||||
<header class="card-header">
|
|
||||||
<p class="card-header-title">
|
|
||||||
This paste is protected with password
|
|
||||||
</p>
|
|
||||||
</header>
|
|
||||||
<div class="card-content">
|
|
||||||
<div class="content">
|
|
||||||
<div class="field tooltip is-tooltip-bottom is-tooltip-multiline" data-tooltip="If you'll enter password here - 'Private paste with unique URL' checkbox will be assumed as checked.">
|
|
||||||
<label for="paste-password">Password for paste:</label>
|
|
||||||
<div class="control">
|
|
||||||
<input class="input" type="text" placeholder="Enter password." name="paste-password" id="paste-password">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="field">
|
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input class="button is-success" type="submit" value="Check password!">
|
<input class="input" type="text" placeholder="Enter password." name="paste-password" id="paste-password">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<div class="control">
|
||||||
|
<input class="button is-success" type="submit" value="Check password!">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</div>
|
||||||
</body>
|
</section>
|
||||||
|
|
||||||
</html>
|
|
@ -1,71 +1,34 @@
|
|||||||
<!DOCTYPE html>
|
<section class="section">
|
||||||
<html>
|
<div class="content">
|
||||||
|
<table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth">
|
||||||
<head>
|
<thead>
|
||||||
<meta charset="utf-8">
|
<tr>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<th>#</th>
|
||||||
<title>Fast Paste Bin - Paste #{pasteID}</title>
|
<th>Title</th>
|
||||||
<link rel="stylesheet" href="/static/css/bulma-0.7.0.min.css">
|
<th>Language</th>
|
||||||
<script defer src="/static/js/fontawesome-5.0.7.js"></script>
|
<th>Pasted on</th>
|
||||||
<link rel="stylesheet" href="/static/css/style.css">
|
<th>Will expire on</th>
|
||||||
</head>
|
<th>Paste type</th>
|
||||||
|
</tr>
|
||||||
<body>
|
</thead>
|
||||||
<nav class="navbar is-dark">
|
<tbody>
|
||||||
<div class="navbar-brand">
|
<tr>
|
||||||
<a class="navbar-item" href="/">Fast Paste Bin</a>
|
<td>{pasteID}</td>
|
||||||
<a class="navbar-item" href="/pastes/">
|
<td>{pasteTitle}</td>
|
||||||
Pastes
|
<td>{pasteLanguage}</td>
|
||||||
</a>
|
<td>{pasteDate}</td>
|
||||||
<div class="navbar-burger burger" data-target="navbarItems">
|
<td>{pasteExpiration}</td>
|
||||||
<span></span>
|
<td>{pasteType}</td>
|
||||||
<span></span>
|
</tr>
|
||||||
<span></span>
|
<tr>
|
||||||
</div>
|
<td colspan="6">
|
||||||
</div>
|
<a class="button" href="/paste/{pasteID}/{pasteTs}raw">View raw</a>
|
||||||
|
</td>
|
||||||
<div id="navbarItems" class="navbar-menu">
|
</tr>
|
||||||
<div class="navbar-start">
|
</tbody>
|
||||||
</div>
|
</table>
|
||||||
|
|
||||||
<div class="navbar-end">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
<section class="section">
|
|
||||||
<div class="content">
|
|
||||||
<table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>#</th>
|
|
||||||
<th>Title</th>
|
|
||||||
<th>Language</th>
|
|
||||||
<th>Pasted on</th>
|
|
||||||
<th>Will expire on</th>
|
|
||||||
<th>Paste type</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td>{pasteID}</td>
|
|
||||||
<td>{pasteTitle}</td>
|
|
||||||
<td>{pasteLanguage}</td>
|
|
||||||
<td>{pasteDate}</td>
|
|
||||||
<td>{pasteExpiration}</td>
|
|
||||||
<td>{pasteType}</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td colspan="6">
|
|
||||||
<a class="button" href="/paste/{pasteID}/{pasteTs}raw">View raw</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
<div class="paste-data">
|
|
||||||
{pastedata}
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</section>
|
||||||
|
<div class="paste-data">
|
||||||
</html>
|
{pastedata}
|
||||||
|
</div>
|
@ -1,48 +1,11 @@
|
|||||||
<!DOCTYPE html>
|
<section class="section">
|
||||||
<html>
|
<div>
|
||||||
|
{pagination}
|
||||||
<head>
|
</div>
|
||||||
<meta charset="utf-8">
|
<div>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
{pastes}
|
||||||
<title>Fast Paste Bin - Pastes</title>
|
</div>
|
||||||
<link rel="stylesheet" href="/static/css/bulma-0.7.0.min.css">
|
<div>
|
||||||
<script defer src="/static/js/fontawesome-5.0.7.js"></script>
|
{pagination}
|
||||||
<link rel="stylesheet" href="/static/css/style.css">
|
</div>
|
||||||
</head>
|
</section>
|
||||||
|
|
||||||
<body>
|
|
||||||
<nav class="navbar is-dark">
|
|
||||||
<div class="navbar-brand">
|
|
||||||
<a class="navbar-item" href="/">Fast Paste Bin</a>
|
|
||||||
<a class="navbar-item" href="/pastes/">
|
|
||||||
Pastes
|
|
||||||
</a>
|
|
||||||
<div class="navbar-burger burger" data-target="navbarItems">
|
|
||||||
<span></span>
|
|
||||||
<span></span>
|
|
||||||
<span></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="navbarItems" class="navbar-menu">
|
|
||||||
<div class="navbar-start">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="navbar-end">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
<section class="section">
|
|
||||||
<div>
|
|
||||||
{pagination}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
{pastes}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
{pagination}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
@ -37,6 +37,7 @@ import (
|
|||||||
"github.com/pztrn/fastpastebin/database"
|
"github.com/pztrn/fastpastebin/database"
|
||||||
"github.com/pztrn/fastpastebin/database/migrations"
|
"github.com/pztrn/fastpastebin/database/migrations"
|
||||||
"github.com/pztrn/fastpastebin/pastes"
|
"github.com/pztrn/fastpastebin/pastes"
|
||||||
|
"github.com/pztrn/fastpastebin/templater"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -57,6 +58,7 @@ func main() {
|
|||||||
c.Database.Initialize()
|
c.Database.Initialize()
|
||||||
migrations.New(c)
|
migrations.New(c)
|
||||||
migrations.Migrate()
|
migrations.Migrate()
|
||||||
|
templater.Initialize(c)
|
||||||
api.New(c)
|
api.New(c)
|
||||||
api.InitializeAPI()
|
api.InitializeAPI()
|
||||||
|
|
||||||
|
@ -24,6 +24,11 @@
|
|||||||
|
|
||||||
package context
|
package context
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Version .
|
||||||
|
Version = "0.1.1-dev"
|
||||||
|
)
|
||||||
|
|
||||||
// New creates new context.
|
// New creates new context.
|
||||||
func New() *Context {
|
func New() *Context {
|
||||||
return &Context{}
|
return &Context{}
|
||||||
|
@ -95,7 +95,10 @@ custom:
|
|||||||
# end: files
|
# end: files
|
||||||
- files:
|
- files:
|
||||||
- "assets/error.html"
|
- "assets/error.html"
|
||||||
|
- "assets/footer.html"
|
||||||
- "assets/index.html"
|
- "assets/index.html"
|
||||||
|
- "assets/main.html"
|
||||||
|
- "assets/navigation.html"
|
||||||
- "assets/pagination_ellipsis.html"
|
- "assets/pagination_ellipsis.html"
|
||||||
- "assets/pagination_link_current.html"
|
- "assets/pagination_link_current.html"
|
||||||
- "assets/pagination_link.html"
|
- "assets/pagination_link.html"
|
||||||
|
@ -34,9 +34,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
// local
|
// local
|
||||||
"github.com/pztrn/fastpastebin/api/http/static"
|
|
||||||
"github.com/pztrn/fastpastebin/captcha"
|
"github.com/pztrn/fastpastebin/captcha"
|
||||||
"github.com/pztrn/fastpastebin/pagination"
|
"github.com/pztrn/fastpastebin/pagination"
|
||||||
|
"github.com/pztrn/fastpastebin/templater"
|
||||||
|
|
||||||
// other
|
// other
|
||||||
"github.com/alecthomas/chroma"
|
"github.com/alecthomas/chroma"
|
||||||
@ -54,11 +54,6 @@ var (
|
|||||||
|
|
||||||
// GET for "/paste/PASTE_ID" and "/paste/PASTE_ID/TIMESTAMP" (private pastes).
|
// GET for "/paste/PASTE_ID" and "/paste/PASTE_ID/TIMESTAMP" (private pastes).
|
||||||
func pasteGET(ec echo.Context) error {
|
func pasteGET(ec echo.Context) error {
|
||||||
errhtml, err := static.ReadFile("error.html")
|
|
||||||
if err != nil {
|
|
||||||
return ec.String(http.StatusNotFound, "error.html wasn't found!")
|
|
||||||
}
|
|
||||||
|
|
||||||
pasteIDRaw := ec.Param("id")
|
pasteIDRaw := ec.Param("id")
|
||||||
// We already get numbers from string, so we will not check strconv.Atoi()
|
// We already get numbers from string, so we will not check strconv.Atoi()
|
||||||
// error.
|
// error.
|
||||||
@ -69,14 +64,14 @@ func pasteGET(ec echo.Context) error {
|
|||||||
paste, err1 := GetByID(pasteID)
|
paste, err1 := GetByID(pasteID)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
c.Logger.Error().Msgf("Failed to get paste #%d: %s", pasteID, err1.Error())
|
c.Logger.Error().Msgf("Failed to get paste #%d: %s", pasteID, err1.Error())
|
||||||
errhtmlAsString := strings.Replace(string(errhtml), "{error}", "Paste #"+strconv.Itoa(pasteID)+" not found", 1)
|
errtpl := templater.GetErrorTemplate(ec, "Paste #"+strconv.Itoa(pasteID)+" not found")
|
||||||
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
|
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
if paste.IsExpired() {
|
if paste.IsExpired() {
|
||||||
c.Logger.Error().Msgf("Paste #%d is expired", pasteID)
|
c.Logger.Error().Msgf("Paste #%d is expired", pasteID)
|
||||||
errhtmlAsString := strings.Replace(string(errhtml), "{error}", "Paste #"+strconv.Itoa(pasteID)+" not found", 1)
|
errtpl := templater.GetErrorTemplate(ec, "Paste #"+strconv.Itoa(pasteID)+" not found")
|
||||||
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
|
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we have a private paste and it's parameters are correct.
|
// Check if we have a private paste and it's parameters are correct.
|
||||||
@ -85,14 +80,14 @@ func pasteGET(ec echo.Context) error {
|
|||||||
tsProvided, err2 := strconv.ParseInt(tsProvidedStr, 10, 64)
|
tsProvided, err2 := strconv.ParseInt(tsProvidedStr, 10, 64)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
c.Logger.Error().Msgf("Invalid timestamp '%s' provided for getting private paste #%d: %s", tsProvidedStr, pasteID, err2.Error())
|
c.Logger.Error().Msgf("Invalid timestamp '%s' provided for getting private paste #%d: %s", tsProvidedStr, pasteID, err2.Error())
|
||||||
errhtmlAsString := strings.Replace(string(errhtml), "{error}", "Paste #"+strconv.Itoa(pasteID)+" not found", 1)
|
errtpl := templater.GetErrorTemplate(ec, "Paste #"+strconv.Itoa(pasteID)+" not found")
|
||||||
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
|
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||||
}
|
}
|
||||||
pasteTs := paste.CreatedAt.Unix()
|
pasteTs := paste.CreatedAt.Unix()
|
||||||
if tsProvided != pasteTs {
|
if tsProvided != pasteTs {
|
||||||
c.Logger.Error().Msgf("Incorrect timestamp '%v' provided for private paste #%d, waiting for %v", tsProvidedStr, pasteID, strconv.FormatInt(pasteTs, 10))
|
c.Logger.Error().Msgf("Incorrect timestamp '%v' provided for private paste #%d, waiting for %v", tsProvidedStr, pasteID, strconv.FormatInt(pasteTs, 10))
|
||||||
errhtmlAsString := strings.Replace(string(errhtml), "{error}", "Paste #"+strconv.Itoa(pasteID)+" not found", 1)
|
errtpl := templater.GetErrorTemplate(ec, "Paste #"+strconv.Itoa(pasteID)+" not found")
|
||||||
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
|
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,24 +112,20 @@ func pasteGET(ec echo.Context) error {
|
|||||||
// If all okay - do nothing :)
|
// If all okay - do nothing :)
|
||||||
}
|
}
|
||||||
|
|
||||||
pasteHTML, err2 := static.ReadFile("paste.html")
|
// Format paste data map.
|
||||||
if err2 != nil {
|
pasteData := make(map[string]string)
|
||||||
return ec.String(http.StatusNotFound, "parse.html wasn't found!")
|
pasteData["pasteTitle"] = paste.Title
|
||||||
}
|
pasteData["pasteID"] = strconv.Itoa(paste.ID)
|
||||||
|
pasteData["pasteDate"] = paste.CreatedAt.Format("2006-01-02 @ 15:04:05") + " UTC"
|
||||||
// Format template with paste data.
|
pasteData["pasteExpiration"] = paste.GetExpirationTime().Format("2006-01-02 @ 15:04:05") + " UTC"
|
||||||
pasteHTMLAsString := strings.Replace(string(pasteHTML), "{pasteTitle}", paste.Title, 1)
|
pasteData["pasteLanguage"] = paste.Language
|
||||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pasteID}", strconv.Itoa(paste.ID), -1)
|
|
||||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pasteDate}", paste.CreatedAt.Format("2006-01-02 @ 15:04:05"), 1)
|
|
||||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pasteExpiration}", paste.GetExpirationTime().Format("2006-01-02 @ 15:04:05"), 1)
|
|
||||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pasteLanguage}", paste.Language, 1)
|
|
||||||
|
|
||||||
if paste.Private {
|
if paste.Private {
|
||||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pasteType}", "<span class='has-text-danger'>Private</span>", 1)
|
pasteData["pasteType"] = "<span class='has-text-danger'>Private</span>"
|
||||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pasteTs}", strconv.FormatInt(paste.CreatedAt.Unix(), 10)+"/", 1)
|
pasteData["pasteTs"] = strconv.FormatInt(paste.CreatedAt.Unix(), 10) + "/"
|
||||||
} else {
|
} else {
|
||||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pasteType}", "<span class='has-text-success'>Public</span>", 1)
|
pasteData["pasteType"] = "<span class='has-text-success'>Public</span>"
|
||||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pasteTs}", "", 1)
|
pasteData["pasteTs"] = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Highlight.
|
// Highlight.
|
||||||
@ -164,26 +155,16 @@ func pasteGET(ec echo.Context) error {
|
|||||||
if err4 != nil {
|
if err4 != nil {
|
||||||
c.Logger.Error().Msgf("Failed to format paste data: %s", err4.Error())
|
c.Logger.Error().Msgf("Failed to format paste data: %s", err4.Error())
|
||||||
}
|
}
|
||||||
|
pasteData["pastedata"] = buf.String()
|
||||||
|
|
||||||
// Escape paste data.
|
// Get template and format it.
|
||||||
//pasteData := html.EscapeString(buf.String())
|
pasteHTML := templater.GetTemplate(ec, "paste.html", pasteData)
|
||||||
pasteHTMLAsString = strings.Replace(pasteHTMLAsString, "{pastedata}", buf.String(), 1)
|
|
||||||
|
|
||||||
return ec.HTML(http.StatusOK, string(pasteHTMLAsString))
|
return ec.HTML(http.StatusOK, pasteHTML)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET for "/paste/PASTE_ID/TIMESTAMP/verify" - a password verify page.
|
// GET for "/paste/PASTE_ID/TIMESTAMP/verify" - a password verify page.
|
||||||
func pastePasswordedVerifyGet(ec echo.Context) error {
|
func pastePasswordedVerifyGet(ec echo.Context) error {
|
||||||
verifyHTMLRaw, err := static.ReadFile("passworded_paste_verify.html")
|
|
||||||
if err != nil {
|
|
||||||
return ec.String(http.StatusNotFound, "passworded_paste_verify.html wasn't found!")
|
|
||||||
}
|
|
||||||
|
|
||||||
errhtml, err := static.ReadFile("error.html")
|
|
||||||
if err != nil {
|
|
||||||
return ec.String(http.StatusNotFound, "error.html wasn't found!")
|
|
||||||
}
|
|
||||||
|
|
||||||
pasteIDRaw := ec.Param("id")
|
pasteIDRaw := ec.Param("id")
|
||||||
timestampRaw := ec.Param("timestamp")
|
timestampRaw := ec.Param("timestamp")
|
||||||
// We already get numbers from string, so we will not check strconv.Atoi()
|
// We already get numbers from string, so we will not check strconv.Atoi()
|
||||||
@ -194,8 +175,8 @@ func pastePasswordedVerifyGet(ec echo.Context) error {
|
|||||||
paste, err1 := GetByID(pasteID)
|
paste, err1 := GetByID(pasteID)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
c.Logger.Error().Msgf("Failed to get paste #%d: %s", pasteID, err1.Error())
|
c.Logger.Error().Msgf("Failed to get paste #%d: %s", pasteID, err1.Error())
|
||||||
errhtmlAsString := strings.Replace(string(errhtml), "{error}", "Paste #"+strconv.Itoa(pasteID)+" not found", 1)
|
errtpl := templater.GetErrorTemplate(ec, "Paste #"+pasteIDRaw+" not found")
|
||||||
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
|
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for auth cookie. If present - redirect to paste.
|
// Check for auth cookie. If present - redirect to paste.
|
||||||
@ -215,19 +196,18 @@ func pastePasswordedVerifyGet(ec echo.Context) error {
|
|||||||
c.Logger.Debug().Msg("Invalid cookie, showing auth page")
|
c.Logger.Debug().Msg("Invalid cookie, showing auth page")
|
||||||
}
|
}
|
||||||
|
|
||||||
verifyHTML := strings.Replace(string(verifyHTMLRaw), "{pasteID}", strconv.Itoa(pasteID), -1)
|
// HTML data.
|
||||||
verifyHTML = strings.Replace(verifyHTML, "{pasteTimestamp}", timestampRaw, 1)
|
htmlData := make(map[string]string)
|
||||||
|
htmlData["pasteID"] = strconv.Itoa(pasteID)
|
||||||
|
htmlData["pasteTimestamp"] = timestampRaw
|
||||||
|
|
||||||
|
verifyHTML := templater.GetTemplate(ec, "passworded_paste_verify.html", htmlData)
|
||||||
|
|
||||||
return ec.HTML(http.StatusOK, verifyHTML)
|
return ec.HTML(http.StatusOK, verifyHTML)
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST for "/paste/PASTE_ID/TIMESTAMP/verify" - a password verify page.
|
// POST for "/paste/PASTE_ID/TIMESTAMP/verify" - a password verify page.
|
||||||
func pastePasswordedVerifyPost(ec echo.Context) error {
|
func pastePasswordedVerifyPost(ec echo.Context) error {
|
||||||
errhtml, err := static.ReadFile("error.html")
|
|
||||||
if err != nil {
|
|
||||||
return ec.String(http.StatusNotFound, "error.html wasn't found!")
|
|
||||||
}
|
|
||||||
|
|
||||||
pasteIDRaw := ec.Param("id")
|
pasteIDRaw := ec.Param("id")
|
||||||
timestampRaw := ec.Param("timestamp")
|
timestampRaw := ec.Param("timestamp")
|
||||||
// We already get numbers from string, so we will not check strconv.Atoi()
|
// We already get numbers from string, so we will not check strconv.Atoi()
|
||||||
@ -239,14 +219,15 @@ func pastePasswordedVerifyPost(ec echo.Context) error {
|
|||||||
paste, err1 := GetByID(pasteID)
|
paste, err1 := GetByID(pasteID)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
c.Logger.Error().Msgf("Failed to get paste #%d: %s", pasteID, err1.Error())
|
c.Logger.Error().Msgf("Failed to get paste #%d: %s", pasteID, err1.Error())
|
||||||
errhtmlAsString := strings.Replace(string(errhtml), "{error}", "Paste #"+strconv.Itoa(pasteID)+" not found", 1)
|
errtpl := templater.GetErrorTemplate(ec, "Paste #"+strconv.Itoa(pasteID)+" not found")
|
||||||
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
|
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
params, err2 := ec.FormParams()
|
params, err2 := ec.FormParams()
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
c.Logger.Debug().Msg("No form parameters passed")
|
c.Logger.Debug().Msg("No form parameters passed")
|
||||||
return ec.HTML(http.StatusBadRequest, string(errhtml))
|
errtpl := templater.GetErrorTemplate(ec, "Paste #"+strconv.Itoa(pasteID)+" not found")
|
||||||
|
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
if paste.VerifyPassword(params["paste-password"][0]) {
|
if paste.VerifyPassword(params["paste-password"][0]) {
|
||||||
@ -261,43 +242,38 @@ func pastePasswordedVerifyPost(ec echo.Context) error {
|
|||||||
return ec.Redirect(http.StatusFound, "/paste/"+strconv.Itoa(pasteID)+"/"+timestampRaw)
|
return ec.Redirect(http.StatusFound, "/paste/"+strconv.Itoa(pasteID)+"/"+timestampRaw)
|
||||||
}
|
}
|
||||||
|
|
||||||
errhtmlAsString := strings.Replace(string(errhtml), "{error}", "Invalid password. Please, try again.", 1)
|
errtpl := templater.GetErrorTemplate(ec, "Invalid password. Please, try again.")
|
||||||
return ec.HTML(http.StatusBadRequest, string(errhtmlAsString))
|
return ec.HTML(http.StatusBadRequest, string(errtpl))
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST for "/paste/" which will create new paste and redirect to
|
// POST for "/paste/" which will create new paste and redirect to
|
||||||
// "/pastes/CREATED_PASTE_ID".
|
// "/pastes/CREATED_PASTE_ID".
|
||||||
func pastePOST(ec echo.Context) error {
|
func pastePOST(ec echo.Context) error {
|
||||||
errhtml, err := static.ReadFile("error.html")
|
|
||||||
if err != nil {
|
|
||||||
return ec.String(http.StatusNotFound, "error.html wasn't found!")
|
|
||||||
}
|
|
||||||
|
|
||||||
params, err := ec.FormParams()
|
params, err := ec.FormParams()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Logger.Debug().Msg("No form parameters passed")
|
errtpl := templater.GetErrorTemplate(ec, "Cannot create empty paste")
|
||||||
return ec.HTML(http.StatusBadRequest, string(errhtml))
|
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||||
}
|
}
|
||||||
c.Logger.Debug().Msgf("Received parameters: %+v", params)
|
c.Logger.Debug().Msgf("Received parameters: %+v", params)
|
||||||
|
|
||||||
// Do nothing if paste contents is empty.
|
// Do nothing if paste contents is empty.
|
||||||
if len(params["paste-contents"][0]) == 0 {
|
if len(params["paste-contents"][0]) == 0 {
|
||||||
c.Logger.Debug().Msg("Empty paste submitted, ignoring")
|
c.Logger.Debug().Msg("Empty paste submitted, ignoring")
|
||||||
errhtmlAsString := strings.Replace(string(errhtml), "{error}", "Empty pastes aren't allowed.", 1)
|
errtpl := templater.GetErrorTemplate(ec, "Empty pastes aren't allowed.")
|
||||||
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
|
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.ContainsAny(params["paste-keep-for"][0], "Mmhd") {
|
if !strings.ContainsAny(params["paste-keep-for"][0], "Mmhd") {
|
||||||
c.Logger.Debug().Msgf("'Keep paste for' field have invalid value: %s", params["paste-keep-for"][0])
|
c.Logger.Debug().Msgf("'Keep paste for' field have invalid value: %s", params["paste-keep-for"][0])
|
||||||
errhtmlAsString := strings.Replace(string(errhtml), "{error}", "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).", 1)
|
errtpl := templater.GetErrorTemplate(ec, "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).")
|
||||||
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
|
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify captcha.
|
// Verify captcha.
|
||||||
if !captcha.Verify(params["paste-captcha-id"][0], params["paste-captcha-solution"][0]) {
|
if !captcha.Verify(params["paste-captcha-id"][0], params["paste-captcha-solution"][0]) {
|
||||||
c.Logger.Debug().Msgf("Invalid captcha solution for captcha ID '%s': %s", params["paste-captcha-id"][0], params["paste-captcha-solution"][0])
|
c.Logger.Debug().Msgf("Invalid captcha solution for captcha ID '%s': %s", params["paste-captcha-id"][0], params["paste-captcha-solution"][0])
|
||||||
errhtmlAsString := strings.Replace(string(errhtml), "{error}", "Invalid captcha solution.", 1)
|
errtpl := templater.GetErrorTemplate(ec, "Invalid captcha solution.")
|
||||||
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
|
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
paste := &Paste{
|
paste := &Paste{
|
||||||
@ -319,8 +295,8 @@ func pastePOST(ec echo.Context) error {
|
|||||||
keepFor, err1 := strconv.Atoi(keepForRaw)
|
keepFor, err1 := strconv.Atoi(keepForRaw)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
c.Logger.Debug().Msgf("Failed to parse 'Keep for' integer: %s", err1.Error())
|
c.Logger.Debug().Msgf("Failed to parse 'Keep for' integer: %s", err1.Error())
|
||||||
errhtmlAsString := strings.Replace(string(errhtml), "{error}", "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).", 1)
|
errtpl := templater.GetErrorTemplate(ec, "Invalid 'Paste should be available for' parameter passed. Please do not try to hack us ;).")
|
||||||
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
|
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||||
}
|
}
|
||||||
paste.KeepFor = keepFor
|
paste.KeepFor = keepFor
|
||||||
|
|
||||||
@ -353,8 +329,8 @@ func pastePOST(ec echo.Context) error {
|
|||||||
id, err2 := Save(paste)
|
id, err2 := Save(paste)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
c.Logger.Debug().Msgf("Failed to save paste: %s", err2.Error())
|
c.Logger.Debug().Msgf("Failed to save paste: %s", err2.Error())
|
||||||
errhtmlAsString := strings.Replace(string(errhtml), "{error}", "Failed to save paste. Please, try again later.", 1)
|
errtpl := templater.GetErrorTemplate(ec, "Failed to save paste. Please, try again later.")
|
||||||
return ec.HTML(http.StatusBadRequest, errhtmlAsString)
|
return ec.HTML(http.StatusBadRequest, errtpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
newPasteIDAsString := strconv.FormatInt(id, 10)
|
newPasteIDAsString := strconv.FormatInt(id, 10)
|
||||||
@ -415,16 +391,6 @@ func pasteRawGET(ec echo.Context) error {
|
|||||||
|
|
||||||
// GET for "/pastes/", a list of publicly available pastes.
|
// GET for "/pastes/", a list of publicly available pastes.
|
||||||
func pastesGET(ec echo.Context) error {
|
func pastesGET(ec echo.Context) error {
|
||||||
pasteListHTML, err1 := static.ReadFile("pastelist_list.html")
|
|
||||||
if err1 != nil {
|
|
||||||
return ec.String(http.StatusNotFound, "pastelist_list.html wasn't found!")
|
|
||||||
}
|
|
||||||
|
|
||||||
pasteElementHTML, err2 := static.ReadFile("pastelist_paste.html")
|
|
||||||
if err2 != nil {
|
|
||||||
return ec.String(http.StatusNotFound, "pastelist_paste.html wasn't found!")
|
|
||||||
}
|
|
||||||
|
|
||||||
pageFromParamRaw := ec.Param("page")
|
pageFromParamRaw := ec.Param("page")
|
||||||
var page = 1
|
var page = 1
|
||||||
if pageFromParamRaw != "" {
|
if pageFromParamRaw != "" {
|
||||||
@ -443,16 +409,17 @@ func pastesGET(ec echo.Context) error {
|
|||||||
// Show "No pastes to show" on any error for now.
|
// Show "No pastes to show" on any error for now.
|
||||||
if err3 != nil {
|
if err3 != nil {
|
||||||
c.Logger.Error().Msgf("Failed to get pastes list from database: %s", err3.Error())
|
c.Logger.Error().Msgf("Failed to get pastes list from database: %s", err3.Error())
|
||||||
pasteListHTMLAsString := strings.Replace(string(pasteListHTML), "{pastes}", pastesString, 1)
|
noPastesToShowTpl := templater.GetErrorTemplate(ec, "No pastes to show.")
|
||||||
return ec.HTML(http.StatusOK, string(pasteListHTMLAsString))
|
return ec.HTML(http.StatusOK, noPastesToShowTpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(pastes) > 0 {
|
if len(pastes) > 0 {
|
||||||
pastesString = ""
|
pastesString = ""
|
||||||
for i := range pastes {
|
for i := range pastes {
|
||||||
pasteString := strings.Replace(string(pasteElementHTML), "{pasteID}", strconv.Itoa(pastes[i].ID), 2)
|
pasteDataMap := make(map[string]string)
|
||||||
pasteString = strings.Replace(pasteString, "{pasteTitle}", pastes[i].Title, 1)
|
pasteDataMap["pasteID"] = strconv.Itoa(pastes[i].ID)
|
||||||
pasteString = strings.Replace(pasteString, "{pasteDate}", pastes[i].CreatedAt.Format("2006-01-02 @ 15:04:05"), 1)
|
pasteDataMap["pasteTitle"] = pastes[i].Title
|
||||||
|
pasteDataMap["pasteDate"] = pastes[i].CreatedAt.Format("2006-01-02 @ 15:04:05") + " UTC"
|
||||||
|
|
||||||
// Get max 4 lines of each paste.
|
// Get max 4 lines of each paste.
|
||||||
pasteDataSplitted := strings.Split(pastes[i].Data, "\n")
|
pasteDataSplitted := strings.Split(pastes[i].Data, "\n")
|
||||||
@ -462,18 +429,20 @@ func pastesGET(ec echo.Context) error {
|
|||||||
} else {
|
} else {
|
||||||
pasteData = strings.Join(pasteDataSplitted[0:4], "\n")
|
pasteData = strings.Join(pasteDataSplitted[0:4], "\n")
|
||||||
}
|
}
|
||||||
pasteString = strings.Replace(pasteString, "{pasteData}", pasteData, 1)
|
|
||||||
|
|
||||||
pastesString += pasteString
|
pasteDataMap["pasteData"] = pasteData
|
||||||
|
pasteTpl := templater.GetRawTemplate(ec, "pastelist_paste.html", pasteDataMap)
|
||||||
|
|
||||||
|
pastesString += pasteTpl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pasteListHTMLAsString := strings.Replace(string(pasteListHTML), "{pastes}", pastesString, 1)
|
// Pagination.
|
||||||
|
|
||||||
pages := GetPastesPages()
|
pages := GetPastesPages()
|
||||||
c.Logger.Debug().Msgf("Total pages: %d, current: %d", pages, page)
|
c.Logger.Debug().Msgf("Total pages: %d, current: %d", pages, page)
|
||||||
paginationHTML := pagination.CreateHTML(page, pages, "/pastes/")
|
paginationHTML := pagination.CreateHTML(page, pages, "/pastes/")
|
||||||
pasteListHTMLAsString = strings.Replace(pasteListHTMLAsString, "{pagination}", paginationHTML, -1)
|
|
||||||
|
|
||||||
return ec.HTML(http.StatusOK, string(pasteListHTMLAsString))
|
pasteListTpl := templater.GetTemplate(ec, "pastelist_list.html", map[string]string{"pastes": pastesString, "pagination": paginationHTML})
|
||||||
|
|
||||||
|
return ec.HTML(http.StatusOK, string(pasteListTpl))
|
||||||
}
|
}
|
||||||
|
124
templater/exported.go
Normal file
124
templater/exported.go
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
// Fast Paste Bin - uberfast and easy-to-use pastebin.
|
||||||
|
//
|
||||||
|
// Copyright (c) 2018, Stanislav N. aka pztrn and Fast Paste Bin
|
||||||
|
// developers.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
// a copy of this software and associated documentation files (the
|
||||||
|
// "Software"), to deal in the Software without restriction, including
|
||||||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
// permit persons to whom the Software is furnished to do so, subject
|
||||||
|
// to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be
|
||||||
|
// included in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||||
|
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
package templater
|
||||||
|
|
||||||
|
import (
|
||||||
|
// stdlib
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
// local
|
||||||
|
"github.com/pztrn/fastpastebin/api/http/static"
|
||||||
|
"github.com/pztrn/fastpastebin/context"
|
||||||
|
|
||||||
|
// other
|
||||||
|
"github.com/labstack/echo"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
c *context.Context
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetErrorTemplate returns formatted error template.
|
||||||
|
// If error.html wasn't found - it will return "error.html not found"
|
||||||
|
// message as simple string.
|
||||||
|
func GetErrorTemplate(ec echo.Context, errorText string) string {
|
||||||
|
// Getting main error template.
|
||||||
|
mainhtml := GetTemplate(ec, "error.html", map[string]string{"error": errorText})
|
||||||
|
|
||||||
|
return mainhtml
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRawTemplate returns only raw template data.
|
||||||
|
func GetRawTemplate(ec echo.Context, templateName string, data map[string]string) string {
|
||||||
|
// Getting main template.
|
||||||
|
tplRaw, err := static.ReadFile(templateName)
|
||||||
|
if err != nil {
|
||||||
|
ec.String(http.StatusBadRequest, templateName+" not found.")
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
tpl := string(tplRaw)
|
||||||
|
// Replace placeholders with data from data map.
|
||||||
|
for placeholder, value := range data {
|
||||||
|
tpl = strings.Replace(tpl, "{"+placeholder+"}", value, -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return tpl
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTemplate returns formatted template that can be outputted to client.
|
||||||
|
func GetTemplate(ec echo.Context, name string, data map[string]string) string {
|
||||||
|
c.Logger.Debug().Msgf("Requested template '%s'", name)
|
||||||
|
|
||||||
|
// Getting main template.
|
||||||
|
mainhtml, err := static.ReadFile("main.html")
|
||||||
|
if err != nil {
|
||||||
|
ec.String(http.StatusBadRequest, "main.html not found.")
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getting navigation.
|
||||||
|
navhtml, err1 := static.ReadFile("navigation.html")
|
||||||
|
if err1 != nil {
|
||||||
|
ec.String(http.StatusBadRequest, "navigation.html not found.")
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getting footer.
|
||||||
|
footerhtml, err2 := static.ReadFile("footer.html")
|
||||||
|
if err2 != nil {
|
||||||
|
ec.String(http.StatusBadRequest, "footer.html not found.")
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format main template.
|
||||||
|
tpl := strings.Replace(string(mainhtml), "{navigation}", string(navhtml), 1)
|
||||||
|
tpl = strings.Replace(tpl, "{footer}", string(footerhtml), 1)
|
||||||
|
// Version.
|
||||||
|
tpl = strings.Replace(tpl, "{version}", context.Version, 1)
|
||||||
|
|
||||||
|
// Get requested template.
|
||||||
|
reqhtml, err3 := static.ReadFile(name)
|
||||||
|
if err3 != nil {
|
||||||
|
ec.String(http.StatusBadRequest, name+" not found.")
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace documentBody.
|
||||||
|
tpl = strings.Replace(tpl, "{documentBody}", string(reqhtml), 1)
|
||||||
|
|
||||||
|
// Replace placeholders with data from data map.
|
||||||
|
for placeholder, value := range data {
|
||||||
|
tpl = strings.Replace(tpl, "{"+placeholder+"}", value, -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return tpl
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize initializes package.
|
||||||
|
func Initialize(cc *context.Context) {
|
||||||
|
c = cc
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user