fix(federation): persist remote instance_name from approval-requests/:id/approve handshake response

Third initiator path that calls remote /peer/accept. Mirrors performHandshake (auto-peer) and /peer/initiate (admin-initiate) — same try/catch parse, same null-or-non-empty-string guard. Caught in final review of #33; same root cause as Bug #1, bundled rather than fragmented to a new backlog item.
This commit is contained in:
Jannis Braun
2026-04-25 11:18:12 +02:00
parent 4aced5654b
commit f0d6bf2ed9
2 changed files with 88 additions and 1 deletions
+14 -1
View File
@@ -1169,8 +1169,21 @@ export async function federationRoutes(app: FastifyInstance): Promise<void> {
return reply.code(502).send({ error: errorMessage, statusCode: 502 });
}
// Parse the remote's instanceName from the response body so the
// federation panel renders a friendly label. Tolerate omission and
// non-JSON bodies — same pattern as performHandshake and /peer/initiate.
let remoteInstanceName: string | null = null;
try {
const body = (await response.json()) as { instanceName?: string | null };
if (typeof body?.instanceName === 'string' && body.instanceName.length > 0) {
remoteInstanceName = body.instanceName;
}
} catch {
// Non-JSON body — leave null.
}
db.update(schema.federationPeers)
.set({ status: 'active', lastSeenAt: now })
.set({ status: 'active', lastSeenAt: now, instanceName: remoteInstanceName })
.where(eq(schema.federationPeers.id, peerId))
.run();