Something went wrong. Try again.
Browser extension: detect and subscribe to standard.site publications on ATProto substandard.blog
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445// A short operator-maintained list of publications that are excluded by// identity, not by a metric. Keep the reason in the audit, and never let a// blocklisted account re-enter through a new publication record.
import { readFile } from 'node:fs/promises'import { resolve } from 'node:path'
const HERE = import.meta.dirnameexport const DEFAULT_BLOCKLIST = resolve(HERE, 'blocklist.json')const DID = /^did:(plc|web):[^\s]+$/i
export async function loadBlocklist(path = DEFAULT_BLOCKLIST) { let data try { data = JSON.parse(await readFile(path, 'utf8')) } catch (err) { throw new Error(`cannot read blocklist ${path}: ${err.message}`) } const accounts = Array.isArray(data?.accounts) ? data.accounts : [] const blocked = new Map() for (const account of accounts) { if (typeof account?.did !== 'string' || !DID.test(account.did)) continue blocked.set(account.did, { did: account.did, handle: typeof account.handle === 'string' ? account.handle : undefined, name: typeof account.name === 'string' ? account.name : undefined, reason: typeof data.reason === 'string' ? data.reason : 'operator blocklist', }) } return { reason: data?.reason, confirmedAt: data?.confirmedAt, blocked }}
export function applyBlocklist(rows, blocked) { if (!(blocked instanceof Map) || blocked.size === 0) return 0 let count = 0 for (const row of rows ?? []) { if (!blocked.has(row.did)) continue row.spam ??= { excluded: false, reasons: [] } row.spam.excluded = true if (!row.spam.reasons.includes('blocklist')) row.spam.reasons.unshift('blocklist') count++ } return count}