generated from template/slidev-template
feat: 添加IPv6地址获取功能,优化Cloudflare DNS记录更新逻辑,更新版本号并添加README
This commit is contained in:
@@ -44,6 +44,24 @@ app.route({
|
||||
|
||||
const cf = new CloudflareDDNS();
|
||||
|
||||
// 先搜索是否已存在相同 domain 和 type 的记录
|
||||
const searchRes = await cf.getList(zone_id, api_token, { search: domain });
|
||||
if (searchRes.success && searchRes.result && searchRes.result.length > 0) {
|
||||
const existingRecord = searchRes.result.find((r: any) => r.name === domain && r.type === type);
|
||||
if (existingRecord) {
|
||||
console.log(`记录已存在: ${domain} (${type}) -> ${existingRecord.content}`);
|
||||
ctx.body = {
|
||||
record_id: existingRecord.id,
|
||||
name: existingRecord.name,
|
||||
content: existingRecord.content,
|
||||
result: existingRecord,
|
||||
existed: true,
|
||||
};
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 不存在则创建新记录
|
||||
const result = await cf.createRecord({
|
||||
zone_id,
|
||||
domain,
|
||||
@@ -52,7 +70,7 @@ app.route({
|
||||
type,
|
||||
});
|
||||
if (result.success === false) {
|
||||
ctx.throw?.(result.errors?.map((e) => e.message).join('; ') || '创建DNS记录失败');
|
||||
ctx.throw?.(result.errors?.map((e: any) => e.message).join('; ') || '创建DNS记录失败');
|
||||
}
|
||||
console.log(`创建成功: ${domain} -> ${new_ip}`);
|
||||
const record_id = result.result.id;
|
||||
@@ -63,7 +81,8 @@ app.route({
|
||||
record_id: record_id,
|
||||
name: name,
|
||||
content: content,
|
||||
result: result.result
|
||||
result: result.result,
|
||||
existed: false,
|
||||
};
|
||||
}).addTo(app);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user