fedipod-server 0.13.0 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34555,8 +34555,40 @@ var PodStore = class {
34555
34555
  this.cache.set("ids.json", ids);
34556
34556
  return id;
34557
34557
  }
34558
+ // The map first, for ids minted under an older scheme. Then, because the
34559
+ // id IS the hash of the url, whatever this store knows is scanned for the
34560
+ // url that hashes to it — actors, posts, contacts, requests, media. The
34561
+ // browser build's worker is stopped whenever it idles, and the in-memory
34562
+ // map went with it: a client clicking an account it had just been shown
34563
+ // reached a fresh worker that held the actor and could not name it.
34558
34564
  urlFor(id) {
34559
- return this.getIds()[id] || null;
34565
+ const ids = this.getIds();
34566
+ if (ids[id]) return ids[id];
34567
+ if (!/^[a-f0-9]{16}$/u.test(String(id))) return null;
34568
+ const hash = (u) => node_crypto_default.createHash("sha256").update(u).digest("hex").slice(0, 16);
34569
+ const seen = /* @__PURE__ */ new Set();
34570
+ const candidates = function* (store) {
34571
+ for (const u of Object.keys(store.getActors())) yield u;
34572
+ for (const st2 of store.getStatuses()) {
34573
+ yield st2.noteId;
34574
+ yield st2.actor;
34575
+ for (const a of st2.attachments || []) if (a?.url) yield a.url;
34576
+ }
34577
+ const c = store.getContacts();
34578
+ for (const f of [...c.followers, ...c.following]) if (f?.actor) yield f.actor;
34579
+ for (const r of store.getRequests()) if (r?.actor) yield r.actor;
34580
+ for (const u of Object.keys(store.getMedia())) yield u;
34581
+ };
34582
+ for (const u of candidates(this)) {
34583
+ if (typeof u !== "string" || seen.has(u)) continue;
34584
+ seen.add(u);
34585
+ if (hash(u) === id) {
34586
+ ids[id] = u;
34587
+ this.cache.set("ids.json", ids);
34588
+ return u;
34589
+ }
34590
+ }
34591
+ return null;
34560
34592
  }
34561
34593
  };
34562
34594
 
@@ -55555,10 +55587,16 @@ function indexQuads(quads) {
55555
55587
  }
55556
55588
  return { bySubject, objects, blanks };
55557
55589
  }
