This commit is contained in:
parent
ccee8ae5da
commit
d16f8c3d8a
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nodename-core",
|
"name": "nodename-core",
|
||||||
"version": "0.2.0",
|
"version": "0.3.0",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
||||||
|
20
src/core.ts
20
src/core.ts
@ -26,7 +26,7 @@ export interface Plugin {
|
|||||||
* The lower the value, the higher priority.
|
* The lower the value, the higher priority.
|
||||||
* It is recommended to make this value changeable over the cosntructor options field.
|
* It is recommended to make this value changeable over the cosntructor options field.
|
||||||
*/
|
*/
|
||||||
Priority: number
|
priority: number
|
||||||
|
|
||||||
init(core: DnsCore): Promise<void>
|
init(core: DnsCore): Promise<void>
|
||||||
}
|
}
|
||||||
@ -82,12 +82,12 @@ export interface StoragePlugin extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* Here you can define wich record types this storage plugin is capable of.
|
* Here you can define wich record types this storage plugin is capable of.
|
||||||
*/
|
*/
|
||||||
RecordTypes: RecordTypes[]
|
record_types: RecordTypes[]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disables record caching for this Storage
|
* Disables record caching for this Storage
|
||||||
*/
|
*/
|
||||||
NoCache: boolean;
|
no_cache: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if storage plugin is responsible for this domain.
|
* Returns if storage plugin is responsible for this domain.
|
||||||
@ -138,13 +138,13 @@ export class StorageManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private presort() {
|
private presort() {
|
||||||
this._storages = this._storages.sort((e1, e2) => e1.Priority - e2.Priority)
|
this._storages = this._storages.sort((e1, e2) => e1.priority - e2.priority)
|
||||||
this._sorted = <any>{}
|
this._sorted = <any>{}
|
||||||
for (let key in RecordTypes) {
|
for (let key in RecordTypes) {
|
||||||
let key_n = Number(key)
|
let key_n = Number(key)
|
||||||
if (key_n !== Number.NaN) {
|
if (key_n !== Number.NaN) {
|
||||||
//The _storages list is sorted with priority.
|
//The _storages list is sorted with priority.
|
||||||
this._sorted[key_n] = this._storages.filter(e => e.RecordTypes.find(t => t === key_n) !== undefined)
|
this._sorted[key_n] = this._storages.filter(e => e.record_types.find(t => t === key_n) !== undefined)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,10 +169,10 @@ export class StorageManager {
|
|||||||
|
|
||||||
let nocache = false;
|
let nocache = false;
|
||||||
for (let storage of storages) {
|
for (let storage of storages) {
|
||||||
nocache = storage.NoCache || nocache;
|
nocache = storage.no_cache || nocache;
|
||||||
records = await storage.getRecords(domain, hostname, type)
|
records = await storage.getRecords(domain, hostname, type)
|
||||||
if (records) {
|
if (records) {
|
||||||
if (storage.NoCache) this._cache.addRecords(domain, hostname, type, records, records.length <= 0 ? 3600 : records[0].ttl)
|
if (storage.no_cache) this._cache.addRecords(domain, hostname, type, records, records.length <= 0 ? 3600 : records[0].ttl)
|
||||||
return records;
|
return records;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -197,7 +197,7 @@ export interface QuestionPlugin extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* This field defines wich question types this plugin is capable of handling.
|
* This field defines wich question types this plugin is capable of handling.
|
||||||
*/
|
*/
|
||||||
QuestionTypes: RecordTypes[];
|
question_types: RecordTypes[];
|
||||||
init(core: DnsCore): Promise<void>
|
init(core: DnsCore): Promise<void>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -219,12 +219,12 @@ export class QuestionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private sort() {
|
private sort() {
|
||||||
this._questions = this._questions.sort((e1, e2) => e1.Priority - e2.Priority);
|
this._questions = this._questions.sort((e1, e2) => e1.priority - e2.priority);
|
||||||
this._sorted = {};
|
this._sorted = {};
|
||||||
for (let key in RecordTypes) {
|
for (let key in RecordTypes) {
|
||||||
let key_n = Number(key)
|
let key_n = Number(key)
|
||||||
if (key_n !== Number.NaN) {
|
if (key_n !== Number.NaN) {
|
||||||
this._sorted[key_n] = this._questions.filter(e => e.QuestionTypes.find(t => t === key_n) !== undefined)
|
this._sorted[key_n] = this._questions.filter(e => e.question_types.find(t => t === key_n) !== undefined)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user