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:
+22
-1
@@ -176,6 +176,12 @@ export interface Gateway {
|
||||
mailboxes: Map<string, unknown[]>;
|
||||
/** Make POST /api/v1/messages answer with this status and error. */
|
||||
postFails?: { status: number; error: string };
|
||||
/** What GET /api/v1/reports answers; unset, the route does not exist (an older node). */
|
||||
reports?: unknown;
|
||||
/** Bodies POSTed to /api/v1/signals (a visitor's tips), in order. */
|
||||
tips: string[];
|
||||
/** Make POST /api/v1/signals answer with this status and error. */
|
||||
tipFails?: { status: number; error: string };
|
||||
/** What GET /api/v1/messages/required answers (bits); unset, the route does not exist (an older node). */
|
||||
requiredBits?: number;
|
||||
/** Refuse the next POST once with 429, asking for this many bits of proof-of-work. */
|
||||
@@ -209,6 +215,7 @@ export async function startGateway(opts: GatewayOptions): Promise<Gateway> {
|
||||
queries,
|
||||
posted,
|
||||
mailboxes,
|
||||
tips: [],
|
||||
close: () => new Promise((ok) => server.close(() => ok())),
|
||||
};
|
||||
const server: Server = createServer((req, res) => {
|
||||
@@ -222,9 +229,23 @@ export async function startGateway(opts: GatewayOptions): Promise<Gateway> {
|
||||
res.writeHead(200, { "Content-Type": "text/tab-separated-values" });
|
||||
return void res.end(readFileSync(new URL("../static/places.tsv", import.meta.url)));
|
||||
}
|
||||
if (url.pathname === "/api/v1/reports" && req.method === "GET") {
|
||||
return gateway.reports === undefined ? json(404, { error: "not found" }) : json(200, gateway.reports);
|
||||
}
|
||||
if (url.pathname === "/api/v1/signals" && req.method === "POST") {
|
||||
let body = "";
|
||||
req.on("data", (c) => (body += c));
|
||||
req.on("end", () => {
|
||||
if (gateway.tipFails) return json(gateway.tipFails.status, { error: gateway.tipFails.error });
|
||||
gateway.tips.push(body);
|
||||
res.writeHead(202);
|
||||
res.end();
|
||||
});
|
||||
return;
|
||||
}
|
||||
// The owner's token-protected routes are played by the test, if it sets `owner`.
|
||||
const writesListing = req.method !== "GET" && /^\/api\/v1\/listings(\/[0-9a-f]{32})?$/.test(url.pathname);
|
||||
if (writesListing || /^\/api\/v1\/(mine|inbox|regions|blocked)|^\/api\/v1\/listings\/[0-9a-f]{32}\/address$/.test(url.pathname)) {
|
||||
if (writesListing || /^\/api\/v1\/(mine|inbox|regions|blocked|signals|reports)|^\/api\/v1\/listings\/[0-9a-f]{32}\/address$/.test(url.pathname)) {
|
||||
let body = "";
|
||||
req.on("data", (c) => (body += c));
|
||||
req.on("end", () => {
|
||||
|
||||
Reference in New Issue
Block a user