diff --git a/pixelapi/admin.go b/pixelapi/admin.go new file mode 100644 index 0000000..5367d52 --- /dev/null +++ b/pixelapi/admin.go @@ -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 +} diff --git a/res/static/script/Toolbar.js b/res/static/script/Toolbar.js index 33b5032..b9b6890 100644 --- a/res/static/script/Toolbar.js +++ b/res/static/script/Toolbar.js @@ -249,7 +249,28 @@ var DetailsWindow = { document.getElementById('bandwidth_chart'), { 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: { stacked: false, aspectRatio: 2.5, @@ -271,7 +292,7 @@ var DetailsWindow = { } }, { type: "linear", - display: true, + display: false, position: "right", id: "y_views", scaleLabel: { diff --git a/res/template/admin.html b/res/template/admin.html index 6ef85d7..f36e38f 100644 --- a/res/template/admin.html +++ b/res/template/admin.html @@ -7,13 +7,96 @@ - Header image -
-
+ {{$isAdmin := .PixelAPI.UserIsAdmin}} +
{{template "menu" .}} + {{if $isAdmin.IsAdmin}} -

System statistics

+

Bandwidth and views

+
+ +
+ + + + + {{end}} {{template "footer"}}
diff --git a/res/template/file_viewer.html b/res/template/file_viewer.html index 636993c..41f1dd8 100644 --- a/res/template/file_viewer.html +++ b/res/template/file_viewer.html @@ -114,6 +114,10 @@
+

Bandwidth and views

+
+ +

About

Pixeldrain is a file sharing platform. Visit the home page for more information. @@ -131,11 +135,6 @@ SHIFT + s = Download all the files in the list as a zip archive -

Bandwidth and views

-
- -
-

Credits

All server side code written by Fornax (me). diff --git a/webcontroller/web_controller.go b/webcontroller/web_controller.go index c2ee7d7..0f688f9 100644 --- a/webcontroller/web_controller.go +++ b/webcontroller/web_controller.go @@ -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.GET(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.POST(p+"/logout" /* */, wc.serveLogout) 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.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) return wc