diff --git a/res/include/script/file_viewer/AbuseReportWindow.js b/res/include/script/file_viewer/AbuseReportWindow.js new file mode 100644 index 0000000..ae57748 --- /dev/null +++ b/res/include/script/file_viewer/AbuseReportWindow.js @@ -0,0 +1,80 @@ +function AbuseReportWindow(viewer) { + this.viewer = viewer + this.visible = false + this.modal = new Modal( + document.getElementById("file_viewer"), + () => { this.toggle() }, + "Report abuse", "600px", "auto", + ) + + this.btnReportAbuse = document.getElementById("btn_report_abuse") + this.btnReportAbuse.addEventListener("click", () => { this.toggle() }) + + let clone = document.getElementById("tpl_report_abuse_popup").content.cloneNode(true) + this.form = clone.querySelector(".abuse_type_form") + // this.emailField = clone.querySelector(".abuse_email_field") + this.notification = clone.querySelector(".abuse_report_notification") + this.modal.setBody(clone) + + this.form.addEventListener("submit", e => { this.submit(e) }) +} + +AbuseReportWindow.prototype.toggle = function () { + if (this.visible) { + this.modal.close() + this.btnReportAbuse.classList.remove("button_highlight") + this.visible = false + } else { + this.modal.open() + this.btnReportAbuse.classList.add("button_highlight") + this.visible = true + } +} + +AbuseReportWindow.prototype.notify = function (success, content) { + this.notification.style.display = "" + this.notification.classList = "abuse_report_notification " + (success ? "highlight_green" : "highlight_red") + this.notification.innerHTML = content +} + +AbuseReportWindow.prototype.submit = async function (e) { + e.preventDefault() + + let abuseType = "" + this.form.querySelectorAll('[name="abuse_type"]').forEach(elem => { + if (elem.checked) { + abuseType = elem.value + } + }) + + if (abuseType === "") { + this.notify(false, "Please select an abuse type") + return + } + + const form = new FormData() + form.append("type", abuseType) + // form.append("email", this.emailField.value) + + try { + const resp = await fetch( + this.viewer.file.get_href + "/report_abuse", + { method: "POST", body: form } + ); + if (resp.status >= 400) { + let json = await resp.json() + if (json.value === "resource_already_exists") { + throw "You have already reported this file" + } else if (json.value === "file_already_blocked") { + throw "This file has already been blocked" + } else if (json.value === "multiple_errors") { + throw json.errors[0].message + } + throw json.message + } + + this.notify(true, "Report has been sent") + } catch (err) { + this.notify(false, "Failed to send report: " + err) + } +} diff --git a/res/include/script/file_viewer/Viewer.js b/res/include/script/file_viewer/Viewer.js index 39e810e..a62257e 100644 --- a/res/include/script/file_viewer/Viewer.js +++ b/res/include/script/file_viewer/Viewer.js @@ -77,6 +77,7 @@ function Viewer(type, viewToken, data) { } this.embedWindow = new EmbedWindow(this) + this.abuseReportWindow = new AbuseReportWindow(this) if (userAuthenticated && !this.file.can_edit) { let btnGrab = document.getElementById("btn_grab") diff --git a/res/template/admin.html b/res/template/admin.html index 49e9a12..df426b8 100644 --- a/res/template/admin.html +++ b/res/template/admin.html @@ -17,6 +17,10 @@ block Block files + + report + User abuse reports + report Manage abuse reporters diff --git a/res/template/admin_abuse_reports.html b/res/template/admin_abuse_reports.html new file mode 100644 index 0000000..11611e9 --- /dev/null +++ b/res/template/admin_abuse_reports.html @@ -0,0 +1,19 @@ +{{define "admin_abuse_reports"}} + + + {{template "meta_tags" "Abuse reports"}} + {{template "user_style" .}} + + + + + + {{template "page_top" .}} +

Abuse reports

+
+ + {{template "page_bottom" .}} + {{template "analytics"}} + + +{{end}} diff --git a/res/template/file_viewer.html b/res/template/file_viewer.html index d45fd61..c978421 100644 --- a/res/template/file_viewer.html +++ b/res/template/file_viewer.html @@ -90,6 +90,10 @@ code Embed +
{{ if and .Other.FileAdsEnabled .Other.UserAdsEnabled }} @@ -175,6 +179,10 @@
+ {{ else if eq .Other.AdType 7 }} + + + {{ else if eq .Other.AdType 8 }}
@@ -207,10 +215,6 @@ Pixeldrain Pro: Only €2 per month
- {{ else }} - - - {{ end }} {{ else if not .Other.UserAdsEnabled }}
@@ -309,6 +313,56 @@
+ + - {{ else if or (eq .Other.AdType 7) (eq .Other.AdType 8) (eq .Other.AdType 9) (eq .Other.AdType 10) (eq .Other.AdType 11) }} + {{ else if ne .Other.AdType 4 }} + + +
+
+ File thumbnail +
+ +
{report.file.name}
+
Type
{report.type}
+ {#if report.status !== "pending"} +
Status
{report.status}
+ {/if} +
R
{report.reports.length}
+
V
{report.file.views}
+
DL
{Math.round(report.file.bandwidth_used / report.file.size)}
+
+
+
+ + open_in_new Open file + + + +
+ + + + + + + + {#each report.reports as user_report} + + + + + + + {/each} +
TimeIPTypeStatus
{formatDate(user_report.time, true, true, true, true)}{user_report.ip_address}{user_report.type}{user_report.status}
+
+
+ + diff --git a/svelte/src/admin_abuse_reports/AbuseReports.svelte b/svelte/src/admin_abuse_reports/AbuseReports.svelte new file mode 100644 index 0000000..d5d5c3d --- /dev/null +++ b/svelte/src/admin_abuse_reports/AbuseReports.svelte @@ -0,0 +1,108 @@ + + +
+ {#if loading} +
+ +
+ {/if} + +
+ + +
+ +

Pending

+ {#each reports as report} + {#if report.status === "pending"} + + {/if} + {/each} + +

Resolved

+ {#each reports as report} + {#if report.status !== "pending"} + + {/if} + {/each} +
+
+ + diff --git a/svelte/src/util/Expandable.svelte b/svelte/src/util/Expandable.svelte new file mode 100644 index 0000000..7a5b239 --- /dev/null +++ b/svelte/src/util/Expandable.svelte @@ -0,0 +1,63 @@ + + + + + diff --git a/webcontroller/web_controller.go b/webcontroller/web_controller.go index 7bfaf36..c64c556 100644 --- a/webcontroller/web_controller.go +++ b/webcontroller/web_controller.go @@ -187,6 +187,7 @@ func New( {GET, "admin/abuse" /* */, wc.serveForm(wc.adminAbuseForm, handlerOpts{Auth: true})}, {PST, "admin/abuse" /* */, wc.serveForm(wc.adminAbuseForm, handlerOpts{Auth: true})}, {GET, "admin/abuse_reporters" /**/, wc.serveTemplate("admin_abuse_reporters", handlerOpts{Auth: true})}, + {GET, "admin/abuse_reports" /* */, wc.serveTemplate("admin_abuse_reports", handlerOpts{Auth: true})}, // Advertising related {GET, "click/:id" /* */, wc.serveAdClick},