add lists to user home
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package pixelapi
|
package pixelapi
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
// API error constants
|
// API error constants
|
||||||
const (
|
const (
|
||||||
ListNotFoundError = "list_not_found"
|
ListNotFoundError = "list_not_found"
|
||||||
@@ -7,22 +9,23 @@ const (
|
|||||||
|
|
||||||
// List information object from the pixeldrain API
|
// List information object from the pixeldrain API
|
||||||
type List struct {
|
type List struct {
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
DateCreated int64 `json:"date_created"`
|
DateCreated time.Time `json:"date_created"`
|
||||||
|
FileCount int `json:"file_count"`
|
||||||
Files []ListFile
|
Files []ListFile
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListFile information object from the pixeldrain API
|
// ListFile information object from the pixeldrain API
|
||||||
type ListFile struct {
|
type ListFile struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
DetailHREF string `json:"detail_href"`
|
DetailHREF string `json:"detail_href"`
|
||||||
FileName string `json:"file_name"`
|
FileName string `json:"file_name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
DateCreated int64 `json:"date_created"`
|
DateCreated time.Time `json:"date_created"`
|
||||||
DateLastView int64 `json:"date_last_view"`
|
DateLastView time.Time `json:"date_last_view"`
|
||||||
ListDescription string `json:"list_description"`
|
ListDescription string `json:"list_description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
@@ -48,7 +48,7 @@ type SuccessResponse struct {
|
|||||||
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{
|
||||||
ReqError: true,
|
ReqError: true,
|
||||||
Success: false,
|
Success: false,
|
||||||
Value: err.Error(),
|
Value: err.Error(),
|
||||||
@@ -62,7 +62,7 @@ func (p *PixelAPI) jsonRequest(method, url string, target interface{}) error {
|
|||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &Error{
|
return Error{
|
||||||
ReqError: true,
|
ReqError: true,
|
||||||
Success: false,
|
Success: false,
|
||||||
Value: err.Error(),
|
Value: err.Error(),
|
||||||
|
@@ -79,3 +79,21 @@ func (p *PixelAPI) UserFiles(page, limit int) (resp *UserFiles, err error) {
|
|||||||
}
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UserLists struct {
|
||||||
|
Success bool `json:"success"`
|
||||||
|
Lists []List `json:"lists"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PixelAPI) UserLists(page, limit int) (resp *UserLists, err error) {
|
||||||
|
resp = &UserLists{Lists: make([]List, 0)}
|
||||||
|
err = p.jsonRequest(
|
||||||
|
"GET",
|
||||||
|
fmt.Sprintf("%s/user/lists?page=%d&limit=%d", p.apiEndpoint, page, limit),
|
||||||
|
resp,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
BIN
res/static/res/img/icon_list.png
Normal file
BIN
res/static/res/img/icon_list.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.8 KiB |
@@ -20,7 +20,7 @@
|
|||||||
<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>
|
||||||
<br/>
|
<br/>
|
||||||
{{.DateUpload}}
|
{{.DateUpload.Format "2006-01-02 15:04:05"}}
|
||||||
</a>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
@@ -18,12 +18,27 @@
|
|||||||
<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>
|
||||||
<br/>
|
<br/>
|
||||||
{{.DateUpload}}
|
{{.DateUpload.Format "2006-01-02 15:04:05"}}
|
||||||
</a>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
<br/>
|
<br/>
|
||||||
<a href="/user/files">...All my files</a>
|
<a href="/user/files">...All my files</a>
|
||||||
</div>
|
</div>
|
||||||
|
<br/>
|
||||||
|
<h2>Your most recently created lists:</h2>
|
||||||
|
<div class="highlight_dark border_top border_bottom">
|
||||||
|
{{$lists := .PixelAPI.UserLists 0 18}}
|
||||||
|
{{range $lists.Lists}}
|
||||||
|
<a class="file_button" href="/l/{{.ID}}" target="_blank">
|
||||||
|
<img src="{{$.APIEndpoint}}/list/{{.ID}}/thumbnail" alt="{{.Title}}" />
|
||||||
|
<span style="color: var(--highlight_color);">{{.Title}}</span>
|
||||||
|
({{.FileCount}} Files)
|
||||||
|
<br/>
|
||||||
|
{{.DateCreated.Format "2006-01-02 15:04:05"}}
|
||||||
|
</a>
|
||||||
|
{{end}}
|
||||||
|
<br/>
|
||||||
|
</div>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
||||||
{{template "footer"}}
|
{{template "footer"}}
|
||||||
|
@@ -15,8 +15,8 @@ func (wc *WebController) serveListViewer(w http.ResponseWriter, r *http.Request,
|
|||||||
var api = pixelapi.New(wc.conf.APIURLInternal, "")
|
var api = pixelapi.New(wc.conf.APIURLInternal, "")
|
||||||
var list, err = api.GetList(p.ByName("id"))
|
var list, err = api.GetList(p.ByName("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if (err.(*pixelapi.Error)).ReqError {
|
if err, ok := err.(pixelapi.Error); ok && err.ReqError {
|
||||||
log.Error("API request error occurred: %s", (err.(pixelapi.Error)).Value)
|
log.Error("API request error occurred: %s", err.Value)
|
||||||
}
|
}
|
||||||
wc.serveNotFound(w, r)
|
wc.serveNotFound(w, r)
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user