From ee5553f04afaad95bdc733f3939eb00255c29420 Mon Sep 17 00:00:00 2001 From: Mqxx <62719703+Mqxx@users.noreply.github.com> Date: Tue, 5 Mar 2024 16:28:55 +0100 Subject: [PATCH] dns records --- src/record/dns_record.ts | 10 ++++++++++ src/record/dns_record_type.ts | 1 + src/record/record_type.ts | 1 - src/url/parse_url_parametrs.ts | 19 ++++++++++++++++++- src/url/url_parameters.ts | 7 ++----- 5 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 src/record/dns_record.ts create mode 100644 src/record/dns_record_type.ts delete mode 100644 src/record/record_type.ts diff --git a/src/record/dns_record.ts b/src/record/dns_record.ts new file mode 100644 index 0000000..da7bdb4 --- /dev/null +++ b/src/record/dns_record.ts @@ -0,0 +1,10 @@ +import { DNSRecordType } from './dns_record_type.ts'; + +export interface DNSRecord { + type : DNSRecordType, + name : string, + address : string, + proxy? : boolean, + ttl? : number, + comment? : string +} diff --git a/src/record/dns_record_type.ts b/src/record/dns_record_type.ts new file mode 100644 index 0000000..79277a2 --- /dev/null +++ b/src/record/dns_record_type.ts @@ -0,0 +1 @@ +export type DNSRecordType = 'A' | 'AAAA' | 'CNAME' diff --git a/src/record/record_type.ts b/src/record/record_type.ts deleted file mode 100644 index be18478..0000000 --- a/src/record/record_type.ts +++ /dev/null @@ -1 +0,0 @@ -export type RecordType = 'A' | 'AAAA' | 'CNAME' diff --git a/src/url/parse_url_parametrs.ts b/src/url/parse_url_parametrs.ts index 86fb72f..909a026 100644 --- a/src/url/parse_url_parametrs.ts +++ b/src/url/parse_url_parametrs.ts @@ -1,7 +1,24 @@ import { URLParameters } from './url_parameters.ts'; +import { DNSRecord } from '../record/dns_record.ts' export function parseUrlParameters(parameters : URLSearchParams) : URLParameters { + const token = parameters.get('token'); + const zoneId = parameters.get('zoneId'); + const records = parameters.get('records'); + + if (!token) { + throw new Error('Missing parameter: "token"') + } + if (!zoneId) { + throw new Error('Missing parameter: "zoneId"') + } + if (!records) { + throw new Error('Missing parameter: "records"') + } + return { - + token, + zoneId, + records: JSON.parse(records) as DNSRecord[] } } diff --git a/src/url/url_parameters.ts b/src/url/url_parameters.ts index 35ca054..64794cc 100644 --- a/src/url/url_parameters.ts +++ b/src/url/url_parameters.ts @@ -1,10 +1,7 @@ -import { RecordType } from '../record/record_type.ts'; +import { DNSRecord } from '../record/dns_record.ts'; export interface URLParameters { token : string, zoneId : string, - type : RecordType, - ipv4 : string, - ipv6 : string, - + records : DNSRecord[] }