UNPKG

wm-ddns

Version:

简单的 DNS 修改 Record 的包。 [https://DNSpod.cn](https://DNSpod.cn)。支持 callback & Promise & async/await。

148 lines (147 loc) 5.26 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); /** * Created by maple on 2018/1/10. */ const RecordType_1 = __importDefault(require("./enums/RecordType")); class DnsPodRecord { constructor(domain, data) { this.id = 0; this.name = ''; this.line = undefined; this.type = RecordType_1.default.A; this.ttl = undefined; this.weight = undefined; this.mx = undefined; this.enabled = undefined; this.status = undefined; this.monitorStatus = undefined; this.remark = undefined; this.updatedOn = undefined; this.useApd = undefined; this.deleteStatus = false; this.domain = domain; data.monitorStatus = data.monitorStatus !== undefined ? data.monitorStatus : data.monitor_status; data.updateOn = data.updateOn !== undefined ? data.updateOn : data.update_on; data.useApd = data.useApd !== undefined ? data.useApd : data.use_apd; const record = data; this.raw = record; this.initByRaw(record); } initByRaw(record) { this.raw = record; this.id = record.id; this.name = record.name; this.line = record.line; this.type = record.type; this.ttl = record.ttl; this.value = record.value; this.weight = record.weight; this.mx = record.mx; this.enabled = record.enabled; this.status = record.status; this.monitorStatus = record.monitorStatus; this.remark = record.remark; this.updatedOn = record.updatedOn; this.useApd = record.useApd; } toJSON() { return Object.assign({ domain: this.domain.toJSON() }, this.raw); } getRaw() { return this.raw; } getId() { return this.id; } getName() { return this.name; } getType() { return this.type; } getTypeAsString() { return this.type.toString(); } sync() { return __awaiter(this, void 0, void 0, function* () { const recordId = this.id; if (recordId === undefined) { throw new Error('recordId can\'t be empty'); } const newRecord = yield this.domain.recordById(recordId); this.initByRaw(newRecord.getRaw()); }); } update(options) { return __awaiter(this, void 0, void 0, function* () { if (this.deleteStatus) { throw new Error('record has already removed'); } const _options = Object.assign(Object.assign({ recordType: this.type }, options), { id: this.id }); yield this.domain.updateRecord(_options); yield this.sync(); }); } dns(options) { return __awaiter(this, void 0, void 0, function* () { if (this.deleteStatus) { throw new Error('record has already removed'); } yield this.domain.dns(Object.assign(Object.assign({}, options), { id: this.id })); yield this.sync(); }); } ddns() { return __awaiter(this, void 0, void 0, function* () { if (this.deleteStatus) { throw new Error('record has already removed'); } const ip = yield this.domain.getGetIpFunction()(); yield this.domain.dns({ id: this.id, value: ip }); yield this.sync(); }); } setRemark(remark) { return __awaiter(this, void 0, void 0, function* () { if (this.deleteStatus) { throw new Error('record has already removed'); } yield this.domain.remark(this.id, remark); yield this.sync(); }); } setStatus(status) { return __awaiter(this, void 0, void 0, function* () { if (this.deleteStatus) { throw new Error('record has already removed'); } yield this.domain.setStatus(this.id, status); yield this.sync(); }); } delete() { return __awaiter(this, void 0, void 0, function* () { if (this.deleteStatus) { throw new Error('record has already removed'); } return yield this.domain.removeRecord(this.id); }); } } exports.default = DnsPodRecord;