Add bandwidth counter to file viewer
This commit is contained in:
@@ -18,6 +18,7 @@ type FileInfo struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Size uint64 `json:"size"`
|
Size uint64 `json:"size"`
|
||||||
Views int64 `json:"views"`
|
Views int64 `json:"views"`
|
||||||
|
BandwidthUsed uint64 `json:"bandwidth_used"`
|
||||||
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"`
|
||||||
|
@@ -19,13 +19,14 @@ type List struct {
|
|||||||
|
|
||||||
// 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"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
DateCreated time.Time `json:"date_created"`
|
DateCreated time.Time `json:"date_created"`
|
||||||
DateLastView time.Time `json:"date_last_view"`
|
DateLastView time.Time `json:"date_last_view"`
|
||||||
Views int64 `json:"views"`
|
Views int64 `json:"views"`
|
||||||
|
BandwidthUsed uint64 `json:"bandwidth_used"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
@@ -209,12 +209,6 @@ var ListNavigator = {
|
|||||||
document.getElementById("button-expand-toolbar").style.top = navHeight+"px";
|
document.getElementById("button-expand-toolbar").style.top = navHeight+"px";
|
||||||
document.getElementById("sharebar").style.top = navHeight+"px";
|
document.getElementById("sharebar").style.top = navHeight+"px";
|
||||||
document.getElementById("info_popup").style.top = (navHeight+20)+"px";
|
document.getElementById("info_popup").style.top = (navHeight+20)+"px";
|
||||||
// $("#listNavigator").animate( {top: 0}, {"duration": 1500, "queue": false});
|
|
||||||
// $("#filepreview").animate( {top: navHeight},{"duration": 1500, "queue": false});
|
|
||||||
// $("#toolbar").animate( {top: navHeight},{"duration": 1500, "queue": false});
|
|
||||||
// $("#button-expand-toolbar").animate({top: navHeight},{"duration": 1500, "queue": false});
|
|
||||||
// $("#sharebar").animate( {top: navHeight},{"duration": 1500, "queue": false});
|
|
||||||
// $("#info_popup").css("top", "120px");
|
|
||||||
}, 200);
|
}, 200);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -55,8 +55,9 @@ var Toolbar = {
|
|||||||
document.getElementById("btnCopy").classList.remove("button_highlight")
|
document.getElementById("btnCopy").classList.remove("button_highlight")
|
||||||
}, 60000);
|
}, 60000);
|
||||||
},
|
},
|
||||||
setViews: function(amount){
|
setStats: function(views, downloads){
|
||||||
document.getElementById("views").innerText = "Views: "+amount;
|
document.getElementById("stat_views").innerText = views
|
||||||
|
document.getElementById("stat_downloads").innerText = Math.round(downloads*10)/10;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -127,12 +128,14 @@ var DetailsWindow = {
|
|||||||
+ "<tr><td>Name<td><td>" + escapeHTML(data.name) + "</td></tr>"
|
+ "<tr><td>Name<td><td>" + escapeHTML(data.name) + "</td></tr>"
|
||||||
+ "<tr><td>Url<td><td><a href=\"/u/" + data.id + "\">/u/" + data.id + "</a></td></tr>"
|
+ "<tr><td>Url<td><td><a href=\"/u/" + data.id + "\">/u/" + data.id + "</a></td></tr>"
|
||||||
+ "<tr><td>Mime Type<td><td>" + escapeHTML(data.mime_type) + "</td></tr>"
|
+ "<tr><td>Mime Type<td><td>" + escapeHTML(data.mime_type) + "</td></tr>"
|
||||||
+ "<tr><td>IS<td><td>" + data.id + "</td></tr>"
|
+ "<tr><td>ID<td><td>" + data.id + "</td></tr>"
|
||||||
+ "<tr><td>Size<td><td class=\"bytecounter\">" + data.size + "</td></tr>"
|
+ "<tr><td>Size<td><td class=\"bytecounter\">" + data.size + "</td></tr>"
|
||||||
|
+ "<tr><td>Bandwidth<td><td class=\"bytecounter\">" + data.bandwidth_used + "</td></tr>"
|
||||||
+ "<tr><td>Upload Date<td><td>" + data.date_upload + "</td></tr>"
|
+ "<tr><td>Upload Date<td><td>" + data.date_upload + "</td></tr>"
|
||||||
+ "<tr><td>Description<td><td>" + escapeHTML(file.description) + "</td></tr>"
|
+ "<tr><td>Description<td><td>" + escapeHTML(file.description) + "</td></tr>"
|
||||||
+ "</table>"
|
+ "</table>"
|
||||||
);
|
);
|
||||||
|
Toolbar.setStats(data.views, data.bandwidth_used/data.size);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -142,9 +145,11 @@ var DetailsWindow = {
|
|||||||
+ "<tr><td>Mime Type<td><td>" + escapeHTML(file.mime_type) + "</td></tr>"
|
+ "<tr><td>Mime Type<td><td>" + escapeHTML(file.mime_type) + "</td></tr>"
|
||||||
+ "<tr><td>ID<td><td>" + file.id + "</td></tr>"
|
+ "<tr><td>ID<td><td>" + file.id + "</td></tr>"
|
||||||
+ "<tr><td>Size<td><td class=\"bytecounter\">" + file.size + "</td></tr>"
|
+ "<tr><td>Size<td><td class=\"bytecounter\">" + file.size + "</td></tr>"
|
||||||
|
+ "<tr><td>Bandwidth<td><td class=\"bytecounter\">" + file.bandwidth_used + "</td></tr>"
|
||||||
+ "<tr><td>Upload Date<td><td>" + file.date_upload + "</td></tr>"
|
+ "<tr><td>Upload Date<td><td>" + file.date_upload + "</td></tr>"
|
||||||
+ "</table>"
|
+ "</table>"
|
||||||
);
|
);
|
||||||
|
Toolbar.setStats(file.views, file.bandwidth_used/file.size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -40,7 +40,6 @@ var Viewer = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
DetailsWindow.setDetails(file);
|
DetailsWindow.setDetails(file);
|
||||||
Toolbar.setViews(file.views);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -148,6 +148,13 @@ body{
|
|||||||
vertical-align: 6px;
|
vertical-align: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.toolbar_label {
|
||||||
|
text-align: left;
|
||||||
|
padding-left: 10px;
|
||||||
|
font-size: 0.8em;
|
||||||
|
line-height: 0.7em;
|
||||||
|
}
|
||||||
|
|
||||||
#sponsors{
|
#sponsors{
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 600px;
|
height: 600px;
|
||||||
|
@@ -45,7 +45,10 @@
|
|||||||
<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>
|
||||||
|
|
||||||
<div id="views" style="text-align: center;">Views: No</div>
|
<div id="stat_views_label" class="toolbar_label">Views</div>
|
||||||
|
<div id="stat_views" style="text-align: center;">N/A</div>
|
||||||
|
<div id="stat_downloads_label" class="toolbar_label">Downloads</div>
|
||||||
|
<div id="stat_downloads" style="text-align: center;">N/A</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"/>
|
||||||
|
@@ -158,6 +158,7 @@
|
|||||||
"date_last_view": 1485894987, // Timestamp
|
"date_last_view": 1485894987, // Timestamp
|
||||||
"size": 5694837, // Bytes
|
"size": 5694837, // Bytes
|
||||||
"views" 1234, // Amount of unique file views
|
"views" 1234, // Amount of unique file views
|
||||||
|
"bandwidth_used": 1234567890, // Bytes
|
||||||
"mime_type" "image/png",
|
"mime_type" "image/png",
|
||||||
"description": "File description",
|
"description": "File description",
|
||||||
"mime_image": "http://pixeldra.in/res/img/mime/image-png.png", // Image associated with the mime type
|
"mime_image": "http://pixeldra.in/res/img/mime/image-png.png", // Image associated with the mime type
|
||||||
|
@@ -130,7 +130,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"date_created": 1513033304,
|
"date_created": 1513033304,
|
||||||
"date_last_view": 1513033304,
|
"date_last_view": 1513033304,
|
||||||
"views": 1
|
"views": 1,
|
||||||
|
"bandwidth_used": 1234567890
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"detail_href": "/file/RKwgZb/info",
|
"detail_href": "/file/RKwgZb/info",
|
||||||
@@ -139,7 +140,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"date_created": 1513033304,
|
"date_created": 1513033304,
|
||||||
"date_last_view": 1513033304,
|
"date_last_view": 1513033304,
|
||||||
"views": 2
|
"views": 2,
|
||||||
|
"bandwidth_used": 1234567890
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"detail_href": "/file/DRaL_e/info",
|
"detail_href": "/file/DRaL_e/info",
|
||||||
@@ -148,7 +150,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"date_created": 1513033304,
|
"date_created": 1513033304,
|
||||||
"date_last_view": 1513033304,
|
"date_last_view": 1513033304,
|
||||||
"views": 3
|
"views": 3,
|
||||||
|
"bandwidth_used": 1234567890
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -82,16 +82,17 @@ func (wc *WebController) serveFileViewerDemo(w http.ResponseWriter, r *http.Requ
|
|||||||
templateData.Other = viewerData{
|
templateData.Other = viewerData{
|
||||||
Type: "file",
|
Type: "file",
|
||||||
APIResponse: map[string]interface{}{
|
APIResponse: map[string]interface{}{
|
||||||
"id": "demo",
|
"id": "demo",
|
||||||
"name": "Demo file",
|
"name": "Demo file",
|
||||||
"date_upload": "2017-01-01 12:34:56",
|
"date_upload": "2017-01-01 12:34:56",
|
||||||
"date_lastview": "2017-01-01 12:34:56",
|
"date_lastview": "2017-01-01 12:34:56",
|
||||||
"size": 123456789,
|
"size": 123456789,
|
||||||
"views": 1,
|
"views": 1,
|
||||||
"mime_type": "text/demo",
|
"bandwidth_used": 123456789,
|
||||||
"description": "A file to demonstrate the viewer page",
|
"mime_type": "text/demo",
|
||||||
"mime_image": "/res/img/mime/text.png",
|
"description": "A file to demonstrate the viewer page",
|
||||||
"thumbnail": "/res/img/mime/text.png",
|
"mime_image": "/res/img/mime/text.png",
|
||||||
|
"thumbnail": "/res/img/mime/text.png",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err := wc.templates.Get().ExecuteTemplate(w, "file_viewer", templateData)
|
err := wc.templates.Get().ExecuteTemplate(w, "file_viewer", templateData)
|
||||||
|
Reference in New Issue
Block a user