Super secret view counting

This commit is contained in:
2019-02-11 22:41:22 +01:00
parent 95405e76d1
commit 32f715e65f
6 changed files with 8 additions and 9 deletions

View File

@@ -17,7 +17,7 @@ type FileInfo struct {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Size uint64 `json:"size"` Size uint64 `json:"size"`
Views int `json:"views"` Views int64 `json:"views"`
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"`
MimeType string `json:"mime_type"` MimeType string `json:"mime_type"`
@@ -26,9 +26,9 @@ 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, urlParam 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"+urlParam, resp)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -67,6 +67,6 @@ var Toolbar = {
}, 10000); }, 10000);
}, },
setViews: function(amount){ setViews: function(amount){
$("#views").html(amount); $("#views").html("Views: "+amount);
} }
}; };

View File

@@ -46,7 +46,7 @@
<div> <div>
<button class="toolbar_button button_full_width" onClick="Toolbar.toggle();">Hide Toolbar</button> <button class="toolbar_button button_full_width" onClick="Toolbar.toggle();">Hide Toolbar</button>
<!--Views: <span id="views" th:text="${data.views}">0</span>--><br/> <div id="views" style="text-align: center;">Views: No</div>
<a href="/" id="btnHome" class="button toolbar_button button_full_width"> <a href="/" id="btnHome" class="button toolbar_button button_full_width">
<img src="/res/img/pixeldrain_small.png" alt="Back to the Home page"/> <img src="/res/img/pixeldrain_small.png" alt="Back to the Home page"/>

View File

@@ -16,7 +16,6 @@
<pre> <pre>
{ {
"title": "My beautiful photos", "title": "My beautiful photos",
"description": "An album of photos from my vacation in Austria",
"files": [ // Ordered array of files to add to the list "files": [ // Ordered array of files to add to the list
{ {
"id": "abc123", "id": "abc123",
@@ -71,7 +70,7 @@
{ {
"success": false, "success": false,
"value": "description_too_long", "value": "description_too_long",
"message": "The description of this list or one of the files in the list is too long, max 3000 characters allowed." "message": "The description of one of the files in the list is too long, max 3000 characters allowed."
} }
</pre> </pre>
<pre>HTTP 422: Unprocessable Entity <pre>HTTP 422: Unprocessable Entity

View File

@@ -24,7 +24,7 @@ func (wc *WebController) serveFilePreview(w http.ResponseWriter, r *http.Request
return return
} }
var api = pixelapi.New(wc.conf.APIURLInternal, "") var api = pixelapi.New(wc.conf.APIURLInternal, "")
inf, err := api.GetFileInfo(p.ByName("id")) // TODO: Error handling inf, err := api.GetFileInfo(p.ByName("id"), "?should_a_view_be_added=yes_gimme") // TODO: Error handling
if err != nil { if err != nil {
wc.serveNotFound(w, r) wc.serveNotFound(w, r)
return return

View File

@@ -30,7 +30,7 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
var api = pixelapi.New(wc.conf.APIURLInternal, "") var api = pixelapi.New(wc.conf.APIURLInternal, "")
var finfo []*pixelapi.FileInfo var finfo []*pixelapi.FileInfo
for _, id := range ids { for _, id := range ids {
inf, err := api.GetFileInfo(id) inf, err := api.GetFileInfo(id, "")
if err != nil { if err != nil {
continue continue
} }