Something went wrong. Try again.
A live media wall for your Bluesky follows
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980export type ContentMode = 'account' | 'hide' | 'blur' | 'show';export type ContentSettings = { adultContent: 'account' | 'allow' | 'disallow'; labels: Record<string, ContentMode>; includeReposts?: boolean; repostCooldownHours?: number;};
type SettingsStorage = Pick<Storage, 'getItem' | 'setItem'>;const modes = new Set(['account', 'hide', 'blur', 'show']);const key = (did: string) => `mural:content-settings:v2:${did}`;
export function defaultContentSettings(): ContentSettings { return { adultContent: 'account', labels: {} };}
export function parseContentSettings(value: unknown): ContentSettings { const result = defaultContentSettings(); if (!value || typeof value !== 'object') return result; const input = value as Record<string, unknown>; if (input.includeReposts === true) result.includeReposts = true; if ( typeof input.repostCooldownHours === 'number' && Number.isFinite(input.repostCooldownHours) && input.repostCooldownHours > 0 && input.repostCooldownHours <= 720 ) result.repostCooldownHours = input.repostCooldownHours; if (input.adultContent === 'allow' || input.adultContent === 'disallow') result.adultContent = input.adultContent; if (input.labels && typeof input.labels === 'object' && !Array.isArray(input.labels)) { for (const [name, mode] of Object.entries(input.labels).slice(0, 200)) { if ( name.length > 256 || name === '__proto__' || name === 'constructor' || name === 'prototype' ) continue; if (typeof mode === 'string' && modes.has(mode) && mode !== 'account') result.labels[name] = mode as ContentMode; } } return result;}
function browserStorage(): SettingsStorage | undefined { try { return typeof localStorage === 'undefined' ? undefined : localStorage; } catch { return undefined; }}
export function readContentSettings(did?: string, storage = browserStorage()): ContentSettings { if (!did?.startsWith('did:')) return defaultContentSettings(); try { const raw = storage?.getItem(key(did)); return raw && raw.length <= 65_536 ? parseContentSettings(JSON.parse(raw)) : defaultContentSettings(); } catch { return defaultContentSettings(); }}
export function saveContentSettings( did: string | undefined, settings: ContentSettings, storage = browserStorage()): boolean { try { if (!did?.startsWith('did:') || !storage) return false; storage.setItem(key(did), JSON.stringify(parseContentSettings(settings))); return true; } catch { return false; }}