generated from template/slidev-template
fix: add test
This commit is contained in:
@@ -32,6 +32,14 @@ export class CloudflareDDNS {
|
||||
if(!result.success) {
|
||||
throw new Error(`更新失败: ${JSON.stringify(result.errors)}`);
|
||||
}
|
||||
console.log(`更新成功: ${domain} -> ${new_ip}`);
|
||||
return result;
|
||||
}
|
||||
async getList(zone_id: string, api_token: string) {
|
||||
const url = `https://api.cloudflare.com/client/v4/zones/${zone_id}/dns_records`;
|
||||
return fetch(url, {
|
||||
method: 'GET',
|
||||
headers: this.makeHeader(api_token),
|
||||
}).then(res => res.json());
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ const storage = createStorage({
|
||||
}),
|
||||
});
|
||||
|
||||
type CloudflareConfig = {
|
||||
export type CloudflareConfig = {
|
||||
// Cloudflare 访问地址
|
||||
website: string;
|
||||
domain: string;
|
||||
|
||||
13
agent/test/common.ts
Normal file
13
agent/test/common.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { createStorage } from "unstorage";
|
||||
import fsDriver from "unstorage/drivers/fs";
|
||||
import { CloudflareDDNS } from "@agent/ddns/cloudflare/index.ts";
|
||||
import { CloudflareConfig } from "@agent/task.ts";
|
||||
const storage = createStorage({
|
||||
driver: fsDriver({
|
||||
base: process.cwd() + '/storage/ddns-agent'
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
export const config = await storage.getItem<CloudflareConfig>('cloudflare.json');
|
||||
|
||||
10
agent/test/get-cf-list.ts
Normal file
10
agent/test/get-cf-list.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { CloudflareDDNS } from "@agent/ddns/cloudflare/index.ts";
|
||||
import { config } from "./common.ts";
|
||||
|
||||
const cf = new CloudflareDDNS();
|
||||
if (config) {
|
||||
const res = await cf.getList(config.zone_id, config.api_token);
|
||||
console.log('Cloudflare DNS Records List:', res);
|
||||
} else {
|
||||
console.log('No configuration found.');
|
||||
}
|
||||
Reference in New Issue
Block a user