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
|
// FileInfo File information object from the pixeldrain API
|
||||||
type FileInfo struct {
|
type FileInfo struct {
|
||||||
|
Success bool `json:"success"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
FileName string `json:"file_name"`
|
FileName string `json:"file_name"`
|
||||||
DateUpload time.Time `json:"date_upload"`
|
DateUpload time.Time `json:"date_upload"`
|
||||||
DateLastview time.Time `json:"date_last_view"`
|
DateLastview time.Time `json:"date_last_view"`
|
||||||
DaysValid uint16 `json:"days_valid"`
|
|
||||||
FileSize uint64 `json:"file_size"`
|
FileSize uint64 `json:"file_size"`
|
||||||
Views uint `json:"views"`
|
Views uint `json:"views"`
|
||||||
MimeType string `json:"mime_type"`
|
MimeType string `json:"mime_type"`
|
||||||
Description string `json:"description"`
|
|
||||||
MimeImage string `json:"mime_image"`
|
MimeImage string `json:"mime_image"`
|
||||||
ThumbnailHREF string `json:"thumbnail_href"`
|
ThumbnailHREF string `json:"thumbnail_href"`
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package pixelapi
|
package pixelapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ type UserInfo struct {
|
|||||||
Username string `json:"username"`
|
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) {
|
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)
|
||||||
@@ -60,3 +61,21 @@ func (p *PixelAPI) UserSessionDestroy(key string) (resp *SuccessResponse, err *E
|
|||||||
}
|
}
|
||||||
return resp, nil
|
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{
|
.file_button, .file_button:hover{
|
||||||
position: relative;
|
position: relative;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
width: 316px;
|
width: 310px;
|
||||||
max-width: 90%;
|
max-width: 90%;
|
||||||
height: 60px;
|
height: 60px;
|
||||||
float: left;
|
|
||||||
margin: 6px;
|
margin: 6px;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
box-shadow: 0px 0px 5px 2px #111;
|
box-shadow: 0px 0px 10px 4px #111;
|
||||||
background-color: #111;
|
background-color: #111;
|
||||||
color: var(--text_color);
|
color: var(--text_color);
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
line-height: 120%;
|
line-height: 120%;
|
||||||
display: block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
.file_button > img{
|
.file_button > img{
|
||||||
max-height: 60px;
|
max-height: 60px;
|
||||||
|
@@ -13,6 +13,15 @@
|
|||||||
in this browser.
|
in this browser.
|
||||||
</div>
|
</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"}}
|
{{template "analytics"}}
|
||||||
</body>
|
</body>
|
||||||
|
@@ -9,6 +9,20 @@
|
|||||||
<div id='body' class="body">
|
<div id='body' class="body">
|
||||||
{{template "menu" .}}
|
{{template "menu" .}}
|
||||||
<h1>Welcome home, {{.Username}}!</h1>
|
<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"}}
|
{{template "footer"}}
|
||||||
</div>
|
</div>
|
||||||
|
@@ -127,8 +127,7 @@
|
|||||||
"file_name": "01 Holy Wars... The Punishment Due.mp3",
|
"file_name": "01 Holy Wars... The Punishment Due.mp3",
|
||||||
"description": "",
|
"description": "",
|
||||||
"date_created": 1513033304,
|
"date_created": 1513033304,
|
||||||
"date_last_view": 1513033304,
|
"date_last_view": 1513033304
|
||||||
"list_description": ""
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"detail_href": "/file/RKwgZb/info",
|
"detail_href": "/file/RKwgZb/info",
|
||||||
@@ -136,8 +135,7 @@
|
|||||||
"file_name": "02 Hangar 18.mp3",
|
"file_name": "02 Hangar 18.mp3",
|
||||||
"description": "",
|
"description": "",
|
||||||
"date_created": 1513033304,
|
"date_created": 1513033304,
|
||||||
"date_last_view": 1513033304,
|
"date_last_view": 1513033304
|
||||||
"list_description": ""
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"detail_href": "/file/DRaL_e/info",
|
"detail_href": "/file/DRaL_e/info",
|
||||||
@@ -145,8 +143,7 @@
|
|||||||
"file_name": "03 Take No Prisoners.mp3",
|
"file_name": "03 Take No Prisoners.mp3",
|
||||||
"description": "",
|
"description": "",
|
||||||
"date_created": 1513033304,
|
"date_created": 1513033304,
|
||||||
"date_last_view": 1513033304,
|
"date_last_view": 1513033304
|
||||||
"list_description": ""
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,7 @@ type TemplateData struct {
|
|||||||
func (wc *WebController) newTemplateData(w http.ResponseWriter, r *http.Request) *TemplateData {
|
func (wc *WebController) newTemplateData(w http.ResponseWriter, r *http.Request) *TemplateData {
|
||||||
var t = &TemplateData{
|
var t = &TemplateData{
|
||||||
Authenticated: false,
|
Authenticated: false,
|
||||||
Username: "Fornax",
|
Username: "",
|
||||||
APIEndpoint: template.URL(wc.conf.APIURLExternal),
|
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+"/login" /* */, wc.serveTemplate("login"))
|
||||||
r.GET(prefix+"/logout" /* */, wc.serveTemplate("logout"))
|
r.GET(prefix+"/logout" /* */, wc.serveTemplate("logout"))
|
||||||
r.POST(prefix+"/logout" /* */, wc.serveLogout)
|
r.POST(prefix+"/logout" /* */, wc.serveLogout)
|
||||||
r.GET(prefix+"/user" /* */, wc.serveTemplate("user_home"))
|
r.GET(prefix+"/user" /* */, wc.serveUserHome)
|
||||||
r.GET(prefix+"/files" /* */, wc.serveTemplate("file_manager"))
|
r.GET(prefix+"/files" /* */, wc.serveUserFiles)
|
||||||
|
|
||||||
r.NotFound = http.HandlerFunc(wc.serveNotFound)
|
r.NotFound = http.HandlerFunc(wc.serveNotFound)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user