mirror of
https://github.com/1f349/admin.1f349.com.git
synced 2024-11-13 23:21:32 +00:00
Convert to record api format
This commit is contained in:
parent
9909f06a40
commit
0c6df00a9d
@ -10,6 +10,12 @@ export const DnsTypeCAA = 257;
|
||||
|
||||
export type AllRecords = SoaRecord | NsRecord | MxRecord | ARecord | AaaaRecord | CnameRecord | TxtRecord | SrvRecord | CaaRecord;
|
||||
|
||||
export interface ApiRecordFormat {
|
||||
name: string;
|
||||
type: number;
|
||||
value: any;
|
||||
}
|
||||
|
||||
export interface RecordHeader {
|
||||
Name: string;
|
||||
Rrtype: number;
|
||||
|
@ -3,7 +3,7 @@
|
||||
import type {RestItem, RestTable} from "../utils/rest-table";
|
||||
import PromiseTable from "../components/PromiseTable.svelte";
|
||||
import PromiseLike from "../components/PromiseLike.svelte";
|
||||
import type {AllRecords, UnknownRecord} from "../types/records";
|
||||
import type {AllRecords, ApiRecordFormat, UnknownRecord} from "../types/records";
|
||||
import ActionPopup from "../components/ActionPopup.svelte";
|
||||
|
||||
type T = $$Generic<UnknownRecord>;
|
||||
@ -11,6 +11,7 @@
|
||||
export let recordName: string;
|
||||
export let table: RestTable<AllRecords>;
|
||||
export let emptyRecord: (() => any) | null;
|
||||
export let convert: (t: T) => ApiRecordFormat;
|
||||
export let rowOrdering: (rows: RestItem<AllRecords>[], domain: string, isTRecord: (t: UnknownRecord) => t is T) => RestItem<T>[];
|
||||
export let isTRecord: (t: UnknownRecord) => t is T;
|
||||
|
||||
@ -18,7 +19,8 @@
|
||||
let createPopup: boolean = false;
|
||||
|
||||
function createRecord() {
|
||||
table.addItem(createItem as any);
|
||||
if (createItem == null) return;
|
||||
table.addItem(convert(createItem) as any);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
type ARecord,
|
||||
type AaaaRecord,
|
||||
type AllRecords,
|
||||
type ApiRecordFormat,
|
||||
type CaaRecord,
|
||||
type CnameRecord,
|
||||
type MxRecord,
|
||||
@ -133,6 +134,11 @@
|
||||
},
|
||||
Ns: "",
|
||||
}),
|
||||
convert: (t: NsRecord): ApiRecordFormat => ({
|
||||
name: t.Hdr.Name,
|
||||
type: t.Hdr.Rrtype,
|
||||
value: t.Ns,
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "MX",
|
||||
@ -150,6 +156,14 @@
|
||||
Mx: "",
|
||||
Preference: 0,
|
||||
}),
|
||||
convert: (t: MxRecord): ApiRecordFormat => ({
|
||||
name: t.Hdr.Name,
|
||||
type: t.Hdr.Rrtype,
|
||||
value: {
|
||||
mx: t.Mx,
|
||||
preference: t.Preference,
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "A/AAAA",
|
||||
@ -167,6 +181,11 @@
|
||||
A: "",
|
||||
AAAA: "",
|
||||
}),
|
||||
convert: (t: ARecord | AaaaRecord): ApiRecordFormat => ({
|
||||
name: t.Hdr.Name,
|
||||
type: t.Hdr.Rrtype,
|
||||
value: isARecord(t) ? t.A : isAaaaRecord(t) ? t.AAAA : "",
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "CNAME",
|
||||
@ -183,6 +202,11 @@
|
||||
},
|
||||
Target: "",
|
||||
}),
|
||||
convert: (t: CnameRecord): ApiRecordFormat => ({
|
||||
name: t.Hdr.Name,
|
||||
type: t.Hdr.Rrtype,
|
||||
value: t.Target,
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "TXT",
|
||||
@ -199,6 +223,11 @@
|
||||
},
|
||||
Txt: [""],
|
||||
}),
|
||||
convert: (t: TxtRecord): ApiRecordFormat => ({
|
||||
name: t.Hdr.Name,
|
||||
type: t.Hdr.Rrtype,
|
||||
value: t.Txt,
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "SRV",
|
||||
@ -218,6 +247,16 @@
|
||||
Port: 0,
|
||||
Target: "",
|
||||
}),
|
||||
convert: (t: SrvRecord): ApiRecordFormat => ({
|
||||
name: t.Hdr.Name,
|
||||
type: t.Hdr.Rrtype,
|
||||
value: {
|
||||
priority: t.Priority,
|
||||
weight: t.Weight,
|
||||
port: t.Port,
|
||||
target: t.Target,
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "CAA",
|
||||
@ -236,6 +275,15 @@
|
||||
Tag: "",
|
||||
Value: "",
|
||||
}),
|
||||
convert: (t: CaaRecord): ApiRecordFormat => ({
|
||||
name: t.Hdr.Name,
|
||||
type: t.Hdr.Rrtype,
|
||||
value: {
|
||||
flag: t.Flag,
|
||||
tag: t.Tag,
|
||||
value: t.Value,
|
||||
},
|
||||
}),
|
||||
},
|
||||
];
|
||||
|
||||
@ -252,7 +300,14 @@
|
||||
{/if}
|
||||
|
||||
{#each recordTypes as recordType}
|
||||
<DomainTableView recordName={recordType.name} {table} emptyRecord={recordType.empty} {rowOrdering} isTRecord={recordType.filter}>
|
||||
<DomainTableView
|
||||
recordName={recordType.name}
|
||||
{table}
|
||||
emptyRecord={recordType.empty}
|
||||
convert={recordType.convert}
|
||||
{rowOrdering}
|
||||
isTRecord={recordType.filter}
|
||||
>
|
||||
<tr slot="headers">
|
||||
{#each recordType.headers as header}
|
||||
<th>{header}</th>
|
||||
|
Loading…
Reference in New Issue
Block a user