This commit is contained in:
2025-11-14 20:43:59 +08:00
parent d1ba8bbab1
commit e35712820f
16 changed files with 606 additions and 14 deletions

View File

@@ -0,0 +1,37 @@
interface DnsUpdate {
zone_id: string;
record_id: string;
domain: string;
new_ip: string;
api_token: string;
type?: string; // 'A' or 'AAAA'
}
export class CloudflareDDNS {
makeHeader(api_token: string) {
return {
'Authorization': `Bearer ${api_token}`,
'Content-Type': 'application/json',
};
}
async updateRecord(data: DnsUpdate) {
const { zone_id, record_id, domain, type ,new_ip, api_token } = data;
const url = `https://api.cloudflare.com/client/v4/zones/${zone_id}/dns_records/${record_id}`;
const body = {
"type": type || 'A',
"name": domain,
"content": new_ip,
"ttl": 0,
"proxied": false,
}
const response = await fetch(url, {
method: 'PUT',
headers: this.makeHeader(api_token),
body: JSON.stringify(body),
});
const result = await response.json();
if(!result.success) {
throw new Error(`更新失败: ${JSON.stringify(result.errors)}`);
}
return result;
}
}