mirror of
https://github.com/fosrl/pangolin.git
synced 2026-10-29 15:09:07 +01:00
Adjust how multi record items are stored
This commit is contained in:
@@ -10,13 +10,16 @@ export const CUSTOM_DNS_RECORD_TYPES = [
|
||||
|
||||
export type CustomDnsRecordType = (typeof CUSTOM_DNS_RECORD_TYPES)[number];
|
||||
|
||||
// One record as the user sees it: a name, type and settings with one or more
|
||||
// values (e.g. both nameservers of an NS record). The DNS server answers with
|
||||
// one resource record per value.
|
||||
export type CustomDnsRecordRow = {
|
||||
customDnsRecordId: number;
|
||||
domainId: string;
|
||||
name: string;
|
||||
fullDomain: string;
|
||||
type: CustomDnsRecordType;
|
||||
value: string;
|
||||
values: string[];
|
||||
ttl: number;
|
||||
priority: number | null;
|
||||
weight: number | null;
|
||||
@@ -30,8 +33,22 @@ export type ListCustomDnsRecordsResponse = {
|
||||
records: CustomDnsRecordRow[];
|
||||
};
|
||||
|
||||
export type CreateCustomDnsRecordsResponse = {
|
||||
records: CustomDnsRecordRow[];
|
||||
};
|
||||
export type CreateOrUpdateCustomDnsRecordResponse = CustomDnsRecordRow;
|
||||
|
||||
export type UpdateCustomDnsRecordResponse = CustomDnsRecordRow;
|
||||
// The values column holds a JSON-encoded string array
|
||||
export function parseCustomDnsRecordValues(raw: string): string[] {
|
||||
try {
|
||||
const parsed = JSON.parse(raw);
|
||||
return Array.isArray(parsed)
|
||||
? parsed.filter((v): v is string => typeof v === "string")
|
||||
: [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function toCustomDnsRecordRow(
|
||||
row: Omit<CustomDnsRecordRow, "values"> & { values: string }
|
||||
): CustomDnsRecordRow {
|
||||
return { ...row, values: parseCustomDnsRecordValues(row.values) };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user