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
| const axios = require("axios"); const token = process.env.DNSPOD_TOKEN; const querystring = require("querystring");
const instance = axios.create({ baseURL: "https://dnsapi.cn" });
async function get_record(domain, subdomain) { const api = "/Record.List"; const data = querystring.stringify({ "domain": domain, "sub_domain": subdomain, "login_token": token, "format": "json" }); const res = await instance.post(api, data); return res.data.records; }
async function update_record(domain, record) { const {id, line, type, name, value} = record; const api = "/Record.Modify"; const data = querystring.stringify({ domain, record_id: id, value, record_line: line, record_type: type, sub_domain: name, "login_token": token, "format": "json", }); const res = await instance.post(api, data); return res.data; }
async function add_record(domain, record) { const {line, type, name, value} = record; const api = "/Record.Create"; const data = querystring.stringify({ domain, value, record_line: line, record_type: type, sub_domain: name, "login_token": token, "format": "json", }); const res = await instance.post(api, data); return res.data; }
async function del_record(domain, record) { const {id} = record; const api = "/Record.Remove"; const data = querystring.stringify({ domain, record_id: id, "login_token": token, "format": "json", }); const res = await instance.post(api, data); return res.data; }
module.exports = {get_record, update_record, add_record, del_record};
|