55558
- function findRoot({ bySubject, objects }) {
55559
- for (const s of bySubject.keys()) if (!objects.has(s)) return s;
55560
- for (const [s, preds] of bySubject) if (preds.has(RDF_TYPE)) return s;
55561
- return bySubject.keys().next().value ?? null;
55590
+ function findRoot({ bySubject, objects, blanks }) {
55591
+ const all = [...bySubject.keys()];
55592
+ const named = all.filter((s) => !blanks.has(s));
55593
+ const free = all.filter((s) => !objects.has(s));
55594
+ const freeNamed = free.find((s) => !blanks.has(s));
55595
+ if (freeNamed) return freeNamed;
55596
+ if (free.length) return free[0];
55597
+ for (const s of named) if (bySubject.get(s).has(RDF_TYPE)) return s;
55598
+ for (const s of all) if (bySubject.get(s).has(RDF_TYPE)) return s;
55599
+ return named[0] ?? all[0] ?? null;
55562
55600
  }
55563
55601
  function readList(head, ctx, depth, path) {
55564
55602
  const out = [];
@@ -55636,7 +55674,7 @@ function makeView(subject, ctx, depth = 0, seen = /* @__PURE__ */ new Set()) {
55636
55674
  function graphView(quads, { root = null } = {}) {
55637
55675
  if (!quads || !quads.length) return null;
55638
55676
  const ctx = indexQuads(quads);
55639
- const subject = root ?? findRoot(ctx);
55677
+ const subject = root && ctx.bySubject.has(root) ? root : findRoot(ctx);
55640
55678
  if (!subject) return null;
55641
55679
  const view = makeView(subject, ctx);
55642
55680
  return view && typeof view === "object" ? view : null;
@@ -55695,19 +55733,21 @@ function groundContext(input) {
55695
55733
  return { ...input, "@context": kept.length === 1 ? kept[0] : kept };
55696
55734
  }
55697
55735
  async function readLenient(raw) {
55736
+ let input = null;
55737
+ try {
55738
+ input = typeof raw === "string" ? JSON.parse(raw) : raw ?? null;
55739
+ } catch {
55740
+ }
55741
+ const own = input && typeof input === "object" ? input.id ?? input["@id"] : null;
55742
+ const root = typeof own === "string" && /^https?:\/\//u.test(own) ? own : null;
55698
55743
  try {
55699
55744
  const { doc, graph: graph2 } = await parseAS2(raw);
55700
- return { doc, graph: graph2, view: graphView(graph2), degraded: null };
55745
+ return { doc, graph: graph2, view: graphView(graph2, { root }), degraded: null };
55701
55746
  } catch (e) {
55702
- let input = null;
55703
- try {
55704
- input = typeof raw === "string" ? JSON.parse(raw) : raw ?? null;
55705
- } catch {
55706
- }
55707
55747
  if (!input || typeof input !== "object") return { doc: null, graph: null, view: null, degraded: e.message };
55708
55748
  try {
55709
55749
  const { graph: graph2 } = await parseAS2(groundContext(input));
55710
- return { doc: input, graph: graph2, view: graphView(graph2), degraded: e.message };
55750
+ return { doc: input, graph: graph2, view: graphView(graph2, { root }), degraded: e.message };
55711
55751
  } catch (inner) {
55712
55752
  return { doc: input, graph: null, view: null, degraded: `${e.message}; grounded read also failed: ${inner.message}` };
55713
55753
  }
@@ -65423,7 +65463,8 @@ async function handle4(api, ctx) {
65423
65463
  }
65424
65464
  const hit = Object.entries(api.store.getActors()).find(([u, a]) => {
65425
65465
  try {
65426
- return `${a.preferredUsername}@${new URL(u).host}` === acct;
65466
+ const at = new URL(u);
65467
+ return `${a.preferredUsername}@${at.host}` === acct || `${a.preferredUsername}@${at.hostname}` === acct;
65427
65468
  } catch {
65428
65469
  return false;
65429
65470
  }
@@ -67364,6 +67405,14 @@ var Deliverer = class {
67364
67405
 
67365
67406
  // web/app/deliver-relay.mjs
67366
67407
  init_fedify_sig();
67408
+ function doorKeyOf(doorInboxUrl) {
67409
+ try {
67410
+ const seg2 = new URL(doorInboxUrl).pathname.split("/");
67411
+ return seg2[1] === "u" && seg2[2] ? decodeURIComponent(seg2[2]) : null;
67412
+ } catch {
67413
+ return null;
67414
+ }
67415
+ }
67367
67416
  var RelayDeliverer = class extends Deliverer {
67368
67417
  constructor(opts) {
67369
67418
  super(opts);
@@ -67388,6 +67437,7 @@ var RelayDeliverer = class extends Deliverer {
67388
67437
  headers: {
67389
67438
  date: s.headers.date,
67390
67439
  digest: s.headers.digest,
67440
+ accept: s.headers.accept,
67391
67441
  "content-type": s.headers["content-type"],
67392
67442
  signature: s.headers.signature
67393
67443
  }
@@ -69615,7 +69665,9 @@ var BrowserAgent = class _BrowserAgent {
69615
69665
  actorId: this.urls.actor,
69616
69666
  log: this.log,
69617
69667
  relayUrl: `${frontOrigin.replace(/\/$/, "")}/api/relay`,
69618
- handle: config.handle,
69668
+ // The relay finds the account by the front's own key for it, which for a
69669
+ // mail-door account is the full address, not the bare handle.
69670
+ handle: doorKeyOf(config.gateway?.url) || config.handle,
69619
69671
  sessionFetch: session.fetch
69620
69672
  });
69621
69673
  this.publisher = new Publisher({