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 }}
+ If you think this file violates pixeldrain's + content policy you can + report it for moderation with this form. You cannot report + copyright abuse with this form, send a formal DMCA notification + to the + abuse e-mail address + instead. +
+ + + - {{ 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 }} + +Time | +IP | +Type | +Status | +
{formatDate(user_report.time, true, true, true, true)} | +{user_report.ip_address} | +{user_report.type} | +{user_report.status} | +