From 10c27721311fe3fbec659915985d088620869bc3 Mon Sep 17 00:00:00 2001 From: William Walker Date: Thu, 23 Jan 2025 07:46:56 -0600 Subject: [PATCH] fix: persist record comments (#139) * chore: clean up ts errors * fix: persist record comments --- src/index.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7d711cd..ce01c94 100644 --- a/src/index.ts +++ b/src/index.ts @@ -74,7 +74,7 @@ async function update(clientOptions: ClientOptions, newRecord: AddressableRecord const records = ( await cloudflare.dns.records.list({ zone_id: zone.id, - name: newRecord.name, + name: newRecord.name as any, type: newRecord.type, }) ).result; @@ -85,19 +85,21 @@ async function update(clientOptions: ClientOptions, newRecord: AddressableRecord throw new HttpError(400, 'No record found! You must first manually create the record.'); } - // Extract the current `proxied` status + // Extract current properties const currentRecord = records[0] as AddressableRecord; const proxied = currentRecord.proxied ?? false; // Default to `false` if `proxied` is undefined + const comment = currentRecord.comment; await cloudflare.dns.records.update(records[0].id, { content: newRecord.content, zone_id: zone.id, - name: newRecord.name, + name: newRecord.name as any, type: newRecord.type, proxied, // Pass the existing "proxied" status + comment, // Pass the existing "comment" }); - console.log('DNS record for ' + newRecord.name + '(' + newRecord.type +') updated successfully to ' + newRecord.content); + console.log('DNS record for ' + newRecord.name + '(' + newRecord.type + ') updated successfully to ' + newRecord.content); return new Response('OK', { status: 200 }); } @@ -107,9 +109,7 @@ export default { const url = new URL(request.url); console.log('Requester IP: ' + request.headers.get('CF-Connecting-IP')); console.log(request.method + ': ' + request.url); - if (request.body) { - console.log('Body: ' + await request.text()); - } + console.log('Body: ' + (await request.text())); try { // Construct client options and DNS record