diff --git a/index.html b/index.html index fb74acb..8de5220 100644 --- a/index.html +++ b/index.html @@ -390,6 +390,84 @@ this.loading = false; }, })); + + Alpine.data('pdsHistory', (did, currentPds) => ({ + loading: false, + error: null, + history: [], + + async init() { + this.loading = true; + this.error = null; + this.history = []; + try { + const res = await fetch(`https://plc.directory/${did}/log/audit`); + if (res.ok) { + const log = await res.json(); + const seen = new Set(); + seen.add(currentPds); + for (op of log) { + const opPds = op.operation.services.atproto_pds.endpoint; + if (seen.has(opPds)) continue; + seen.add(opPds); + this.history.push({ + pds: opPds, + date: op.createdAt, + }); + } + this.history.reverse(); + } else { + this.error = `${res.status}: ${await res.text()}`; + } + } catch (e) { + this.error = 'failed to get history'; + console.error(e); + } + this.loading = false; + }, + })); + + Alpine.data('handleHistory', (did, currentHandle) => ({ + loading: false, + error: null, + history: [], + + async init() { + this.loading = true; + this.error = null; + this.history = []; + try { + const res = await fetch(`https://plc.directory/${did}/log/audit`); + if (res.ok) { + const log = await res.json(); + const seen = new Set(); + seen.add(currentHandle); + for (op of log) { + let opHandle = null; + for (aka of op.operation.alsoKnownAs) { + if (aka.startsWith("at://")) { + opHandle = aka.slice("at://".length); + break; + } + } + if (seen.has(opHandle)) continue; + seen.add(opHandle); + this.history.push({ + handle: opHandle, + date: op.createdAt, + }); + } + this.history.reverse(); + } else { + this.error = `${res.status}: ${await res.text()}`; + } + } catch (e) { + this.error = 'failed to get history'; + console.error(e); + } + this.loading = false; + }, + })); }) @@ -449,7 +527,7 @@ x-data="pdsCheck(pds)" x-init="$watch('pds', v => update(v))" > -