luci-app-https-dns-proxy: bugfixes and resolvers update

* fix templates loading when no template found (thanks @systemcrash!)
* fix redundant checks in view (thanks @systemcrash!)
* fix/update/delete/add resolvers

Signed-off-by: Stan Grishin <stangri@melmac.ca>
This commit is contained in:
Stan Grishin
2024-12-30 03:29:04 +00:00
parent f843014f24
commit e1887f25fe
8 changed files with 114 additions and 242 deletions
@@ -25,21 +25,24 @@ var pkg = {
);
},
templateToRegexp: function (template) {
return RegExp(
"^" +
template
.split(/(\{\w+\})/g)
.map((part) => {
let placeholder = part.match(/^\{(\w+)\}$/);
if (placeholder) return `(?<${placeholder[1]}>.*?)`;
else return part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
})
.join("") +
"$"
);
if (template)
return new RegExp(
"^" +
template
.split(/(\{\w+\})/g)
.map((part) => {
let placeholder = part.match(/^\{(\w+)\}$/);
if (placeholder) return `(?<${placeholder[1]}>.*?)`;
else return part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
})
.join("") +
"$"
);
return new RegExp("");
},
templateToResolver: function (template, args) {
return template.replace(/{(\w+)}/g, (_, v) => args[v]);
if (template) return template.replace(/{(\w+)}/g, (_, v) => args[v]);
return null;
},
};
@@ -157,8 +160,11 @@ var status = baseclass.extend({
force_dns_active: null,
version: null,
},
providers: (data[1] && data[1][pkg.Name]) || { providers: [] },
runtime: (data[2] && data[2][pkg.Name]) || { instances: [] },
providers: (data[1] && data[1][pkg.Name]) || [{ title: "empty" }],
runtime: (data[2] && data[2][pkg.Name]) || {
instances: null,
triggers: [],
},
};
reply.providers.sort(function (a, b) {
return _(a.title).localeCompare(_(b.title));