abuse reports in the browser: notice, visitor tips, operator form and queue
A listing page says when the node hides the listing and who flagged it. A visitor can tip off the operator (proof-of-work, nothing is hidden by it); the signed-in operator can sign or withdraw a report from the page and works through the tips at #/mine/reports. e2e covers the real binaries. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
Vendored
+289
-3
@@ -82,6 +82,28 @@ async function postMessage(envelope) {
|
||||
}
|
||||
throw new HttpError(res.status, detail, requiredBits);
|
||||
}
|
||||
async function getReportSummary(author, id) {
|
||||
try {
|
||||
const res = await fetch(`/api/v1/reports?author=${author}&id=${id}`);
|
||||
if (!res.ok) return null;
|
||||
const s = await res.json();
|
||||
if (typeof s.hidden !== "boolean" || typeof s.trusted !== "object" || s.trusted === null) return null;
|
||||
return { hidden: s.hidden, trusted: s.trusted, others: Number(s.others) || 0, signals: Number(s.signals) || 0, own: s.own };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
async function postSignal(body) {
|
||||
const res = await fetch("/api/v1/signals", { method: "POST", headers: { "Content-Type": "application/json" }, body });
|
||||
if (res.ok) return;
|
||||
let detail = res.statusText;
|
||||
try {
|
||||
const b = await res.json();
|
||||
if (typeof b.error === "string") detail = b.error;
|
||||
} catch {
|
||||
}
|
||||
throw new HttpError(res.status, detail);
|
||||
}
|
||||
async function pollMailbox(tag, since) {
|
||||
const data = await getJSON(`/api/v1/messages?mailbox=${encodeURIComponent(tag)}&since=${since}`);
|
||||
if (!Array.isArray(data)) throw new Error("unexpected response");
|
||||
@@ -189,6 +211,36 @@ var de = {
|
||||
"send.404": "Dieser Knoten kennt die Anzeige nicht (mehr), oder der Anbieter hat sein Ger\xE4t gewechselt. Lade die Anzeige neu.",
|
||||
"send.429": "Zu viele Nachrichten. Bitte warte einen Moment.",
|
||||
"send.busy": "Diese Anzeige bekommt gerade sehr viele Nachrichten. Versuche es sp\xE4ter noch einmal.",
|
||||
"rep.hiddenNotice": "Diese Anzeige wird auf diesem Knoten nicht in der Suche gezeigt, weil sie gemeldet wurde. Du siehst sie, weil du den Link kennst.",
|
||||
"rep.counts": "Gemeldet von vertrauensw\xFCrdigen Betreibern: {list}.",
|
||||
"rep.others": "Dazu kommen {n} Meldungen von Betreibern, denen dieser Knoten nicht vertraut. Sie z\xE4hlen nicht.",
|
||||
"rep.cat.scam": "Betrug",
|
||||
"rep.cat.illegal": "rechtswidrige Inhalte",
|
||||
"rep.cat.category": "falsche Kategorie",
|
||||
"rep.cat.other": "Sonstiges",
|
||||
"rep.report": "Anzeige melden",
|
||||
"rep.intro": "Deine Meldung geht an den Betreiber dieses Knotens. Sie blendet nichts aus: er entscheidet.",
|
||||
"rep.reason": "Grund",
|
||||
"rep.note": "Anmerkung (optional)",
|
||||
"rep.send": "Melden",
|
||||
"rep.working": "Wird vorbereitet \u2026",
|
||||
"rep.thanks": "Danke. Der Betreiber dieses Knotens wurde informiert.",
|
||||
"rep.fail": "Die Meldung konnte nicht gesendet werden: {detail}",
|
||||
"rep.operator": "Als Betreiber melden",
|
||||
"rep.operatorIntro": "Deine Meldung wird signiert und im Netz verbreitet. Auf deinem Knoten blendet sie die Anzeige sofort aus.",
|
||||
"rep.operatorSend": "Signiert melden",
|
||||
"rep.withdraw": "Meine Meldung zur\xFCckziehen",
|
||||
"rep.done": "Gemeldet.",
|
||||
"rep.withdrawn": "Zur\xFCckgezogen.",
|
||||
"rep.mine": "Deine Meldung: {what}.",
|
||||
"rep.title": "Meldungen",
|
||||
"rep.tipsIntro": "Hinweise von Besuchern dieses Knotens. Sie blenden nichts aus: du entscheidest, ob du selbst meldest.",
|
||||
"rep.none": "Keine Hinweise von Besuchern.",
|
||||
"rep.work": "Aufwand {n} Bit",
|
||||
"rep.sign": "Als \u201E{what}\u201C melden",
|
||||
"rep.dismiss": "Verwerfen",
|
||||
"rep.open": "Anzeige ansehen",
|
||||
"rep.back": "\u2190 Meine Anzeigen",
|
||||
"send.other": "Senden fehlgeschlagen: {detail}",
|
||||
"send.network": "Der Knoten ist nicht erreichbar.",
|
||||
"chat.back": "\u2190 Zur Anzeige",
|
||||
@@ -447,6 +499,36 @@ var en = {
|
||||
"send.404": "This node does not know the listing (anymore), or the owner changed device. Reload the listing.",
|
||||
"send.429": "Too many messages. Please wait a moment.",
|
||||
"send.busy": "This listing is receiving a lot of messages right now. Please try again later.",
|
||||
"rep.hiddenNotice": "This listing is hidden from search on this node because it was reported. You can see it because you have its link.",
|
||||
"rep.counts": "Reported by trusted operators: {list}.",
|
||||
"rep.others": "{n} more reports came from operators this node does not trust. They do not count.",
|
||||
"rep.cat.scam": "scam",
|
||||
"rep.cat.illegal": "illegal content",
|
||||
"rep.cat.category": "wrong category",
|
||||
"rep.cat.other": "other",
|
||||
"rep.report": "Report this listing",
|
||||
"rep.intro": "Your report goes to the operator of this node. It hides nothing by itself: they decide.",
|
||||
"rep.reason": "Reason",
|
||||
"rep.note": "Note (optional)",
|
||||
"rep.send": "Send report",
|
||||
"rep.working": "Preparing \u2026",
|
||||
"rep.thanks": "Thank you. The operator of this node has been told.",
|
||||
"rep.fail": "The report could not be sent: {detail}",
|
||||
"rep.operator": "Report as operator",
|
||||
"rep.operatorIntro": "Your report is signed and shared with the network. On your node it hides the listing at once.",
|
||||
"rep.operatorSend": "Sign and report",
|
||||
"rep.withdraw": "Withdraw my report",
|
||||
"rep.done": "Reported.",
|
||||
"rep.withdrawn": "Withdrawn.",
|
||||
"rep.mine": "Your report: {what}.",
|
||||
"rep.title": "Reports",
|
||||
"rep.tipsIntro": "Tips from visitors of this node. They hide nothing: you decide whether to report yourself.",
|
||||
"rep.none": "No tips from visitors.",
|
||||
"rep.work": "Effort {n} bits",
|
||||
"rep.sign": "Report as \u201C{what}\u201D",
|
||||
"rep.dismiss": "Dismiss",
|
||||
"rep.open": "View listing",
|
||||
"rep.back": "\u2190 My listings",
|
||||
"send.other": "Sending failed: {detail}",
|
||||
"send.network": "The node is not reachable.",
|
||||
"chat.back": "\u2190 Back to the listing",
|
||||
@@ -4913,6 +4995,15 @@ async function unblockThread(listing, thread) {
|
||||
async function getBlocked() {
|
||||
return await call("GET", "/api/v1/blocked");
|
||||
}
|
||||
async function getTips() {
|
||||
return await call("GET", "/api/v1/signals");
|
||||
}
|
||||
async function dismissTips(author, listing) {
|
||||
await call("DELETE", `/api/v1/signals/${e(author)}/${e(listing)}`);
|
||||
}
|
||||
async function signReport(author, listing, category, note) {
|
||||
await call("POST", "/api/v1/reports", { listing: { author, id: listing }, category, note });
|
||||
}
|
||||
async function getAddress(listing) {
|
||||
try {
|
||||
return await call("GET", `/api/v1/listings/${e(listing)}/address`);
|
||||
@@ -5010,6 +5101,7 @@ async function showOwner(listingId, thread) {
|
||||
h("p", null, h("a", { class: "btn primary", href: "#/mine/new" }, t("own.new"))),
|
||||
listingsBox,
|
||||
h("p", null, h("a", { class: "btn", href: "#/mine/regions" }, t("reg.title"))),
|
||||
h("p", null, h("a", { class: "btn", href: "#/mine/reports" }, t("rep.title"))),
|
||||
h("p", null, h("button", { type: "button", class: "btn", onclick: logout }, t("own.logout")))
|
||||
);
|
||||
const reqTitle = h("h2", { class: "pane-title" });
|
||||
@@ -5531,6 +5623,198 @@ function openSheet(listingId, thread, opener, done) {
|
||||
);
|
||||
}
|
||||
|
||||
// src/reports.ts
|
||||
var REASONS = ["scam", "illegal", "category", "other"];
|
||||
var MAX_NOTE_BYTES = 300;
|
||||
var reasonLabel = (c) => REASONS.includes(c) ? t(`rep.cat.${c}`) : c;
|
||||
var utf82 = (s) => new TextEncoder().encode(s).length;
|
||||
async function sendTip(author, id, category, note) {
|
||||
const bits = state.node?.message_difficulty ?? DEFAULT_MESSAGE_DIFFICULTY;
|
||||
const body = { category, created_at: nowSeconds(), listing: { author, id }, note, pow: 0, v: 1 };
|
||||
await mine(body, bits);
|
||||
await postSignal(canonicalize(body));
|
||||
}
|
||||
function describe2(e2) {
|
||||
if (e2 instanceof Unauthorized) return t("reg.signedOut");
|
||||
if (e2 instanceof HttpError) return e2.detail;
|
||||
return t("send.network");
|
||||
}
|
||||
function reasonFields() {
|
||||
const select2 = h("select", { name: "category" }, ...REASONS.map((c) => h("option", { value: c }, reasonLabel(c))));
|
||||
const note = h("textarea", { name: "note", rows: 3, maxlength: MAX_NOTE_BYTES, "aria-label": t("rep.note"), placeholder: t("rep.note") });
|
||||
return {
|
||||
nodes: [h("label", null, t("rep.reason"), " ", select2), note],
|
||||
read: () => ({ category: select2.value, note: note.value.trim() })
|
||||
};
|
||||
}
|
||||
function summaryLines(sum) {
|
||||
const out = [];
|
||||
if (sum.hidden) out.push(h("p", { class: "note warn", role: "status" }, t("rep.hiddenNotice")));
|
||||
const counted = Object.entries(sum.trusted).filter(([, n]) => n > 0);
|
||||
if (counted.length) {
|
||||
out.push(h("p", { class: "muted" }, t("rep.counts", { list: counted.map(([c, n]) => `${reasonLabel(c)} (${n})`).join(", ") })));
|
||||
}
|
||||
if (sum.others > 0) out.push(h("p", { class: "muted small" }, t("rep.others", { n: sum.others })));
|
||||
if (sum.own) out.push(h("p", { class: "muted" }, t("rep.mine", { what: reasonLabel(sum.own) })));
|
||||
return out;
|
||||
}
|
||||
function reportPanel(l) {
|
||||
const lines = h("div", null);
|
||||
const root = h("section", { class: "panel report" }, lines, visitorForm(l));
|
||||
const refresh = () => void getReportSummary(l.author, l.id).then((sum) => {
|
||||
if (!sum) return;
|
||||
clear(lines);
|
||||
append(lines, summaryLines(sum));
|
||||
});
|
||||
if (getToken()) root.append(operatorForm(l, refresh));
|
||||
refresh();
|
||||
return root;
|
||||
}
|
||||
function visitorForm(l) {
|
||||
const fields = reasonFields();
|
||||
const status = h("p", { class: "muted", role: "status" });
|
||||
const problem = h("p", { class: "error", role: "alert" });
|
||||
const button = h("button", { type: "submit", class: "btn" }, t("rep.send"));
|
||||
const form = h(
|
||||
"form",
|
||||
{
|
||||
class: "compose",
|
||||
onsubmit: (ev) => {
|
||||
ev.preventDefault();
|
||||
const { category, note } = fields.read();
|
||||
problem.textContent = "";
|
||||
if (utf82(note) > MAX_NOTE_BYTES) {
|
||||
problem.textContent = t("rep.fail", { detail: t("rep.note") });
|
||||
return;
|
||||
}
|
||||
button.disabled = true;
|
||||
status.textContent = t("rep.working");
|
||||
void sendTip(l.author, l.id, category, note).then(() => {
|
||||
clear(form);
|
||||
form.append(h("p", { role: "status" }, t("rep.thanks")));
|
||||
}).catch((e2) => {
|
||||
button.disabled = false;
|
||||
status.textContent = "";
|
||||
problem.textContent = t("rep.fail", { detail: describe2(e2) });
|
||||
});
|
||||
}
|
||||
},
|
||||
h("p", { class: "muted" }, t("rep.intro")),
|
||||
...fields.nodes,
|
||||
h("div", { class: "actions" }, button),
|
||||
status,
|
||||
problem
|
||||
);
|
||||
return h("details", { class: "report-form" }, h("summary", null, t("rep.report")), form);
|
||||
}
|
||||
function operatorForm(l, changed) {
|
||||
const fields = reasonFields();
|
||||
const status = h("p", { class: "muted", role: "status" });
|
||||
const problem = h("p", { class: "error", role: "alert" });
|
||||
const act = (category, note, done) => {
|
||||
problem.textContent = "";
|
||||
void signReport(l.author, l.id, category, note).then(() => {
|
||||
status.textContent = t(done);
|
||||
changed();
|
||||
}).catch((e2) => {
|
||||
problem.textContent = t("rep.fail", { detail: describe2(e2) });
|
||||
});
|
||||
};
|
||||
return h(
|
||||
"details",
|
||||
{ class: "report-form" },
|
||||
h("summary", null, t("rep.operator")),
|
||||
h(
|
||||
"form",
|
||||
{
|
||||
class: "compose",
|
||||
onsubmit: (ev) => {
|
||||
ev.preventDefault();
|
||||
const { category, note } = fields.read();
|
||||
act(category, note, "rep.done");
|
||||
}
|
||||
},
|
||||
h("p", { class: "muted" }, t("rep.operatorIntro")),
|
||||
...fields.nodes,
|
||||
h(
|
||||
"div",
|
||||
{ class: "actions" },
|
||||
h("button", { type: "submit", class: "btn primary" }, t("rep.operatorSend")),
|
||||
h("button", { type: "button", class: "btn", onclick: () => act("withdrawn", "", "rep.withdrawn") }, t("rep.withdraw"))
|
||||
),
|
||||
status,
|
||||
problem
|
||||
)
|
||||
);
|
||||
}
|
||||
async function showReports() {
|
||||
const root = document.getElementById("app");
|
||||
clear(root);
|
||||
if (!getToken()) {
|
||||
renderLogin(false);
|
||||
return;
|
||||
}
|
||||
const list = h("div", null);
|
||||
const problem = h("p", { class: "error", role: "alert" });
|
||||
append(root, [
|
||||
h("a", { class: "back", href: "#/mine" }, t("rep.back")),
|
||||
h("h1", null, t("rep.title")),
|
||||
h("p", { class: "muted" }, t("rep.tipsIntro")),
|
||||
problem,
|
||||
list
|
||||
]);
|
||||
const load2 = async () => {
|
||||
let tips;
|
||||
try {
|
||||
tips = await getTips();
|
||||
} catch (e2) {
|
||||
if (e2 instanceof Unauthorized) return renderLogin(true);
|
||||
problem.textContent = describe2(e2);
|
||||
return;
|
||||
}
|
||||
clear(list);
|
||||
if (tips.length === 0) {
|
||||
list.append(h("p", { class: "muted" }, t("rep.none")));
|
||||
return;
|
||||
}
|
||||
const byListing = /* @__PURE__ */ new Map();
|
||||
for (const tip of tips) byListing.set(`${tip.author}/${tip.listing}`, [...byListing.get(`${tip.author}/${tip.listing}`) ?? [], tip]);
|
||||
for (const group of byListing.values()) list.append(card(group, load2, problem));
|
||||
};
|
||||
await load2();
|
||||
}
|
||||
function card(group, reload, problem) {
|
||||
const first = group[0];
|
||||
const fail2 = (e2) => {
|
||||
problem.textContent = describe2(e2);
|
||||
};
|
||||
const categories = [...new Set(group.map((g) => g.category))];
|
||||
return h(
|
||||
"section",
|
||||
{ class: "panel" },
|
||||
h("h2", null, h("a", { href: `#/l/${first.author}/${first.listing}` }, first.title || t("rep.open"))),
|
||||
h(
|
||||
"ul",
|
||||
null,
|
||||
...group.map(
|
||||
(g) => h("li", null, `${reasonLabel(g.category)}: ${g.note || "\u2013"} `, h("span", { class: "muted small" }, `(${t("rep.work", { n: g.work })})`))
|
||||
)
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "actions" },
|
||||
...categories.map(
|
||||
(c) => h(
|
||||
"button",
|
||||
{ type: "button", class: "btn", onclick: () => void signReport(first.author, first.listing, c, group.find((g) => g.category === c)?.note ?? "").then(reload).catch(fail2) },
|
||||
t("rep.sign", { what: reasonLabel(c) })
|
||||
)
|
||||
),
|
||||
h("button", { type: "button", class: "btn", onclick: () => void dismissTips(first.author, first.listing).then(reload).catch(fail2) }, t("rep.dismiss"))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// src/parse.ts
|
||||
function parseEuros(input) {
|
||||
const s = input.replace(/[€\s ]|eur/gi, "");
|
||||
@@ -6233,7 +6517,7 @@ function navigate(hash) {
|
||||
if (location.hash === hash || hash === "#/" && location.hash === "") route();
|
||||
else location.hash = hash;
|
||||
}
|
||||
function card(l) {
|
||||
function card2(l) {
|
||||
const facts = [
|
||||
label("cat", l.category),
|
||||
l.area_m2 ? t("card.area", { n: l.area_m2 }) : "",
|
||||
@@ -6276,7 +6560,7 @@ async function loadResults(gen, q, root) {
|
||||
for (const raw of items) {
|
||||
const verdict = verifyListing(raw, opts);
|
||||
if (verdict.ok) {
|
||||
cards.append(card(raw));
|
||||
cards.append(card2(raw));
|
||||
shown++;
|
||||
} else {
|
||||
hidden++;
|
||||
@@ -6388,7 +6672,8 @@ function listingBody(l) {
|
||||
),
|
||||
l.description ? h("section", { class: "panel" }, h("p", { class: "desc" }, l.description)) : h("span"),
|
||||
l.features?.length ? h("section", { class: "panel" }, h("h2", null, t("detail.features")), h("ul", { class: "chips" }, ...l.features.map((f) => h("li", null, f)))) : h("span"),
|
||||
contactPanel(l)
|
||||
contactPanel(l),
|
||||
reportPanel(l)
|
||||
];
|
||||
}
|
||||
async function showDetail(author, id) {
|
||||
@@ -6455,6 +6740,7 @@ function route() {
|
||||
else if (c) void showConversation(c[1], c[2], c[3]);
|
||||
else if (path === "/messages") showInbox();
|
||||
else if (path === "/mine/regions") showRegions();
|
||||
else if (path === "/mine/reports") void showReports();
|
||||
else if (path === "/mine/new") void showPublish();
|
||||
else if (edit) void showPublish(edit[1]);
|
||||
else if (own) void showOwner(own[1], own[2]);
|
||||
|
||||
Reference in New Issue
Block a user