Files
ddns-agent/agent/routes/cloudflare.ts
2025-11-16 13:32:35 +08:00

26 lines
732 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {app} from '../app.ts';
import { CloudflareDDNS } from '../ddns/cloudflare/index.ts';
app.route({
path: 'cf',
key: 'update',
description: '更新Cloudflare DNS记录, 需要提供zone_id, record_id, domain, new_ip, api_token, type参数 type参数可选默认为A记录 A 或AAAA',
}).define(async (ctx) => {
const { zone_id, record_id, domain, new_ip, api_token, type = 'A' } = ctx.query || {};
if(!zone_id || !record_id || !domain || !new_ip || !api_token) {
ctx.throw?.('缺少必要参数');
}
const cf = new CloudflareDDNS();
const result = await cf.updateRecord({
zone_id,
record_id,
domain,
new_ip,
api_token,
type,
});
ctx.body = { result };
}).addTo(app);