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:
@@ -88,6 +88,47 @@ export async function postMessage(envelope: Envelope): Promise<void> {
|
||||
throw new HttpError(res.status, detail, requiredBits);
|
||||
}
|
||||
|
||||
/** What one node makes of the abuse reports about a listing. */
|
||||
export interface ReportSummary {
|
||||
/** The node's own rules hide the listing from search. */
|
||||
hidden: boolean;
|
||||
/** Reports from reporters this node trusts, by category. */
|
||||
trusted: Record<string, number>;
|
||||
/** Reports from reporters it does not trust: shown, never counted. */
|
||||
others: number;
|
||||
/** Tips from visitors waiting for the operator. */
|
||||
signals: number;
|
||||
/** The operator's own report, if any. */
|
||||
own?: string;
|
||||
}
|
||||
|
||||
/** The reports about a listing, or null if this node cannot say. */
|
||||
export async function getReportSummary(author: string, id: string): Promise<ReportSummary | null> {
|
||||
try {
|
||||
const res = await fetch(`/api/v1/reports?author=${author}&id=${id}`);
|
||||
if (!res.ok) return null;
|
||||
const s = (await res.json()) as Partial<ReportSummary>;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/** Tells the node's operator about a listing. Unsigned: backed only by proof-of-work (see sendTip). */
|
||||
export async function postSignal(body: string): Promise<void> {
|
||||
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()) as { error?: unknown };
|
||||
if (typeof b.error === "string") detail = b.error;
|
||||
} catch {
|
||||
// keep the status text
|
||||
}
|
||||
throw new HttpError(res.status, detail);
|
||||
}
|
||||
|
||||
/** Envelopes in a mailbox created at or after `since` (unix seconds). Unverified. */
|
||||
export async function pollMailbox(tag: string, since: number): Promise<unknown[]> {
|
||||
const data = await getJSON(`/api/v1/messages?mailbox=${encodeURIComponent(tag)}&since=${since}`);
|
||||
|
||||
Reference in New Issue
Block a user