user list listing
This commit is contained in:
@@ -13,15 +13,14 @@ func (p *PixelAPI) GetFile(id string) (io.ReadCloser, error) {
|
||||
|
||||
// FileInfo File information object from the pixeldrain API
|
||||
type FileInfo struct {
|
||||
Success bool `json:"success"`
|
||||
ID string `json:"id"`
|
||||
FileName string `json:"file_name"`
|
||||
DateUpload time.Time `json:"date_upload"`
|
||||
DateLastview time.Time `json:"date_last_view"`
|
||||
DaysValid uint16 `json:"days_valid"`
|
||||
FileSize uint64 `json:"file_size"`
|
||||
Views uint `json:"views"`
|
||||
MimeType string `json:"mime_type"`
|
||||
Description string `json:"description"`
|
||||
MimeImage string `json:"mime_image"`
|
||||
ThumbnailHREF string `json:"thumbnail_href"`
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package pixelapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
@@ -40,7 +41,7 @@ type UserInfo struct {
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
// UserInfo returns information about the logged in user. Required an API key
|
||||
// UserInfo returns information about the logged in user. Requires an API key
|
||||
func (p *PixelAPI) UserInfo() (resp *UserInfo, err *Error) {
|
||||
resp = &UserInfo{}
|
||||
err = p.jsonRequest("GET", p.apiEndpoint+"/user", resp)
|
||||
@@ -60,3 +61,21 @@ func (p *PixelAPI) UserSessionDestroy(key string) (resp *SuccessResponse, err *E
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type UserFiles struct {
|
||||
Success bool `json:"success"`
|
||||
Files []FileInfo `json:"files"`
|
||||
}
|
||||
|
||||
func (p *PixelAPI) UserFiles(page, limit int) (resp *UserFiles, err *Error) {
|
||||
resp = &UserFiles{Files: make([]FileInfo, 0)}
|
||||
err = p.jsonRequest(
|
||||
"GET",
|
||||
fmt.Sprintf("%s/user/files?page=%d&limit=%d", p.apiEndpoint, page, limit),
|
||||
resp,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
@@ -219,20 +219,19 @@ a:hover{
|
||||
.file_button, .file_button:hover{
|
||||
position: relative;
|
||||
box-sizing: border-box;
|
||||
width: 316px;
|
||||
width: 310px;
|
||||
max-width: 90%;
|
||||
height: 60px;
|
||||
float: left;
|
||||
margin: 6px;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
box-shadow: 0px 0px 5px 2px #111;
|
||||
box-shadow: 0px 0px 10px 4px #111;
|
||||
background-color: #111;
|
||||
color: var(--text_color);
|
||||
word-break: break-all;
|
||||
text-align: left;
|
||||
line-height: 120%;
|
||||
display: block;
|
||||
display: inline-block;
|
||||
}
|
||||
.file_button > img{
|
||||
max-height: 60px;
|
||||
|
@@ -13,6 +13,15 @@
|
||||
in this browser.
|
||||
</div>
|
||||
|
||||
<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>
|
||||
|
@@ -9,6 +9,20 @@
|
||||
<div id='body' class="body">
|
||||
{{template "menu" .}}
|
||||
<h1>Welcome home, {{.Username}}!</h1>
|
||||
<hr/>
|
||||
<h2>Your most recently uploaded files:</h2>
|
||||
<div class="highlight_dark border_top border_bottom">
|
||||
{{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}}
|
||||
<a href="/files">...All my files</a>
|
||||
</div>
|
||||
<hr/>
|
||||
|
||||
{{template "footer"}}
|
||||
</div>
|
||||
|
@@ -127,8 +127,7 @@
|
||||
"file_name": "01 Holy Wars... The Punishment Due.mp3",
|
||||
"description": "",
|
||||
"date_created": 1513033304,
|
||||
"date_last_view": 1513033304,
|
||||
"list_description": ""
|
||||
"date_last_view": 1513033304
|
||||
},
|
||||
{
|
||||
"detail_href": "/file/RKwgZb/info",
|
||||
@@ -136,8 +135,7 @@
|
||||
"file_name": "02 Hangar 18.mp3",
|
||||
"description": "",
|
||||
"date_created": 1513033304,
|
||||
"date_last_view": 1513033304,
|
||||
"list_description": ""
|
||||
"date_last_view": 1513033304
|
||||
},
|
||||
{
|
||||
"detail_href": "/file/DRaL_e/info",
|
||||
@@ -145,8 +143,7 @@
|
||||
"file_name": "03 Take No Prisoners.mp3",
|
||||
"description": "",
|
||||
"date_created": 1513033304,
|
||||
"date_last_view": 1513033304,
|
||||
"list_description": ""
|
||||
"date_last_view": 1513033304
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ type TemplateData struct {
|
||||
func (wc *WebController) newTemplateData(w http.ResponseWriter, r *http.Request) *TemplateData {
|
||||
var t = &TemplateData{
|
||||
Authenticated: false,
|
||||
Username: "Fornax",
|
||||
Username: "",
|
||||
APIEndpoint: template.URL(wc.conf.APIURLExternal),
|
||||
}
|
||||
|
||||
|
@@ -21,5 +21,63 @@ func (wc *WebController) serveLogout(
|
||||
}
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/", 302)
|
||||
http.Redirect(w, r, "/", http.StatusPermanentRedirect)
|
||||
}
|
||||
|
||||
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.StatusTemporaryRedirect)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@@ -50,8 +50,8 @@ func New(r *httprouter.Router, prefix string, conf *conf.PixelWebConfig) *WebCon
|
||||
r.GET(prefix+"/login" /* */, wc.serveTemplate("login"))
|
||||
r.GET(prefix+"/logout" /* */, wc.serveTemplate("logout"))
|
||||
r.POST(prefix+"/logout" /* */, wc.serveLogout)
|
||||
r.GET(prefix+"/user" /* */, wc.serveTemplate("user_home"))
|
||||
r.GET(prefix+"/files" /* */, wc.serveTemplate("file_manager"))
|
||||
r.GET(prefix+"/user" /* */, wc.serveUserHome)
|
||||
r.GET(prefix+"/files" /* */, wc.serveUserFiles)
|
||||
|
||||
r.NotFound = http.HandlerFunc(wc.serveNotFound)
|
||||
|
||||
|
Reference in New Issue
Block a user