Let people take back the sites they had before the gateway

The domains Shakespeare Deploy published to are now served by a gateway that
took them over, and the sites already under those names had to keep working, so
they were republished under an archive key rather than left to break. That key
is not theirs. This is how it stops speaking for them: the gateway holds a
record of who each name is waiting for, they publish their own copy of the site,
and the name is repointed at it.

All of it at once, because the person with one name to recover is not the person
this is for. Doing it a site at a time through the deploy button would mean
re-deploying a hundred projects, most of which are no longer checked out
anywhere, to recover sites whose files the gateway already has.

The list is only reached by asking, never on page load: finding out what is
waiting costs a signature, and a signing prompt nobody asked for is worse than a
button that sometimes opens an empty list.

A name whose site was always published under its owner's key needs nothing
republished — the record is the whole migration. The rest need the archived
manifest signed again, which reproduces the site exactly, since a manifest is
its tags and the blobs are addressed by hash and already sit where the server
tags say. Publishing happens before claiming, so the name never points at an
event the gateway has not fetched.

What a name must never do is come back at the cost of a live one. Kind 35128 is
addressable, so republishing an archived snapshot at a `d` tag someone already
publishes under would replace the current site with an old copy of itself —
which is not hypothetical: two of the first hundred names looked at were exactly
that. Those are claimed straight to the site that already exists, so both names
end up serving it. Working that out needs relays to answer, so silence from them
is treated as silence and not as "publishes nothing": a user whose own sites the
gateway is already serving must see at least those come back, or nothing is
planned at all.

Also fixes ProviderConfigDialog, which had grown a relay list and a server list
and no height limit, and was pushing its own Save button off the bottom of the
screen with no way to scroll to it.
This commit is contained in:
Alex Gleason committed 2026-09-13 15:05:37 -05:00
1 parent fc26a8b27b
commit cb5561ba69
8 files changed
+715 -40

No files matched your search

+86
View File
@@ -0,0 +1,86 @@
import { useQuery } from '@tanstack/react-query';
import { useNostr } from '@nostrify/react';
import { useCurrentUser } from '@/hooks/useCurrentUser';
import type { NpanelProvider } from '@/contexts/DeploySettingsContext';
import { fetchNpanelClaims, type NpanelClaim } from '@/lib/deploy/npanelApi';
import { NAMED_SITE_KIND, planClaim, type MigrationStep } from '@/lib/deploy/npanelMigration';
/** How long the relay round trip for one's own sites is given. */
const RELAY_TIMEOUT_MS = 4_000;
/** A waiting name, with what it would take to get it back. */
export interface NpanelClaimPlan extends NpanelClaim {
step: MigrationStep;
}
/** The `identifier` half of a `kind:pubkey:identifier` address. */
function addressIdentifier(address: string): string {
return address.split(':').slice(2).join(':');
}
/**
* The names waiting for the logged-in user on a gateway, and what each needs.
*
* The second half of the answer comes from relays rather than the gateway: to
* know whether a name can simply be repointed, one has to know which sites this
* user already publishes, and that is on the network, not in npanel.
*/
export function useNpanelClaims(provider: NpanelProvider | undefined) {
const { user } = useCurrentUser();
const { nostr } = useNostr();
return useQuery<NpanelClaimPlan[]>({
queryKey: ['npanel-claims', provider?.dashboardHost, user?.pubkey],
enabled: Boolean(provider && user),
// Nobody's list of waiting names changes on its own, and every refetch
// costs a signature — which on a remote signer costs a round trip.
staleTime: 5 * 60 * 1000,
refetchOnWindowFocus: false,
retry: false,
queryFn: async ({ signal }) => {
if (!provider || !user) return [];
const claims = await fetchNpanelClaims(provider.dashboardHost, user.signer, signal);
if (!claims.length) return [];
// Only the names actually in play are asked about, rather than every
// site this key has ever published.
const wanted = new Set<string>();
for (const claim of claims) {
const identifier = claim.manifest?.tags.find(([name]) => name === 'd')?.[1];
if (identifier) wanted.add(identifier);
if (claim.mine && claim.address) wanted.add(addressIdentifier(claim.address));
}
const events = wanted.size
? await nostr.group(provider.relayUrls).query(
[{ kinds: [NAMED_SITE_KIND], authors: [user.pubkey], '#d': [...wanted] }],
{ signal: AbortSignal.any([signal, AbortSignal.timeout(RELAY_TIMEOUT_MS)]) },
)
: [];
const published = new Set(
events
.map((event) => event.tags.find(([name]) => name === 'd')?.[1])
.filter((identifier): identifier is string => Boolean(identifier)),
);
// A name npanel serves from this user's own key is a site this user
// published, so relays that know nothing about it are relays that are
// not answering. Planning against that silence would mean republishing
// over live sites, so it fails loudly instead.
const known = claims
.filter((claim) => claim.mine && claim.address)
.map((claim) => addressIdentifier(claim.address ?? ''))
.filter(Boolean);
if (known.length && !known.some((identifier) => published.has(identifier))) {
throw new Error(
'Relays did not answer with the sites you already publish, so it is not safe to work out what needs republishing. Try again in a moment.',
);
}
return claims.map((claim) => ({ ...claim, step: planClaim(claim, user.pubkey, published) }));
},
});
}