Just a whole bunch of fixing

This commit is contained in:
2018-07-09 21:41:17 +02:00
parent 5633460b97
commit 9c7b79403e
25 changed files with 208 additions and 320 deletions

View File

@@ -26,7 +26,7 @@ type FileInfo struct {
}
// GetFileInfo gets the FileInfo from the pixeldrain API
func (p *PixelAPI) GetFileInfo(id string) (resp *FileInfo, err *Error) {
func (p *PixelAPI) GetFileInfo(id string) (resp *FileInfo, err error) {
resp = &FileInfo{}
err = p.jsonRequest("GET", p.apiEndpoint+"/file/"+id+"/info", resp)
if err != nil {

View File

@@ -27,7 +27,7 @@ type ListFile struct {
// GetList get a List from the pixeldrain API. Errors will be available through
// List.Error. Standard error checks apply.
func (p *PixelAPI) GetList(id string) (resp *List, err *Error) {
func (p *PixelAPI) GetList(id string) (resp *List, err error) {
resp = &List{}
err = p.jsonRequest("GET", p.apiEndpoint+"/list/"+id, resp)
if err != nil {

View File

@@ -4,7 +4,7 @@ type Recaptcha struct {
SiteKey string `json:"site_key"`
}
func (p *PixelAPI) GetRecaptcha() (resp *Recaptcha, err *Error) {
func (p *PixelAPI) GetRecaptcha() (resp *Recaptcha, err error) {
err = p.jsonRequest("GET", p.apiEndpoint+"/misc/recpatcha", resp)
if err != nil {
return nil, err

View File

@@ -45,7 +45,7 @@ type SuccessResponse struct {
Success bool `json:"success"`
}
func (p *PixelAPI) jsonRequest(method, url string, target interface{}) *Error {
func (p *PixelAPI) jsonRequest(method, url string, target interface{}) error {
req, err := http.NewRequest(method, url, nil)
if err != nil {
return &Error{
@@ -116,7 +116,7 @@ func (p *PixelAPI) getRaw(url string) (io.ReadCloser, error) {
return resp.Body, err
}
func (p *PixelAPI) postForm(url string, vals url.Values, target interface{}) *Error {
func (p *PixelAPI) postForm(url string, vals url.Values, target interface{}) error {
req, err := http.NewRequest("POST", url, strings.NewReader(vals.Encode()))
if err != nil {
return &Error{
@@ -145,7 +145,7 @@ func (p *PixelAPI) postForm(url string, vals url.Values, target interface{}) *Er
return parseJSONResponse(resp, target)
}
func parseJSONResponse(resp *http.Response, target interface{}) *Error {
func parseJSONResponse(resp *http.Response, target interface{}) error {
var jdec = json.NewDecoder(resp.Body)
var err error

View File

@@ -21,7 +21,7 @@ type RegistrationError struct {
// never be able to reset your password in case you forget it. captcha depends
// on whether reCaptcha is enabled on the Pixeldrain server, this can be checked
// through the GetRecaptcha function.
func (p *PixelAPI) UserRegister(username, email, password, captcha string) (resp *Registration, err *Error) {
func (p *PixelAPI) UserRegister(username, email, password, captcha string) (resp *Registration, err error) {
resp = &Registration{}
var form = url.Values{}
form.Add("username", username)
@@ -42,7 +42,7 @@ type UserInfo struct {
}
// UserInfo returns information about the logged in user. Requires an API key
func (p *PixelAPI) UserInfo() (resp *UserInfo, err *Error) {
func (p *PixelAPI) UserInfo() (resp *UserInfo, err error) {
resp = &UserInfo{}
err = p.jsonRequest("GET", p.apiEndpoint+"/user", resp)
if err != nil {
@@ -53,7 +53,7 @@ func (p *PixelAPI) UserInfo() (resp *UserInfo, err *Error) {
// UserSessionDestroy destroys an API key so it can no longer be used to perform
// actions
func (p *PixelAPI) UserSessionDestroy(key string) (resp *SuccessResponse, err *Error) {
func (p *PixelAPI) UserSessionDestroy(key string) (resp *SuccessResponse, err error) {
resp = &SuccessResponse{}
err = p.jsonRequest("DELETE", p.apiEndpoint+"/user/session", resp)
if err != nil {
@@ -67,7 +67,7 @@ type UserFiles struct {
Files []FileInfo `json:"files"`
}
func (p *PixelAPI) UserFiles(page, limit int) (resp *UserFiles, err *Error) {
func (p *PixelAPI) UserFiles(page, limit int) (resp *UserFiles, err error) {
resp = &UserFiles{Files: make([]FileInfo, 0)}
err = p.jsonRequest(
"GET",

View File

@@ -1,76 +0,0 @@
/*
Created on : Feb 19, 2017, 11:21:45 AM
Author : Fornax <fornax@pixeldrain.com>
*/
/* Global Definitions */
.api_doc_details{
border-top: 1px solid;
border-bottom: 1px solid;
margin-top: 10px;
margin: 15px -8px 15px -8px;
}
.api_doc_details > summary {
padding: 2px;
font-family: monospace;
}
.api_doc_details > summary > .method {
display: inline-block;
width: 80px;
}
.api_doc_details > div {
padding: 8px;
}
table{
border-collapse: collapse;
width: 100%;
}
tr{
border-bottom: 1px #333 solid;
}
tr > td {
padding: 6px;
}
pre{
padding: 2px;
border-bottom: 1px #333 solid;
overflow-x: scroll;
}
h3{
border-bottom: 1px #777 solid;
}
/* GET requests */
.api_doc_details.request_get{
border-color: rgb(54, 54, 255);
background-color: rgba(32, 32, 255, 0.2);
}
/* POST requests */
.api_doc_details.request_post{
border-color: #00d000;
background-color: rgba(0, 255, 0, 0.05);
}
/* DELETE requests */
.api_doc_details.request_delete{
border-color: #B00000;
background-color: rgba(255, 0, 0, 0.05);
}
/* PUT requests */
.api_doc_details.request_put{
border-color: #B06000;
background-color: rgba(255, 128, 0, 0.05);
}
/* PATCH requests */
.api_doc_details.request_patch{
border-color: #6000B0;
background-color: rgba(128, 0, 255, 0.1);
}

View File

@@ -1,35 +0,0 @@
/*
Created on : Aug 27, 2015, 9:31:34 PM
Author : Fornax
*/
.text-warning{
position: relative;
width: auto;
height: auto;
background: #656762 no-repeat top center;
border: #9FCF6C ridge 4px;
margin: 10px;
font-size: 18px;
color: #ff9090;
}
.text-info{
position: relative;
width: auto;
height: auto;
background: #656762 no-repeat top center;
border: #9FCF6C ridge 4px;
margin: 10px;
}
.g-recaptcha{
overflow:hidden;
width:298px;
height:74px;
}
.g-recaptcha > div > div > iframe{
margin:-1px 0px 0px -2px;
}

View File

@@ -7,6 +7,8 @@
--highlight_border: inset 0px 0px 5px 1px var(--highlight_color), 0px 0px 1px 0px var(--highlight_color);
}
html{height: 100%;}
body{
background-color: #111;
background-repeat: repeat;
@@ -20,26 +22,9 @@ body{
color: var(--text_color);
}
html{
height: 100%;
}
/* Page layout elements */
#header{
position: relative;
width: auto;
height: auto;
margin: 0 -8px 0 -8px;
box-sizing: border-box;
overflow: hidden;
background-color: #222;
text-align: center;
z-index: 101;
border-bottom: #606060 solid 1px;
}
#header_image{
.header_image{
width: 100%;
max-width: 1000px;
margin-top: 15px;
@@ -131,6 +116,8 @@ html{
/* Common elements */
h3{border-bottom: 1px #777 solid;} /* Differentiate it a bit, else it just looks like bold text */
hr{
height: 8px;
border: none;
@@ -142,16 +129,9 @@ hr{
width: 12px; /* for vertical scrollbars */
height: 12px; /* for horizontal scrollbars */
}
::-webkit-scrollbar-track{
background: rgba(0, 0, 0, 0);
}
::-webkit-scrollbar-thumb{
/*background: rgba(0, 0, 0, 0.5);*/
background-color: #555;
}
::-webkit-scrollbar-corner{
background: transparent;
}
::-webkit-scrollbar-track {background: rgba(0, 0, 0, 0);}
::-webkit-scrollbar-thumb {background-color: #555;}
::-webkit-scrollbar-corner{background: transparent;}
a{
color: var(--highlight_color);
@@ -162,6 +142,22 @@ a:hover{
color: var(--highlight_color);
}
.form{
margin-left: auto;
margin-right: auto;
text-align: left;
max-width: 30em;
}
table:not(.form) {border-collapse: collapse; width: 100%;}
tr:not(.form) {border-bottom: 1px #333 solid;}
tr > td {padding: 6px;}
pre{
padding: 2px;
border-bottom: 1px #333 solid;
overflow-x: scroll;
}
.big_button{
height: 40px;
width: 40%;
@@ -243,9 +239,7 @@ a:hover{
/* Form fields */
.form_input {
width: 100%;
}
.form_input {width: 100%;}
/* BUTTONS */
button,
@@ -293,10 +287,7 @@ select:active{
.button_red:active {background: linear-gradient(#61152F, #821C40) !important;}
/* Dropdown list of the select tag */
option{
background-color: #404040;
color: #FFFFFF;
}
option{background-color: #404040; color: #FFFFFF;}
/* TEXT FIELDS */
textarea,

View File

@@ -1,14 +0,0 @@
/*
Created on : Jul 1, 2015, 8:02:38 PM
Author : Fornax
*/
.textarea{
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
border: none !important;
background: #202020;
}

View File

@@ -1 +0,0 @@
/* Nothing to see here */

25
res/template/404.html Normal file
View File

@@ -0,0 +1,25 @@
{{define "404"}}<!DOCTYPE html>
<html>
<head>
{{template "meta_tags" "Not Found"}}
</head>
<body>
<div id='body' class="body">
{{template "menu" .}}
<br/>
<h1>This page does not exist!</h1>
If you came here by a link from this very same website you can tell
me about it on <a href="https://twitter.com/Fornax96">twitter</a>.
<br/><br/>
Either way, there's nothing to see here, so you'll have to
<a href='/'>head over to the home page</a>.
<br/>
<br/>
Bye!
{{template "footer"}}
</div>
{{template "analytics"}}
</body>
</html>
{{end}}

26
res/template/500.html Normal file
View File

@@ -0,0 +1,26 @@
{{define "500"}}<!DOCTYPE html>
<html>
<head>
{{template "meta_tags" "Internal Server Error"}}
</head>
<body>
<div id='body' class="body">
{{template "menu" .}}
<br/>
<h1>You broke pixeldrain</h1>
Great job.
<br/><br/>
But not to worry, the engineering team has been pulled out of bed to
have a look at the issue. You can try again in a few minutes (maybe
hours, who knows?), or go back to the <a href='/'>home page</a> and
start over.
<br/>
<br/>
Bye!
{{template "footer"}}
</div>
{{template "analytics"}}
</body>
</html>
{{end}}

View File

@@ -0,0 +1,24 @@
{{define "file_manager"}}<!DOCTYPE html>
<html>
<head>
{{template "meta_tags" "File Manager"}}
<script type="text/javascript">var apiEndpoint = '{{.APIEndpoint}}';</script>
</head>
<body>
{{template "menu" .}}
<br/>
{{range .Other.Files}}
<a class="file_button" href="/u/{{.ID}}" target="_blank">
<img src="{{$.APIEndpoint}}/file/{{.ID}}/thumbnail" alt="{{.FileName}}" />
<span style="color: var(--highlight_color);">{{.FileName}}</span>
<br/>
{{.DateUpload}}
</a>
{{end}}
{{template "analytics"}}
</body>
</html>
{{end}}

View File

@@ -12,16 +12,16 @@
<h1>Log in to your PixelDrain account</h1>
<div id="submit_result"></div>
<form onSubmit="return submitForm();" class="highlight_dark border_top border_bottom">
<table style="margin-left: auto; margin-right: auto;">
<tr>
<table class="form">
<tr class="form">
<td>Username</td>
<td><input id="username" name="username" type="text" autocomplete="username" value=""/></td>
</tr>
<tr>
<tr class="form">
<td>Password</td>
<td><input id="password" name="password" type="password" autocomplete="current-password"/></td>
</tr>
<tr>
<tr class="form">
<td colspan=2 style="text-align: right;"><input type="submit" value="Login" class="button_highlight"/></td>
</tr>
</table>

View File

@@ -14,36 +14,36 @@
<div id="submit_result"></div>
<form onSubmit="return submitForm();" class="highlight_dark border_top border_bottom">
<table style="margin-left: auto; margin-right: auto; text-align: left; max-width: 30em;">
<tr>
<tr class="form">
<td>Username</td>
<td><input id="register_username" type="text" autocomplete="username" class="form_input"/></td>
</tr>
<tr><td colspan="2">used for logging into your account<br/><hr/></td></tr>
<tr>
<tr class="form"><td colspan="2">used for logging into your account<br/><hr/></td></tr>
<tr class="form">
<td>E-mail address</td>
<td><input id="register_email" type="text" autocomplete="email" class="form_input"/></td>
</tr>
<tr><td colspan="2">
<tr class="form"><td colspan="2">
not required. your e-mail address will only be used for
password resets and important account notifications<br/>
<hr/>
</td></tr>
<tr>
<tr class="form">
<td>Password</td>
<td><input id="register_password1" type="password" autocomplete="new-password" class="form_input"/></td>
</tr>
<tr>
<tr class="form">
<td>Password verification</td>
<td><input id="register_password2" type="password" autocomplete="new-password" class="form_input"/></td>
</tr>
<tr>
<tr class="form">
<td colspan="2">
you need to enter your password twice so we can
verify that you have not made any typing errors<br/>
<hr/>
</td>
</tr>
<tr>
<tr class="form">
<td>
Turing test<br/>
(Click the white box)
@@ -52,14 +52,18 @@
<div class="g-recaptcha" data-theme="dark" data-sitekey="6LdEeQ0TAAAAALBmDF_k_2LgbpuJM66PGspByViS"></div>
</td>
</tr>
<tr>
<tr class="form">
<td colspan="2">
the reCaptcha turing test verifies that you are not
an evil robot that is trying to flood the website
with fake accounts<br/><hr/>
</td>
</tr>
<tr><td colspan="2" style="text-align: right;"><input type="submit" value="Register" class="button_highlight"/></td></tr>
<tr class="form">
<td colspan="2" style="text-align: right;">
<input type="submit" value="Register" class="button_highlight"/>
</td>
</tr>
</table>
</form>
<br/>

View File

@@ -1,7 +1,7 @@
{{define "file_manager"}}<!DOCTYPE html>
{{define "user_files"}}<!DOCTYPE html>
<html>
<head>
{{template "meta_tags" "File Manager"}}
{{template "meta_tags" "Files"}}
<script type="text/javascript">var apiEndpoint = '{{.APIEndpoint}}';</script>
</head>
@@ -14,7 +14,8 @@
</div>
<br/>
{{range .Other.Files}}
{{$files := .PixelAPI.UserFiles 0 1000}}
{{range $files.Files}}
<a class="file_button" href="/u/{{.ID}}" target="_blank">
<img src="{{$.APIEndpoint}}/file/{{.ID}}/thumbnail" alt="{{.FileName}}" />
<span style="color: var(--highlight_color);">{{.FileName}}</span>

View File

@@ -12,7 +12,8 @@
<hr/>
<h2>Your most recently uploaded files:</h2>
<div class="highlight_dark border_top border_bottom">
{{range .Other.Files}}
{{$files := .PixelAPI.UserFiles 0 18}}
{{range $files.Files}}
<a class="file_button" href="/u/{{.ID}}" target="_blank">
<img src="{{$.APIEndpoint}}/file/{{.ID}}/thumbnail" alt="{{.FileName}}" />
<span style="color: var(--highlight_color);">{{.FileName}}</span>
@@ -21,7 +22,7 @@
</a>
{{end}}
<br/>
<a href="/files">...All my files</a>
<a href="/user/files">...All my files</a>
</div>
<hr/>

View File

@@ -2,7 +2,30 @@
<html>
<head>
{{template "meta_tags" "API Documentation"}}
<link rel="stylesheet" href="/res/style/apidoc.css"/>
<style>
.api_doc_details{
border-top: 1px solid;
border-bottom: 1px solid;
margin: 15px -8px 15px -8px;
}
.api_doc_details > summary {
padding: 2px;
font-family: monospace;
}
.api_doc_details > summary > .method {
display: inline-block;
width: 80px;
}
.api_doc_details > div {
padding: 8px;
}
.api_doc_details.request_get{ border-color: #3636ff; background-color: rgba(32, 32, 255, 0.2);} /* GET requests */
.api_doc_details.request_post{ border-color: #00d000; background-color: rgba(0, 255, 0, 0.05);} /* POST requests */
.api_doc_details.request_delete{border-color: #B00000; background-color: rgba(255, 0, 0, 0.05);} /* DELETE requests */
.api_doc_details.request_put{ border-color: #B06000; background-color: rgba(255, 128, 0, 0.05);} /* PUT requests */
.api_doc_details.request_patch{ border-color: #6000B0; background-color: rgba(128, 0, 255, 0.1);} /* PATCH requests */
</style>
</head>
<body>

View File

@@ -1,23 +0,0 @@
{{define "error"}}<!DOCTYPE html>
<html>
<head>
{{template "meta_tags" "Error"}}
</head>
<body>
<div id='body' class="body">
{{template "menu" .}}
<br/>
<h1>Some Error occurred</h1>
Either you made a mistake, or I made a mistake.
<br/><br/>
Either way, there's nothing to see here, so you'll have to <a href='/'>head over to the home page</a>.
<br/>
<br/>
Bye!
{{template "footer"}}
</div>
{{template "analytics"}}
</body>
</html>
{{end}}

View File

@@ -1,7 +1,7 @@
{{define "menu"}}
<div id="navigation" class="highlight_light border_top border_bottom navigation">
<a href="/">Home</a>
<a href="{{if .Authenticated}}/files{{else}}/history{{end}}">My&nbsp;Files</a>
<a href="{{if .Authenticated}}/user/files{{else}}/history{{end}}">My&nbsp;Files</a>
<a href="/api">API</a>
{{if .Authenticated}}<a href="/user">{{.Username}}</a>
<a href="/logout" style="vertical-align: 0.6em; font-size: 0.9em; padding: 1px;">(Log out)</a>{{else}}

View File

@@ -2,28 +2,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Paste ~ PixelDrain</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="/global.css"/>
{{template "meta_tags" "Text Upload"}}
<link rel="stylesheet" href="/res/style/viewer.css"/>
<link rel="stylesheet" href="/res/style/layout.css"/>
<link rel="stylesheet" href="/res/style/paste.css"/>
<link href='https://fonts.googleapis.com/css?family=Ubuntu' rel='stylesheet' type='text/css'/>
<link rel="shortcut icon" href="/res/img/tray32.png"/>
<meta name="theme-color" content="#9FCF6C"/>
<link rel="icon" sizes="180x180" href="res/img/pixeldrain.png"/>
<link rel="icon" sizes="256x256" href="res/img/pixeldrain_big.png"/>
<script src="/res/script/jquery-2.1.4.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<meta property="og:type" content="website" />
<meta property="og:title" content="Paste ~ PixelDrain" />
<meta property="og:site_name" content="PixelDrain" />
<meta property="og:description" content="Upload text to PixelDrain" />
<meta property="article:author" content="Fornax96" />
<style>
.textarea{
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
border: none !important;
background: #202020;
}
</style>
</head>
<body>

View File

@@ -4,22 +4,23 @@ import (
"fmt"
"net/http"
"fornaxian.com/pixeldrain-web/pixelapi"
"github.com/Fornaxian/log"
"github.com/julienschmidt/httprouter"
)
// ServeListViewer controller for GET /l/:id
func (wc *WebController) serveListViewer(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
var list, aerr = wc.api.GetList(p.ByName("id"))
if aerr != nil {
if aerr.ReqError {
log.Error("API request error occurred: %s", aerr.Value)
var list, err = wc.api.GetList(p.ByName("id"))
if err != nil {
if (err.(pixelapi.Error)).ReqError {
log.Error("API request error occurred: %s", (err.(pixelapi.Error)).Value)
}
wc.serveNotFound(w, r)
return
}
var err error
var ogData OGData
listdata := map[string]interface{}{
"id": list.ID,

View File

@@ -15,6 +15,7 @@ type TemplateData struct {
Authenticated bool
Username string
APIEndpoint template.URL
PixelAPI *pixelapi.PixelAPI
Other interface{}
Title string
@@ -28,11 +29,11 @@ func (wc *WebController) newTemplateData(w http.ResponseWriter, r *http.Request)
}
if key, err := wc.getAPIKey(r); err == nil {
var api = pixelapi.New(wc.conf.APIURLInternal, key)
uinf, err := api.UserInfo()
t.PixelAPI = pixelapi.New(wc.conf.APIURLInternal, key)
uinf, err := t.PixelAPI.UserInfo()
if err != nil {
// This session key doesn't work, delete it
log.Debug("Invalid API key '%s' passed", key)
log.Debug("Session check for key '%s' failed: %s", key, err)
http.SetCookie(w, &http.Cookie{
Name: "pd_auth_key",
Value: "",
@@ -45,6 +46,8 @@ func (wc *WebController) newTemplateData(w http.ResponseWriter, r *http.Request)
// Authentication succeeded
t.Authenticated = true
t.Username = uinf.Username
} else {
t.PixelAPI = pixelapi.New(wc.conf.APIURLInternal, "")
}
return t

View File

@@ -23,61 +23,3 @@ func (wc *WebController) serveLogout(
http.Redirect(w, r, "/", http.StatusSeeOther)
}
func (wc *WebController) serveUserHome(
w http.ResponseWriter,
r *http.Request,
p httprouter.Params,
) {
var key string
var err error
if key, err = wc.getAPIKey(r); err != nil {
http.Redirect(w, r, "/", http.StatusSeeOther)
return
}
var api = pixelapi.New(wc.conf.APIURLInternal, key)
files, aerr := api.UserFiles(0, 18)
if aerr != nil {
log.Error("Cannot get user files: %v", aerr)
wc.serveNotFound(w, r)
return
}
templateData := wc.newTemplateData(w, r)
templateData.Other = files
err = wc.templates.Get().ExecuteTemplate(w, "user_home", templateData)
if err != nil {
log.Error("Failed to execute template: %s", err)
}
}
func (wc *WebController) serveUserFiles(
w http.ResponseWriter,
r *http.Request,
p httprouter.Params,
) {
var key string
var err error
if key, err = wc.getAPIKey(r); err != nil {
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
return
}
var api = pixelapi.New(wc.conf.APIURLInternal, key)
files, aerr := api.UserFiles(0, 1000)
if aerr != nil {
log.Error("Cannot get user files: %v", aerr)
wc.serveNotFound(w, r)
return
}
templateData := wc.newTemplateData(w, r)
templateData.Other = files
err = wc.templates.Get().ExecuteTemplate(w, "file_manager", templateData)
if err != nil {
log.Error("Failed to execute template: %s", err)
}
}

View File

@@ -36,39 +36,43 @@ func New(r *httprouter.Router, prefix string, conf *conf.PixelWebConfig) *WebCon
// Serve static files
r.ServeFiles(prefix+"/res/*filepath", http.Dir(wc.staticResourceDir+"/res"))
r.GET(prefix+"/" /* */, wc.serveTemplate("home"))
r.GET(prefix+"/" /* */, wc.serveTemplate("home", false))
r.GET(prefix+"/favicon.ico" /* */, wc.serveFile("/favicon.ico"))
r.GET(prefix+"/global.css" /* */, wc.globalCSSHandler)
r.GET(prefix+"/api" /* */, wc.serveTemplate("apidoc"))
r.GET(prefix+"/history" /* */, wc.serveTemplate("history_cookies"))
r.GET(prefix+"/api" /* */, wc.serveTemplate("apidoc", false))
r.GET(prefix+"/history" /* */, wc.serveTemplate("history_cookies", false))
r.GET(prefix+"/u/:id" /* */, wc.serveFileViewer)
r.GET(prefix+"/u/:id/preview" /**/, wc.serveFilePreview)
r.GET(prefix+"/l/:id" /* */, wc.serveListViewer)
r.GET(prefix+"/t" /* */, wc.serveTemplate("paste"))
r.GET(prefix+"/t" /* */, wc.serveTemplate("paste", false))
r.GET(prefix+"/register" /* */, wc.serveTemplate("register"))
r.GET(prefix+"/login" /* */, wc.serveTemplate("login"))
r.GET(prefix+"/logout" /* */, wc.serveTemplate("logout"))
r.GET(prefix+"/register" /* */, wc.serveTemplate("register", false))
r.GET(prefix+"/login" /* */, wc.serveTemplate("login", false))
r.GET(prefix+"/logout" /* */, wc.serveTemplate("logout", true))
r.POST(prefix+"/logout" /* */, wc.serveLogout)
r.GET(prefix+"/user" /* */, wc.serveUserHome)
r.GET(prefix+"/files" /* */, wc.serveUserFiles)
r.GET(prefix+"/user" /* */, wc.serveTemplate("user_home", true))
r.GET(prefix+"/user/files" /* */, wc.serveTemplate("user_files", true))
r.NotFound = http.HandlerFunc(wc.serveNotFound)
return wc
}
func (wc *WebController) ReloadTemplates() {
wc.templates.ParseTemplates(false)
}
func (wc *WebController) serveTemplate(tpl string) httprouter.Handle {
func (wc *WebController) serveTemplate(
tpl string,
requireAuth bool,
) httprouter.Handle {
return func(
w http.ResponseWriter,
r *http.Request,
p httprouter.Params,
) {
err := wc.templates.Get().ExecuteTemplate(w, tpl, wc.newTemplateData(w, r))
var tpld = wc.newTemplateData(w, r)
if requireAuth && !tpld.Authenticated {
http.Redirect(w, r, "/login", http.StatusSeeOther)
return
}
err := wc.templates.Get().ExecuteTemplate(w, tpl, tpld)
if err != nil {
log.Error("Error executing template '%s': %s", tpl, err)
}
@@ -87,7 +91,7 @@ func (wc *WebController) serveFile(path string) httprouter.Handle {
func (wc *WebController) serveNotFound(w http.ResponseWriter, r *http.Request) {
log.Debug("Not Found: %s", r.URL)
wc.templates.Get().ExecuteTemplate(w, "error", wc.newTemplateData(w, r))
wc.templates.Get().ExecuteTemplate(w, "404", wc.newTemplateData(w, r))
}
func (wc *WebController) getAPIKey(r *http.Request) (key string, err error) {