admin time series
This commit is contained in:
16
pixelapi/admin.go
Normal file
16
pixelapi/admin.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package pixelapi
|
||||||
|
|
||||||
|
// IsAdmin is the response to the /admin/is_admin API
|
||||||
|
type IsAdmin struct {
|
||||||
|
Success bool `json:"success"`
|
||||||
|
IsAdmin bool `json:"is_admin"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIsAdmin returns if the logged in user is an admin user
|
||||||
|
func (p *PixelAPI) UserIsAdmin() (resp IsAdmin, err error) {
|
||||||
|
err = p.jsonRequest("GET", p.apiEndpoint+"/admin/is_admin", &resp)
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
@@ -249,7 +249,28 @@ var DetailsWindow = {
|
|||||||
document.getElementById('bandwidth_chart'),
|
document.getElementById('bandwidth_chart'),
|
||||||
{
|
{
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: response,
|
data: {
|
||||||
|
labels: response.labels,
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: "Downloads",
|
||||||
|
backgroundColor: "rgba(100, 255, 100, .4)",
|
||||||
|
borderColor: "rgba(100, 255, 100, .8)",
|
||||||
|
borderWidth: 2,
|
||||||
|
fill: false,
|
||||||
|
yAxisID: "y_bandwidth",
|
||||||
|
data: response.downloads
|
||||||
|
}, {
|
||||||
|
label: "Views",
|
||||||
|
backgroundColor: "rgba(128, 128, 255, .4)",
|
||||||
|
borderColor: "rgba(128, 128, 255, .8)",
|
||||||
|
borderWidth: 2,
|
||||||
|
fill: false,
|
||||||
|
yAxisID: "y_views",
|
||||||
|
data: response.views
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
options: {
|
options: {
|
||||||
stacked: false,
|
stacked: false,
|
||||||
aspectRatio: 2.5,
|
aspectRatio: 2.5,
|
||||||
@@ -271,7 +292,7 @@ var DetailsWindow = {
|
|||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
type: "linear",
|
type: "linear",
|
||||||
display: true,
|
display: false,
|
||||||
position: "right",
|
position: "right",
|
||||||
id: "y_views",
|
id: "y_views",
|
||||||
scaleLabel: {
|
scaleLabel: {
|
||||||
|
@@ -7,13 +7,96 @@
|
|||||||
<script type="text/javascript">var apiEndpoint = '{{.APIEndpoint}}';</script>
|
<script type="text/javascript">var apiEndpoint = '{{.APIEndpoint}}';</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<img id="header_image" class="header_image" src="/res/img/header_neuropol.png" alt="Header image"/>
|
{{$isAdmin := .PixelAPI.UserIsAdmin}}
|
||||||
<br/>
|
<div id="body" class="body" style="max-width: 100%">
|
||||||
<div id="body" class="body">
|
|
||||||
{{template "menu" .}}
|
{{template "menu" .}}
|
||||||
|
{{if $isAdmin.IsAdmin}}
|
||||||
|
|
||||||
<h1>System statistics</h1>
|
<h3>Bandwidth and views</h3>
|
||||||
|
<div id="chart_container" class="chart-container" style="position: relative; width: 100%; height: auto;">
|
||||||
|
<canvas id="bandwidth_chart"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="/res/script/jquery.js"></script>
|
||||||
|
<script src="/res/misc/chartjs/Chart.min.js"></script>
|
||||||
|
<script>
|
||||||
|
$.get(apiEndpoint+"/admin/files/timeseries", function(response){
|
||||||
|
console.log(response);
|
||||||
|
if (response.success) {
|
||||||
|
var ctx = document.getElementById('bandwidth_chart');
|
||||||
|
Chart.defaults.global.defaultFontColor = "#b3b3b3";
|
||||||
|
Chart.defaults.global.defaultFontSize = 16;
|
||||||
|
Chart.defaults.global.defaultFontFamily = "Ubuntu";
|
||||||
|
new Chart(
|
||||||
|
document.getElementById('bandwidth_chart'),
|
||||||
|
{
|
||||||
|
type: 'line',
|
||||||
|
data: {
|
||||||
|
labels: response.labels,
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: "Downloads",
|
||||||
|
backgroundColor: "rgba(100, 255, 100, .4)",
|
||||||
|
borderColor: "rgba(100, 255, 100, .8)",
|
||||||
|
borderWidth: 2,
|
||||||
|
fill: false,
|
||||||
|
yAxisID: "y_bandwidth",
|
||||||
|
data: response.downloads
|
||||||
|
}, {
|
||||||
|
label: "Views",
|
||||||
|
backgroundColor: "rgba(128, 128, 255, .4)",
|
||||||
|
borderColor: "rgba(128, 128, 255, .8)",
|
||||||
|
borderWidth: 2,
|
||||||
|
fill: false,
|
||||||
|
yAxisID: "y_views",
|
||||||
|
data: response.views
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
stacked: false,
|
||||||
|
aspectRatio: 3,
|
||||||
|
tooltips: {
|
||||||
|
mode: "index",
|
||||||
|
intersect: false,
|
||||||
|
axis: "x"
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
yAxes: [
|
||||||
|
{
|
||||||
|
type: "linear",
|
||||||
|
display: true,
|
||||||
|
position: "left",
|
||||||
|
id: "y_bandwidth",
|
||||||
|
scaleLabel: {
|
||||||
|
display: true,
|
||||||
|
labelString: "Downloads"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
type: "linear",
|
||||||
|
display: false,
|
||||||
|
position: "right",
|
||||||
|
id: "y_views",
|
||||||
|
scaleLabel: {
|
||||||
|
display: true,
|
||||||
|
labelString: "Views"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
elements: {
|
||||||
|
point: {
|
||||||
|
radius: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{{end}}
|
||||||
{{template "footer"}}
|
{{template "footer"}}
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
@@ -114,6 +114,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<span id="info_file_details"></span>
|
<span id="info_file_details"></span>
|
||||||
<span id="info_about">
|
<span id="info_about">
|
||||||
|
<h3>Bandwidth and views</h3>
|
||||||
|
<div id="chart_container" class="chart-container" style="position: relative; width: 100%; height: auto;">
|
||||||
|
<canvas id="bandwidth_chart"></canvas>
|
||||||
|
</div>
|
||||||
<h3>About</h3>
|
<h3>About</h3>
|
||||||
Pixeldrain is a file sharing platform.
|
Pixeldrain is a file sharing platform.
|
||||||
<a href="/" target="_blank">Visit the home page for more information.</a>
|
<a href="/" target="_blank">Visit the home page for more information.</a>
|
||||||
@@ -131,11 +135,6 @@
|
|||||||
<tr><td>SHIFT + s</td><td> = Download all the files in the list as a zip archive</td></tr>
|
<tr><td>SHIFT + s</td><td> = Download all the files in the list as a zip archive</td></tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h3>Bandwidth and views</h3>
|
|
||||||
<div id="chart_container" class="chart-container" style="position: relative; width: 100%; height: auto;">
|
|
||||||
<canvas id="bandwidth_chart"></canvas>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h3>Credits</h3>
|
<h3>Credits</h3>
|
||||||
All server side code written by
|
All server side code written by
|
||||||
<a target="_blank" href="https://fornaxian.com/">Fornax (me)</a>.
|
<a target="_blank" href="https://fornaxian.com/">Fornax (me)</a>.
|
||||||
|
@@ -77,7 +77,6 @@ func New(r *httprouter.Router, prefix string, conf *conf.PixelWebConfig) *WebCon
|
|||||||
r.POST(p+"/register" /* */, wc.serveForm(wc.registerForm, false))
|
r.POST(p+"/register" /* */, wc.serveForm(wc.registerForm, false))
|
||||||
r.GET(p+"/login" /* */, wc.serveForm(wc.loginForm, false))
|
r.GET(p+"/login" /* */, wc.serveForm(wc.loginForm, false))
|
||||||
r.POST(p+"/login" /* */, wc.serveForm(wc.loginForm, false))
|
r.POST(p+"/login" /* */, wc.serveForm(wc.loginForm, false))
|
||||||
// r.GET(p+"/login" /* */, wc.serveTemplate("login", false))
|
|
||||||
r.GET(p+"/logout" /* */, wc.serveTemplate("logout", true))
|
r.GET(p+"/logout" /* */, wc.serveTemplate("logout", true))
|
||||||
r.POST(p+"/logout" /* */, wc.serveLogout)
|
r.POST(p+"/logout" /* */, wc.serveLogout)
|
||||||
r.GET(p+"/user" /* */, wc.serveTemplate("user_home", true))
|
r.GET(p+"/user" /* */, wc.serveTemplate("user_home", true))
|
||||||
@@ -90,6 +89,8 @@ func New(r *httprouter.Router, prefix string, conf *conf.PixelWebConfig) *WebCon
|
|||||||
r.GET(p+"/user/change_password" /* */, wc.serveForm(wc.passwordForm, true))
|
r.GET(p+"/user/change_password" /* */, wc.serveForm(wc.passwordForm, true))
|
||||||
r.POST(p+"/user/change_password" /**/, wc.serveForm(wc.passwordForm, true))
|
r.POST(p+"/user/change_password" /**/, wc.serveForm(wc.passwordForm, true))
|
||||||
|
|
||||||
|
r.GET(p+"/admin", wc.serveTemplate("admin_panel", true))
|
||||||
|
|
||||||
r.NotFound = http.HandlerFunc(wc.serveNotFound)
|
r.NotFound = http.HandlerFunc(wc.serveNotFound)
|
||||||
|
|
||||||
return wc
|
return wc
|
||||||
|
Reference in New Issue
Block a user