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 // 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{} resp = &FileInfo{}
err = p.jsonRequest("GET", p.apiEndpoint+"/file/"+id+"/info", resp) err = p.jsonRequest("GET", p.apiEndpoint+"/file/"+id+"/info", resp)
if err != nil { 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 // GetList get a List from the pixeldrain API. Errors will be available through
// List.Error. Standard error checks apply. // 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{} resp = &List{}
err = p.jsonRequest("GET", p.apiEndpoint+"/list/"+id, resp) err = p.jsonRequest("GET", p.apiEndpoint+"/list/"+id, resp)
if err != nil { if err != nil {

View File

@@ -4,7 +4,7 @@ type Recaptcha struct {
SiteKey string `json:"site_key"` 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) err = p.jsonRequest("GET", p.apiEndpoint+"/misc/recpatcha", resp)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -45,7 +45,7 @@ type SuccessResponse struct {
Success bool `json:"success"` 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) req, err := http.NewRequest(method, url, nil)
if err != nil { if err != nil {
return &Error{ return &Error{
@@ -116,7 +116,7 @@ func (p *PixelAPI) getRaw(url string) (io.ReadCloser, error) {
return resp.Body, err 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())) req, err := http.NewRequest("POST", url, strings.NewReader(vals.Encode()))
if err != nil { if err != nil {
return &Error{ return &Error{
@@ -145,7 +145,7 @@ func (p *PixelAPI) postForm(url string, vals url.Values, target interface{}) *Er
return parseJSONResponse(resp, target) 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 jdec = json.NewDecoder(resp.Body)
var err error 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 // 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 // on whether reCaptcha is enabled on the Pixeldrain server, this can be checked
// through the GetRecaptcha function. // 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{} resp = &Registration{}
var form = url.Values{} var form = url.Values{}
form.Add("username", username) form.Add("username", username)
@@ -42,7 +42,7 @@ type UserInfo struct {
} }
// UserInfo returns information about the logged in user. Requires an API key // 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{} resp = &UserInfo{}
err = p.jsonRequest("GET", p.apiEndpoint+"/user", resp) err = p.jsonRequest("GET", p.apiEndpoint+"/user", resp)
if err != nil { 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 // UserSessionDestroy destroys an API key so it can no longer be used to perform
// actions // actions
func (p *PixelAPI) UserSessionDestroy(key string) (resp *SuccessResponse, err *Error) { func (p *PixelAPI) UserSessionDestroy(key string) (resp *SuccessResponse, err error) {
resp = &SuccessResponse{} resp = &SuccessResponse{}
err = p.jsonRequest("DELETE", p.apiEndpoint+"/user/session", resp) err = p.jsonRequest("DELETE", p.apiEndpoint+"/user/session", resp)
if err != nil { if err != nil {
@@ -67,7 +67,7 @@ type UserFiles struct {
Files []FileInfo `json:"files"` 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)} resp = &UserFiles{Files: make([]FileInfo, 0)}
err = p.jsonRequest( err = p.jsonRequest(
"GET", "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); --highlight_border: inset 0px 0px 5px 1px var(--highlight_color), 0px 0px 1px 0px var(--highlight_color);
} }
html{height: 100%;}
body{ body{
background-color: #111; background-color: #111;
background-repeat: repeat; background-repeat: repeat;
@@ -20,26 +22,9 @@ body{
color: var(--text_color); color: var(--text_color);
} }
html{
height: 100%;
}
/* Page layout elements */ /* Page layout elements */
#header{ .header_image{
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{
width: 100%; width: 100%;
max-width: 1000px; max-width: 1000px;
margin-top: 15px; margin-top: 15px;
@@ -131,6 +116,8 @@ html{
/* Common elements */ /* Common elements */
h3{border-bottom: 1px #777 solid;} /* Differentiate it a bit, else it just looks like bold text */
hr{ hr{
height: 8px; height: 8px;
border: none; border: none;
@@ -142,16 +129,9 @@ hr{
width: 12px; /* for vertical scrollbars */ width: 12px; /* for vertical scrollbars */
height: 12px; /* for horizontal scrollbars */ height: 12px; /* for horizontal scrollbars */
} }
::-webkit-scrollbar-track{ ::-webkit-scrollbar-track {background: rgba(0, 0, 0, 0);}
background: rgba(0, 0, 0, 0); ::-webkit-scrollbar-thumb {background-color: #555;}
} ::-webkit-scrollbar-corner{background: transparent;}
::-webkit-scrollbar-thumb{
/*background: rgba(0, 0, 0, 0.5);*/
background-color: #555;
}
::-webkit-scrollbar-corner{
background: transparent;
}
a{ a{
color: var(--highlight_color); color: var(--highlight_color);
@@ -162,6 +142,22 @@ a:hover{
color: var(--highlight_color); 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{ .big_button{
height: 40px; height: 40px;
width: 40%; width: 40%;
@@ -243,9 +239,7 @@ a:hover{
/* Form fields */ /* Form fields */
.form_input { .form_input {width: 100%;}
width: 100%;
}
/* BUTTONS */ /* BUTTONS */
button, button,
@@ -293,10 +287,7 @@ select:active{
.button_red:active {background: linear-gradient(#61152F, #821C40) !important;} .button_red:active {background: linear-gradient(#61152F, #821C40) !important;}
/* Dropdown list of the select tag */ /* Dropdown list of the select tag */
option{ option{background-color: #404040; color: #FFFFFF;}
background-color: #404040;
color: #FFFFFF;
}
/* TEXT FIELDS */ /* TEXT FIELDS */
textarea, 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> <h1>Log in to your PixelDrain account</h1>
<div id="submit_result"></div> <div id="submit_result"></div>
<form onSubmit="return submitForm();" class="highlight_dark border_top border_bottom"> <form onSubmit="return submitForm();" class="highlight_dark border_top border_bottom">
<table style="margin-left: auto; margin-right: auto;"> <table class="form">
<tr> <tr class="form">
<td>Username</td> <td>Username</td>
<td><input id="username" name="username" type="text" autocomplete="username" value=""/></td> <td><input id="username" name="username" type="text" autocomplete="username" value=""/></td>
</tr> </tr>
<tr> <tr class="form">
<td>Password</td> <td>Password</td>
<td><input id="password" name="password" type="password" autocomplete="current-password"/></td> <td><input id="password" name="password" type="password" autocomplete="current-password"/></td>
</tr> </tr>
<tr> <tr class="form">
<td colspan=2 style="text-align: right;"><input type="submit" value="Login" class="button_highlight"/></td> <td colspan=2 style="text-align: right;"><input type="submit" value="Login" class="button_highlight"/></td>
</tr> </tr>
</table> </table>

View File

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

View File

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

View File

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

View File

@@ -2,7 +2,30 @@
<html> <html>
<head> <head>
{{template "meta_tags" "API Documentation"}} {{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> </head>
<body> <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"}} {{define "menu"}}
<div id="navigation" class="highlight_light border_top border_bottom navigation"> <div id="navigation" class="highlight_light border_top border_bottom navigation">
<a href="/">Home</a> <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> <a href="/api">API</a>
{{if .Authenticated}}<a href="/user">{{.Username}}</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}} <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> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Paste ~ PixelDrain</title> {{template "meta_tags" "Text Upload"}}
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="/global.css"/>
<link rel="stylesheet" href="/res/style/viewer.css"/> <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> <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"/> <style>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> .textarea{
position: absolute;
<meta property="og:type" content="website" /> top: 0;
<meta property="og:title" content="Paste ~ PixelDrain" /> left: 0;
<meta property="og:site_name" content="PixelDrain" /> height: 100%;
<meta property="og:description" content="Upload text to PixelDrain" /> width: 100%;
<meta property="article:author" content="Fornax96" /> border: none !important;
background: #202020;
}
</style>
</head> </head>
<body> <body>
@@ -45,8 +37,8 @@
</button> </button>
</form> </form>
<iframe id='sponsors' data-aa='73974' <iframe id='sponsors' data-aa='73974'
src='//ad.a-ads.com/73974?size=120x600&amp;background_color=000000&amp;text_color=eeeeee&amp;title_color=eeeeee&amp;link_color=9fcf6c&amp;link_hover_color=d2ffa1&amp;title_hover_color=d2ffa1' src='//ad.a-ads.com/73974?size=120x600&amp;background_color=000000&amp;text_color=eeeeee&amp;title_color=eeeeee&amp;link_color=9fcf6c&amp;link_hover_color=d2ffa1&amp;title_hover_color=d2ffa1'
scrolling='no' allowtransparency='true' seamless="seamless"> scrolling='no' allowtransparency='true' seamless="seamless">
</iframe> </iframe>
</div> </div>
@@ -57,4 +49,4 @@
{{template "analytics"}} {{template "analytics"}}
</body> </body>
</html> </html>
{{end}} {{end}}

View File

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

View File

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

View File

@@ -23,61 +23,3 @@ func (wc *WebController) serveLogout(
http.Redirect(w, r, "/", http.StatusSeeOther) 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 // Serve static files
r.ServeFiles(prefix+"/res/*filepath", http.Dir(wc.staticResourceDir+"/res")) 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+"/favicon.ico" /* */, wc.serveFile("/favicon.ico"))
r.GET(prefix+"/global.css" /* */, wc.globalCSSHandler) r.GET(prefix+"/global.css" /* */, wc.globalCSSHandler)
r.GET(prefix+"/api" /* */, wc.serveTemplate("apidoc")) r.GET(prefix+"/api" /* */, wc.serveTemplate("apidoc", false))
r.GET(prefix+"/history" /* */, wc.serveTemplate("history_cookies")) r.GET(prefix+"/history" /* */, wc.serveTemplate("history_cookies", false))
r.GET(prefix+"/u/:id" /* */, wc.serveFileViewer) r.GET(prefix+"/u/:id" /* */, wc.serveFileViewer)
r.GET(prefix+"/u/:id/preview" /**/, wc.serveFilePreview) r.GET(prefix+"/u/:id/preview" /**/, wc.serveFilePreview)
r.GET(prefix+"/l/:id" /* */, wc.serveListViewer) 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+"/register" /* */, wc.serveTemplate("register", false))
r.GET(prefix+"/login" /* */, wc.serveTemplate("login")) r.GET(prefix+"/login" /* */, wc.serveTemplate("login", false))
r.GET(prefix+"/logout" /* */, wc.serveTemplate("logout")) r.GET(prefix+"/logout" /* */, wc.serveTemplate("logout", true))
r.POST(prefix+"/logout" /* */, wc.serveLogout) r.POST(prefix+"/logout" /* */, wc.serveLogout)
r.GET(prefix+"/user" /* */, wc.serveUserHome) r.GET(prefix+"/user" /* */, wc.serveTemplate("user_home", true))
r.GET(prefix+"/files" /* */, wc.serveUserFiles) r.GET(prefix+"/user/files" /* */, wc.serveTemplate("user_files", true))
r.NotFound = http.HandlerFunc(wc.serveNotFound) r.NotFound = http.HandlerFunc(wc.serveNotFound)
return wc return wc
} }
func (wc *WebController) ReloadTemplates() { func (wc *WebController) serveTemplate(
wc.templates.ParseTemplates(false) tpl string,
} requireAuth bool,
) httprouter.Handle {
func (wc *WebController) serveTemplate(tpl string) httprouter.Handle {
return func( return func(
w http.ResponseWriter, w http.ResponseWriter,
r *http.Request, r *http.Request,
p httprouter.Params, 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 { if err != nil {
log.Error("Error executing template '%s': %s", tpl, err) 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) { func (wc *WebController) serveNotFound(w http.ResponseWriter, r *http.Request) {
log.Debug("Not Found: %s", r.URL) 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) { func (wc *WebController) getAPIKey(r *http.Request) (key string, err error) {