Fix editing and deleting DNS records from the cached list
The records endpoint returned raw cache rows, whose `id` is this app's own row number (12, 13, ...). The DNS page sends `r.id` back when a record is edited or deleted, so the provider was handed a row number instead of its record id. That only worked straight after a manual Sync, whose response carries the provider's ids; after any save or delete the page reloads from the cache and the problem came back. The ID check added for connected systems now refuses such an id with "That isn't a valid record ID". The list now returns records shaped like a sync's: `id` is the provider's record id. Editing and deleting work from the cached list for every DNS provider. The test checks the list hands out the provider's id, and that deleting with it reaches Cloudflare at the right address; with the old shape it fails. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2dac273b1d
commit
f71756b119
2 files changed
+29
-1
No files matched your search
@@ -283,10 +283,21 @@ dnsRouter.get("/providers/:id/zones/:zoneId/records", asyncHandler(async (req, r
|
||||
const providerId = Number(req.params.id);
|
||||
const zoneId = req.params.zoneId;
|
||||
|
||||
const records = await db
|
||||
const rows = await db
|
||||
.select()
|
||||
.from(dnsRecordsCache)
|
||||
.where(and(eq(dnsRecordsCache.providerId, providerId), eq(dnsRecordsCache.zoneId, zoneId)));
|
||||
// Shaped like what the provider returns on a sync: `id` is the provider's own record id, which is what editing and deleting
|
||||
// send back. A cache row's own `id` is just a row number in this app's database and means nothing to the provider.
|
||||
const records = rows.map((r) => ({
|
||||
id: r.recordId,
|
||||
type: r.type,
|
||||
name: r.name,
|
||||
content: r.content,
|
||||
ttl: r.ttl,
|
||||
priority: r.priority,
|
||||
proxied: r.proxied,
|
||||
}));
|
||||
const [zoneCache] = await db
|
||||
.select()
|
||||
.from(dnsZonesCache)
|
||||
|
||||
Reference in new issue
Block a user