diff options
author | Dirk Brenken <dev@brenken.org> | 2023-04-27 13:35:54 +0200 |
---|---|---|
committer | Dirk Brenken <dev@brenken.org> | 2023-04-27 13:35:54 +0200 |
commit | 7ce43d20cb51ff0e002e5fda4267c876bd4a44ce (patch) | |
tree | 1462941c22d271940d6b2672f2e1e418f3ae0100 /applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js | |
parent | ea9e3ad7e802c759f76295909fa0dee3eb76d9df (diff) |
luci-app-banip: more feed editor improvements
* add upload safeguards
* beautify JSON output
* small translation fix
Signed-off-by: Dirk Brenken <dev@brenken.org>
Diffstat (limited to 'applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js')
-rw-r--r-- | applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js index 30fcb9d047..690fa4d1a5 100644 --- a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js +++ b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js @@ -58,8 +58,22 @@ observer.observe(targetNode, observerConfig); function handleEdit(ev) { if (ev === 'upload') { return ui.uploadFile('/etc/banip/banip.custom.feeds').then(function () { - L.resolveDefault(fs.read_direct('/etc/banip/banip.custom.feeds', 'json'), "").then(function (res) { - if (res) { + L.resolveDefault(fs.read_direct('/etc/banip/banip.custom.feeds', 'json'), "").then(function (data) { + if (data) { + let dataLength = Object.keys(data).length || 0; + if (dataLength > 0) { + for (let i = 0; i < dataLength; i++) { + let feed = Object.keys(data)[i]; + let descr = data[feed].descr; + if (feed && descr) { + continue; + } + fs.write('/etc/banip/banip.custom.feeds', null).then(function () { + ui.addNotification(null, E('p', _('Upload of the custom feed file failed.')), 'error'); + }); + return; + } + } location.reload(); } else { fs.write('/etc/banip/banip.custom.feeds', null).then(function () { @@ -131,7 +145,7 @@ function handleEdit(ev) { } sumSubElements.push(nodeKeys[i].value, subElements); } - exportJson = JSON.stringify(sumSubElements).replace(/,{/g, ':{').replace(/^\[/, '{').replace(/\]$/, '}'); + exportJson = JSON.stringify(sumSubElements).replace(/^\[/, '{\n').replace(/\}]$/, '\n\t}\n}\n').replace(/,{"/g, ':{\n\t"').replace(/"},"/g, '"\n\t},\n"').replace(/","/g, '",\n\t"'); return fs.write('/etc/banip/banip.custom.feeds', exportJson).then(function () { location.reload(); }); @@ -145,7 +159,7 @@ return view.extend({ render: function (data) { let m, s, o, feed, url_4, url_6, rule_4, rule_6, descr, flag; - m = new form.JSONMap(data, 'Custom Feed Editor', _('With this editor you can upload your local custom feed file or fill up an initial one (a 1:1 copy of the version shipped with the package). \ + m = new form.JSONMap(data, _('Custom Feed Editor'), _('With this editor you can upload your local custom feed file or fill up an initial one (a 1:1 copy of the version shipped with the package). \ The file is located at \'/etc/banip/banip.custom.feeds\'. \ Then you can edit this file, delete entries, add new ones or make a local backup. To go back to the maintainers version just empty the custom feed file again (do not delete it!).')); for (let i = 0; i < Object.keys(m.data.data).length; i++) { |