2017-11-05 16:16:27 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
module.exports.create = function (opts) {
|
|
|
|
// opts = { filepath };
|
|
|
|
var engine = { db: null };
|
|
|
|
|
|
|
|
var db = require(opts.filepath);
|
|
|
|
|
|
|
|
engine.primaryNameservers = db.primaryNameservers;
|
2018-01-10 08:14:05 +00:00
|
|
|
engine.zones = {
|
|
|
|
all: function (query, cb) {
|
|
|
|
process.nextTick(function () {
|
|
|
|
cb(null, db.domains.slice(0));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
, get: function (query, cb) {
|
|
|
|
var myDomains = db.domains.filter(function (d) {
|
|
|
|
return -1 !== query.names.indexOf(d.id.toLowerCase());
|
|
|
|
});
|
|
|
|
process.nextTick(function () {
|
|
|
|
cb(null, myDomains);
|
|
|
|
});
|
|
|
|
}
|
2017-11-05 16:16:27 +00:00
|
|
|
};
|
2018-01-10 08:14:05 +00:00
|
|
|
engine.records = {
|
|
|
|
all: function (query, cb) {
|
|
|
|
process.nextTick(function () {
|
|
|
|
cb(null, db.records.slice(0));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
, get: function (query, cb) {
|
|
|
|
var myRecords = db.records.slice(0).filter(function (r) {
|
2017-11-05 16:16:27 +00:00
|
|
|
|
2018-01-10 08:14:05 +00:00
|
|
|
if ('string' !== typeof r.name) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-11-05 16:16:27 +00:00
|
|
|
|
2018-01-10 08:14:05 +00:00
|
|
|
// TODO use IN in masterquest (or implement OR)
|
|
|
|
// Only return single-level wildcard?
|
|
|
|
if (query.name === r.name || ('*.' + query.name.split('.').slice(1).join('.')) === r.name) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
process.nextTick(function () {
|
|
|
|
cb(null, myRecords);
|
|
|
|
});
|
|
|
|
}
|
2017-11-05 16:16:27 +00:00
|
|
|
};
|
2018-01-10 08:14:05 +00:00
|
|
|
engine.getSoas = engine.zones.get;
|
|
|
|
engine.getRecords = engine.records.get;
|
2017-11-05 16:16:27 +00:00
|
|
|
|
|
|
|
return engine;
|
|
|
|
};
|