wm-ddns
Version:
简单的 DNS 修改 Record 的包。 [https://DNSpod.cn](https://DNSpod.cn)。支持 callback & Promise & async/await。
118 lines (117 loc) • 3.79 kB
JavaScript
"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 });
const RecordType_1 = __importDefault(require("./enums/RecordType"));
class DNSRecord {
constructor(domain, data, client) {
this.id = 0;
this.name = '';
this.type = RecordType_1.default.A;
this.deleteStatus = false;
this.domain = domain;
this.raw = data;
this.updateByRaw(data);
}
/**
* 更新 record 的属性
* @param record
*/
updateByRaw(record) {
this.id = record.id;
this.name = record.name;
this.value = record.value;
// 覆盖参数
Object.assign(this.raw, record);
}
/**
* 设置 delete 状态
*/
setDeleteStatus() {
this.deleteStatus = true;
}
/**
* 是否被删除
*/
isDeleted() {
return this.deleteStatus;
}
getRaw() {
return this.raw;
}
getDomainRaw() {
return this.domain.getRaw();
}
getId() {
return this.id;
}
getName() {
return this.name;
}
getType() {
return this.type;
}
getTypeAsString() {
return this.type.toString();
}
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);
});
}
dns(value) {
return __awaiter(this, void 0, void 0, function* () {
if (this.deleteStatus) {
throw new Error('record has already removed');
}
yield this.domain.ddns("record", this);
});
}
ddns() {
return __awaiter(this, void 0, void 0, function* () {
if (this.deleteStatus) {
throw new Error('record has already removed');
}
yield this.domain.ddns("record", this);
});
}
setRemark(remark) {
return __awaiter(this, void 0, void 0, function* () {
if (this.deleteStatus) {
throw new Error('record has already removed');
}
yield this.domain.setRemark("record", this, remark);
});
}
setStatus(status) {
return __awaiter(this, void 0, void 0, function* () {
if (this.deleteStatus) {
throw new Error('record has already removed');
}
yield this.domain.setStatus("record", this, status);
});
}
delete() {
return __awaiter(this, void 0, void 0, function* () {
if (this.deleteStatus) {
throw new Error('record has already removed');
}
yield this.domain.deleteRecord("record", this);
});
}
}
exports.default = DNSRecord;