-
Notifications
You must be signed in to change notification settings - Fork 0
/
zone.html
674 lines (623 loc) · 34.3 KB
/
zone.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>解析记录 - Cypher</title>
<script src="/static/js/header.js"></script>
<link href="https://fonts.googleapis.cn/css?family=Open+Sans:300,400,600,700" rel="stylesheet" />
<link href="/static/css/fontawesome-pro-6.4.2.min.css" rel="stylesheet" />
<link href="/static/css/soft-ui-dashboard.min.css?v=1.0.7" rel="stylesheet" />
<script async defer src="https://cdn.imyrs.cn/static/umami.v2.min.js"
data-website-id="daa90fea-70f0-42b4-b2ae-4964a5dd3b56" data-host-url="https://stats.imyrs.cn"
data-domains="dns.imyrs.cn,dns.imyrs.com"></script>
</head>
<body class="g-sidenav-show bg-gray-100">
<main class="main-content position-relative max-height-vh-100 h-100 border-radius-lg">
<nav class="navbar navbar-main navbar-expand-lg px-0 mx-4 shadow-none border-radius-xl" id="navbarBlur"
navbar-scroll="true">
<div class="container-fluid py-1 px-3">
<nav aria-label="breadcrumb">
<ol class="breadcrumb bg-transparent mb-0 pb-0 pt-1 px-0 me-sm-6 me-5">
<li class="breadcrumb-item text-sm">Cypher</li>
<li class="breadcrumb-item text-sm"><a href="/zones.html" class="text-muted">域名列表</a></li>
<li class="breadcrumb-item text-sm text-dark active" aria-current="page">解析记录</li>
</ol>
<h6 class="font-weight-bolder mb-0">编辑域名解析</h6>
</nav>
</div>
</nav>
<div class="container-fluid py-4">
<div class="row">
<div class="col-12 col-xl-2">
<div class="card mb-3 position-sticky" style="top: 10%;">
<div class="card-body py-3">
<div class="form-group">
<label class="form-control-label">区域</label>
<select class="form-control form-control-sm" id="page-zone"
onchange="switchZone(this.value)" disabled>
<option>加载中...</option>
</select>
</div>
<div class="form-group">
<label class="form-control-label">每页显示</label>
<select class="form-control form-control-sm" id="page-size"
onchange="updateQuery('page_size', this.value)">
<option value="5">5 条</option>
<option value="10">10 条</option>
<option value="20">20 条</option>
<option value="50">50 条</option>
<option value="100">100 条</option>
</select>
</div>
<div class="form-group">
<label class="form-control-label">排序方式</label>
<select class="form-control form-control-sm" id="order-by"
onchange="updateQuery('order_by', this.value)">
<option value="name">域名</option>
<option value="type">类型</option>
<option value="created_on">创建时间</option>
<option value="modified_on">修改时间</option>
</select>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="direction" checked
onchange="updateQuery('direction', this.checked ? 'desc' : 'asc')">
<label class="form-check-label" for="direction">降序</label>
</div>
</div>
</div>
</div>
<div class="col-12 col-xl-10">
<div class="card mb-4">
<div class="card-header p-3 pb-0">
<div class="d-flex justify-content-between">
<div>
<h5 class="mb-1 text-bolder">
<span id="domain" class="me-2">...</span>
<span class="text-sm text-muted opacity-7">共 <span id="data-length">...</span>
条记录</span>
</h5>
<p class="text-sm text-monospace" id="zone-id"></p>
</div>
<div>
<button class="btn bg-gradient-primary" type="button" onclick="showCreateModal()">
<i class="fas fa-plus-circle me-1"></i>
添加
</button>
</div>
</div>
</div>
<div class="card-body p-3 pt-0">
<div class="table-responsive p-0 mb-0">
<table class="table align-items-center mb-0">
<thead>
<tr>
<th
class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-3">
Host
</th>
<th
class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">
Value
</th>
<th
class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">
Action
</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<div>
<nav>
<ul class="pagination pagination-primary justify-content-end my-0" id="page-links">
</ul>
</nav>
</div>
</div>
</div>
</div>
</div>
<footer class="footer pt-3">
<div class="container-fluid">
<div class="row align-items-center justify-content-lg-between">
<div class="col-lg-6 mb-lg-0 mb-3">
<div class="text-center text-sm text-muted text-lg-start">
Made with <i class="fas fa-heart text-danger"></i> by
<a href="https://imyrs.cn" class="font-weight-bold" target="_blank">ImYrS</a>
using <i class="fab fa-js" style="color: #F7DF1E;"></i> for a better web.
</div>
<div class="text-sm text-center text-muted text-lg-start">
©
<script>document.write(new Date().getFullYear().toString())</script>
ImYrS, All Rights Reserved.
</div>
</div>
<div class="col-lg-6">
<ul class="nav nav-footer justify-content-center justify-content-lg-end">
<li class="nav-item">
<a href="https://github.com/ImYrS/Cypher" class="nav-link text-muted"
target="_blank">
<i class="fa-regular fa-stars me-1"></i>
关于 Cypher
</a>
</li>
<li class="nav-item">
<a href="https://up.imyrs.cn" class="nav-link text-muted" target="_blank">
<i class="fa-regular fa-monitor-waveform me-1"></i>
服务状态
</a>
</li>
<li class="nav-item">
<a href="https://beian.miit.gov.cn" class="nav-link text-muted" target="_blank">
<i class="fa-regular fa-shield-check me-1"></i>
粤 ICP 备 2021162740 号
</a>
</li>
</ul>
</div>
</div>
</div>
</footer>
</div>
</main>
<div class="modal fade" id="edit-record" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-md">
<div class="modal-content">
<div class="modal-body p-0">
<div class="card card-plain">
<div class="card-header pb-0">
<div class="d-flex justify-content-between">
<div>
<h4 class="font-weight-bolder text-primary text-gradient" id="edit-title">添加解析</h4>
</div>
<div class="mb-0">
<div class="form-check">
<input class="form-check-input me-1" type="checkbox" id="edit-mode"
onchange="switchMode()" data-edit>
<label class="form-check-label text-gradient text-danger text-bolder"
for="edit-mode">
高级模式
</label>
</div>
</div>
</div>
</div>
<div class="card-body pb-3">
<form role="form">
<div id="edit-ui">
<div class="row mb-3">
<div class="col-12 col-md-3">
<div class="form-group">
<label class="form-control-label" for="edit-type">类型</label>
<div class="input-group">
<select class="form-control" id="edit-type" data-edit>
<option>A</option>
<option>AAAA</option>
<option>CNAME</option>
<option>TXT</option>
</select>
</div>
</div>
</div>
<div class="col-12 col-md-9">
<div class="form-group">
<label class="form-control-label" for="edit-host">名称</label>
<div class="input-group">
<input type="text" class="form-control" id="edit-host"
autocomplete="off" placeholder="@" data-edit>
</div>
</div>
</div>
</div>
<div class="row mb-3">
<div class="col-12 col-md-3">
<div class="form-group">
<label class="form-control-label" for="edit-ttl">TTL</label>
<div class="input-group">
<input type="number" class="form-control" id="edit-ttl"
placeholder="300" value="300" data-edit>
</div>
</div>
</div>
<div class="col-12 col-md-9">
<div class="form-group">
<label class="form-control-label" for="edit-content">值</label>
<div class="input-group">
<input type="text" class="form-control" id="edit-content"
autocomplete="off" placeholder="1.1.1.1" data-edit>
</div>
</div>
</div>
</div>
<div class="form-check form-switch mb-3">
<input class="form-check-input" type="checkbox" id="edit-proxied"
onchange="proxyFlagChanged()" data-edit>
<label class="form-check-label text-gradient text-warning text-bolder"
for="edit-proxied">
<i class="fa-brands fa-cloudflare me-1 text-lg"></i>
由 Cloudflare 代理流量 (CDN)
</label>
</div>
<div class="text-xs" id="edit-info"></div>
</div>
<div id="edit-raw" style="display: none;">
<div class="form-group">
<label class="form-control-label" for="edit-json">请求 JSON</label>
<div class="input-group">
<textarea class="form-control text-monospace" id="edit-json" data-edit
rows="7"></textarea>
</div>
<div class="text-xs mt-1 mx-1">
请参照
<a href="https://developers.cloudflare.com/api/operations/dns-records-for-a-zone-create-dns-record"
target="_blank" class="text-under">
Cloudflare API 文档
<i class="fa-duotone fa-arrow-up-right-from-square ms-1"></i>
</a>
</div>
</div>
</div>
<div class="text-sm px-1" id="description"></div>
<div class="text-center">
<button type="submit" class="btn bg-gradient-primary btn-rounded w-100 mt-4"
id="edit-btn" data-edit disabled>
提交
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.3/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/sweetalert2/11.7.3/sweetalert2.all.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.11/clipboard.min.js"></script>
<script src="/static/js/soft-ui-dashboard.min.js?v=1.0.7"></script>
<script>
const endpoint = localStorage.endpoint;
const apiToken = localStorage.apiToken;
const accountId = localStorage.accountId;
let params, zoneId, page, pageSize, orderBy, direction;
const clipboard = new ClipboardJS('[data-clipboard]');
clipboard.on('success', (e) => {
let icon = $(e.trigger).find('i');
icon.removeClass('fa-copy').addClass('fa-check');
setTimeout(() => icon.removeClass('fa-check').addClass('fa-copy'), 1000);
});
clipboard.on('error', (e) => {
let icon = $(e.trigger).find('i');
icon.removeClass('fa-copy').addClass('fa-circle-exclamation');
setTimeout(() => icon.removeClass('fa-circle-exclamation').addClass('fa-copy'), 1000);
});
const rawMode = $('#edit-mode');
$('[data-edit]').change(() => {
if (rawMode.is(':checked')) return;
syncRawJSON();
})
const initQuery = () => {
params = new URLSearchParams(location.search);
zoneId = params.get('id');
page = parseInt(params.get('page')) || 1;
pageSize = parseInt(params.get('page_size')) || localStorage.getItem('page_size') || 10;
orderBy = params.get('order_by') || localStorage.getItem('order_by') || 'modified_on';
direction = params.get('direction') || localStorage.getItem('direction') || 'desc';
$('#zone-id').text(zoneId);
$('#page-size').val(pageSize);
$('#order-by').val(orderBy);
$('#direction').prop('checked', direction === 'desc');
if (!zoneId) location.href = '/zones.html';
};
const updateQuery = (key, value, doNotReload = false) => {
let query = new URLSearchParams(window.location.search);
query.set(key, value);
history.replaceState(null, null, `?${query.toString()}`);
localStorage.setItem(key, value);
if (!doNotReload) reload();
};
const switchZone = (zoneInfo) => {
zoneInfo = zoneInfo.split('|');
let zoneId = zoneInfo[0];
let zoneName = zoneInfo[1];
$('#domain').text(zoneName);
updateQuery('page', 1, doNotReload = true);
updateQuery('id', zoneId);
};
const reload = () => {
$('tbody').html('');
initQuery();
getRecords();
};
const loadPagination = (currentPage, totalPages) => {
let links = '';
for (let i = 1; i <= totalPages; i++) {
if (i === currentPage) links += `<li class="page-item active"><a class="page-link" href="javascript:updateQuery('page', ${i});">${i}</a></li>`;
else links += `<li class="page-item"><a class="page-link" href="javascript:updateQuery('page', ${i});">${i}</a></li>`;
}
if (currentPage > 1) {
links = `<li class="page-item"><a class="page-link" href="javascript:updateQuery('page', ${currentPage - 1});"><i class="fa-solid fa-angle-left"></i></a></li>` + links;
}
if (currentPage < totalPages) {
links += `<li class="page-item"><a class="page-link" href="javascript:updateQuery('page', ${currentPage + 1});"><i class="fa-solid fa-angle-right"></i></a></li>`;
}
$('#page-links').html(links);
if (totalPages > 1) $('#page-links').show();
else $('#page-links').hide();
};
class Record {
constructor(record) {
this.id = record.id;
this.type = record.type;
this.name = record.name;
this.content = record.content;
this.proxied = record.proxied;
this.ttl = record.ttl === 1 ? 'Auto' : `${record.ttl}s`;
this.modified_on = record.modified_on;
this.zone_name = record.zone_name;
this.meta = record.meta;
// 额外处理
this.host = (this.name.replace(this.zone_name, '').replace(/\.$/, '') || '@');
this.isWorker = this.meta.origin_worker_id ? true : false;
this.isSaaS = this.meta.fallback_origin ? true : false;
this.canEdit = true;
this.canDelete = true;
if (this.isWorker) {
this.canEdit = false;
this.canDelete = false;
}
if (this.isSaaS) this.canDelete = false;
};
};
const getRecords = () => {
$.ajax({
url: `${endpoint}/client/v4/zones/${zoneId}/dns_records`,
method: 'get',
headers: { 'Authorization': `Bearer ${apiToken}` },
dataType: 'json',
data: {
per_page: pageSize,
page: page,
order: orderBy,
direction: direction
},
success: (resp) => {
loadPagination(page, resp.result_info.total_pages);
$('#data-length').text(resp.result_info.total_count);
let tb = $('tbody');
resp.result.forEach((recordRaw) => {
let record = new Record(recordRaw);
let type = record.isWorker ? 'Worker' : record.type;
let typeClass = record.isWorker ? 'text-gradient text-success' : '';
let proxyIconClass = record.proxied ? 'text-gradient text-warning' : 'text-secondary';
let proxyBtn = record.proxied ? `<button class="btn btn-sm bg-gradient-info mb-0 px-3 mx-1" data-clipboard data-clipboard-text="${record.name}.cdn.cloudflare.net"><i class="fas fa-copy text-xxs me-2"></i>CNAME</button>` : '';
let moreInfo = '';
if (record.isSaaS) moreInfo += `<span class="badge text-xxs bg-gradient-danger text-white"><i class="fa-solid fa-lock me-1"></i> SaaS 回源地址</span>`;
moreInfo = `<div class="d-flex flex-column justify-content-center ms-3">${moreInfo}</div>`;
let tr = '';
tr += `<tr><td><div class="d-flex px-2">`;
tr += `<div class="d-flex flex-column justify-content-center">`;
tr += `<h6 class="mb-0 mt-0"><span class="text-bolder me-2 ${typeClass}">${type}</span>`;
tr += `${record.host}<span class="text-secondary me-2">.${record.zone_name}</span>`;
tr += `<span class="text-sm text-monospace text-primary text-gradient">[TTL ${record.ttl}]</span>`;
tr += `<p class="text-xxs text-secondary mb-0 text-monospace">${new Date(record.modified_on).toLocaleString()}</p>`;
tr += `</div>${moreInfo}</div></td>`;
tr += `<td><div class="d-flex"><div class="d-flex pt-2"><span class="text-sm text-bold mb-0 text-monospace" id="content-${record.id}">${record.content}</span></div>`;
tr += `<div><i class="fa-brands fa-cloudflare fa-2x ms-2 ${proxyIconClass}" title="CDN ${record.proxied ? '已开启' : '未开启'}"></i></div>`;
tr += `</td><td class="text-center">${proxyBtn}`;
tr += `<button class="btn btn-sm btn-dark mb-0 px-3 mx-1" onclick="showEditModal('${record.id}')" style="${record.canEdit ? '' : 'display: none;'}">`;
tr += `<i class="fas fa-pen text-xxs me-2"></i>编辑</button>`;
tr += `<button class="btn btn-sm btn-danger mb-0 px-3 mx-1" onclick="deleteRecord('${record.id}', '${type}', '${record.name}')" style="${(record.canDelete) ? '' : 'display: none;'}">`;
tr += `<i class="fas fa-trash text-xxs me-2"></i>删除</button>`;
tr += `</td></tr>`;
tb.append(tr);
if (record.isWorker) getWorker(record);
});
},
error: (resp) => Swal.fire('加载失败', resp.responseJSON.errors[0].message, 'error'),
complete: () => { }
});
};
const deleteRecord = (id, type, host) => {
Swal.fire({
customClass: {
confirmButton: 'btn bg-gradient-danger', cancelButton: 'btn btn-secondary mx-2'
},
confirmButtonText: '确认删除',
cancelButtonText: '取消',
buttonsStyling: false,
title: '删除解析记录',
text: `即将删除位于 ${host} 的 ${type} 解析记录`,
icon: 'warning',
showCancelButton: true,
reverseButtons: true,
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: `${endpoint}/client/v4/zones/${zoneId}/dns_records/${id}`,
method: 'delete',
headers: { 'Authorization': `Bearer ${apiToken}` },
dataType: 'json',
success: (resp) => {
reload();
Swal.fire('删除成功', '解析记录已删除', 'success');
},
error: (resp) => Swal.fire('删除失败', resp.responseJSON.errors[0].message, 'error'),
complete: () => { }
});
}
});
};
const getRecord = (id) => {
$.ajax({
url: `${endpoint}/client/v4/zones/${zoneId}/dns_records/${id}`,
method: 'get',
headers: { 'Authorization': `Bearer ${apiToken}` },
dataType: 'json',
success: (resp) => {
let record = new Record(resp.result);
let type = $('#edit-type');
let host = $('#edit-host');
let proxied = $('#edit-proxied');
let info = $('#edit-info');
$('[data-edit]').attr('disabled', false);
type.val(record.type).attr('disabled', true);
host.val(resp.result.name.replace(`${resp.result.zone_name}`, '').replace(/\.$/, '') || '@');
proxied.prop('checked', resp.result.proxied).attr('disabled', !resp.result.proxiable);
$('#edit-content').val(resp.result.content);
proxyFlagChanged(resp.result.ttl);
syncRawJSON();
if (record.isSaaS) {
host.attr('disabled', true);
proxied.attr('disabled', true);
info.html('<i class="fa-solid fa-lock me-1"></i> SaaS 回源地址无法更改 Host 和代理状态.').addClass('text-danger');
}
},
error: (resp) => Swal.fire('加载失败', resp.responseJSON.errors[0].message, 'error'),
complete: () => { }
});
};
const proxyFlagChanged = (currentTTL = 0) => {
let ttl = $('#edit-ttl');
if ($('#edit-proxied').is(':checked')) ttl.attr('disabled', true).attr('data-ttl', ttl.val()).val(currentTTL || 1);
else ttl.attr('disabled', false).val(ttl.attr('data-ttl') || currentTTL || 60);
};
const showEditModal = (id) => {
$('#edit-title').text('编辑解析');
$('#edit-btn').attr('onclick', `editRecord('${id}')`);
$('[data-edit]').attr('disabled', true).val('').removeClass('is-invalid').removeClass('is-valid');
$('#edit-record').modal('show');
$('#edit-mode').prop('checked', false);
$('#edit-info').html('').removeClass('text-danger');
switchMode();
getRecord(id);
};
const showCreateModal = () => {
$('#edit-title').text('添加解析');
$('#edit-btn').attr('onclick', 'editRecord()');
$('[data-edit]').attr('disabled', false).val('').removeClass('is-invalid').removeClass('is-valid');
$('#edit-type').val('A');
$('#edit-proxied').prop('checked', false);
$('#edit-record').modal('show');
$('#edit-mode').prop('checked', false);
switchMode();
proxyFlagChanged();
syncRawJSON();
};
const checkField = (ele) => {
if (!ele.val()) {
ele.addClass('is-invalid');
ele.focus();
return false;
}
ele.removeClass('is-invalid').addClass('is-valid');
return true;
}
const editRecord = (id = '') => {
if (event) event.preventDefault();
let data;
if (!rawMode.is(':checked')) {
let type = $('#edit-type');
let host = $('#edit-host');
let ttl = $('#edit-ttl');
let content = $('#edit-content');
let proxied = $('#edit-proxied');
if (!host.val()) host.val('@');
if (!checkField(type) || !checkField(host) || !checkField(ttl) || !checkField(content)) return;
data = JSON.stringify({
type: type.val(),
name: host.val(),
ttl: ttl.val(),
content: content.val(),
proxied: proxied.is(':checked')
});
} else data = $('#edit-json').val();
$('#edit-btn').attr('disabled', true).html('<span class="spinner-border spinner-border-sm"></span>');
let action = id ? '修改' : '添加';
$.ajax({
url: `${endpoint}/client/v4/zones/${zoneId}/dns_records${id ? '/' + id : ''}`,
method: id ? 'put' : 'post',
headers: { 'Authorization': `Bearer ${apiToken}` },
dataType: 'json',
data: data,
success: (resp) => {
$('#edit-record').modal('hide');
reload();
Swal.fire(`${action}成功`, `解析记录已${action}`, 'success');
},
error: (resp) => Swal.fire(`${action}失败`, resp.responseJSON.errors[0].message, 'error'),
complete: () => $('#edit-btn').attr('disabled', false).html('提交')
});
};
const switchMode = () => {
if (rawMode.is(':checked')) {
$('#edit-ui').hide();
$('#edit-raw').show();
} else {
$('#edit-ui').show();
$('#edit-raw').hide();
}
};
const syncRawJSON = () => {
$('#edit-json').val(JSON.stringify(
{
type: $('#edit-type').val(),
name: $('#edit-host').val(),
ttl: $('#edit-ttl').val(),
content: $('#edit-content').val(),
proxied: $('#edit-proxied').is(':checked')
},
null,
2
));
}
const getZones = () => {
let zone = $('#page-zone');
zone.attr('disabled', true);
$.ajax({
url: `${endpoint}/client/v4/zones`,
method: 'get',
headers: { 'Authorization': `Bearer ${apiToken}` },
dataType: 'json',
data: {
per_page: 100,
status: 'active'
},
success: (resp) => {
zone.html('');
resp.result.forEach(item => {
zone.append(`<option value="${item.id}|${item.name}">${item.name}</option>`);
if (item.id === zoneId) {
$('#domain').text(item.name);
zone.val(`${item.id}|${item.name}`).attr('disabled', false);
}
});
},
error: (resp) => Swal.fire('加载失败', resp.responseJSON.errors[0].message, 'error'),
complete: () => { }
});
};
const getWorker = (record) => {
$.ajax({
url: `${endpoint}/client/v4/accounts/${accountId}/workers/domains`,
method: 'get',
headers: { 'Authorization': `Bearer ${apiToken}` },
data: { hostname: record.name },
dataType: 'json',
success: (resp) => {
let worker = resp.result[0];
$(`#content-${record.id}`).text(`${worker.service}`).addClass('text-gradient text-success fst-italic');
},
error: (resp) => $(`#content-${record.id}`).text('获取 Worker 信息失败')
});
};
initQuery();
getZones();
getRecords();
</script>
</body>
</html>