add admin page to block files

This commit is contained in:
2020-07-20 16:43:12 +02:00
parent 618ed4e501
commit 3c07909822
3 changed files with 63 additions and 40 deletions

View File

@@ -10,7 +10,12 @@
{{template "page_top" .}}
<div class="page_content">
{{if $isAdmin}}
<h3>Bandwidth and views</h3>
<div class="limit_width">
<a class="button" href="/admin/globals">Update global settings</a>
<a class="button" href="/admin/abuse">Block files</a>
<h3>Bandwidth and views</h3>
</div>
<div class="highlight_dark">
<button onclick="loadGraph(360, 1, true);">Live</button>
<button onclick="loadGraph(1440, 10, true);">Day</button>
@@ -29,8 +34,6 @@
<span id="total_bandwidth"></span> bandwidth and <span id="total_views"></span> views
</div>
<div class="limit_width">
<br/>
<a href="/admin/globals">Update global settings</a>
<h3>Database connection statistics</h3>
<table>
<thead>

View File

@@ -96,44 +96,62 @@ func (wc *WebController) adminGlobalsForm(td *TemplateData, r *http.Request) (f
return f
}
// func (wc *WebController) adminFileDeleteForm(td *TemplateData, r *http.Request) (f Form) {
// if isAdmin, err := td.PixelAPI.UserIsAdmin(); err != nil {
// td.Title = err.Error()
// return Form{Title: td.Title}
// } else if !isAdmin.IsAdmin {
// td.Title = ";)"
// return Form{Title: td.Title}
// }
func (wc *WebController) adminAbuseForm(td *TemplateData, r *http.Request) (f Form) {
if isAdmin, err := td.PixelAPI.UserIsAdmin(); err != nil {
td.Title = err.Error()
return Form{Title: td.Title}
} else if !isAdmin {
td.Title = ";)"
return Form{Title: td.Title}
}
// td.Title = "Admin file removal"
// f = Form{
// Name: "admin_file_removal",
// Title: td.Title,
// PreFormHTML: template.HTML("<p>Paste any pixeldrain file links in here to remove them</p>"),
// Fields: []Field{
// {
// Name: "files",
// Label: "Files to delete",
// Type: FieldTypeTextarea,
// },
// },
// BackLink: "/admin",
// SubmitLabel: "Submit",
// }
td.Title = "Admin file removal"
f = Form{
Name: "admin_file_removal",
Title: td.Title,
PreFormHTML: template.HTML("<p>Paste any pixeldrain file links in here to remove them</p>"),
Fields: []Field{
{
Name: "text",
Label: "Files to delete",
Type: FieldTypeTextarea,
}, {
Name: "type",
Label: "Type",
DefaultValue: "unknown",
Description: "Can be 'unknown', 'copyright', 'terrorism' or 'child_abuse'",
Type: FieldTypeText,
}, {
Name: "reporter",
Label: "Reporter",
DefaultValue: "pixeldrain",
Type: FieldTypeText,
},
},
BackLink: "/admin",
SubmitLabel: "Submit",
}
// if f.ReadInput(r) {
// filesText := f.FieldVal("files")
if f.ReadInput(r) {
resp, err := td.PixelAPI.AdminBlockFiles(
f.FieldVal("text"),
f.FieldVal("type"),
f.FieldVal("reporter"),
)
if err != nil {
formAPIError(err, &f)
return
}
// // Get all links from the text
// strings.Index(filesText, "/u/")
successMsg := template.HTML("The following files were blocked:<br/><ul>")
for _, v := range resp.FilesBlocked {
successMsg += template.HTML("<li>pixeldrain.com/u/" + v + "</li>")
}
successMsg += "<ul>"
// if len(f.SubmitMessages) == 0 {
// // Request was a success
// f.SubmitSuccess = true
// f.SubmitMessages = []template.HTML{template.HTML(
// fmt.Sprintf("Success! %d values updated", successfulUpdates),
// )}
// }
// }
// return f
// }
// Request was a success
f.SubmitSuccess = true
f.SubmitMessages = []template.HTML{successMsg}
}
return f
}

View File

@@ -128,6 +128,8 @@ func New(
r.GET(p+"/admin" /* */, wc.serveTemplate("admin_panel", true))
r.GET(p+"/admin/globals" /* */, wc.serveForm(wc.adminGlobalsForm, true))
r.POST(p+"/admin/globals" /**/, wc.serveForm(wc.adminGlobalsForm, true))
r.GET(p+"/admin/abuse" /* */, wc.serveForm(wc.adminAbuseForm, true))
r.POST(p+"/admin/abuse" /**/, wc.serveForm(wc.adminAbuseForm, true))
// Advertising related
r.GET(p+"/click/:id" /* */, wc.serveAdClick)