From 10f246ea61efb6afbf43324f124a9dca3afff87d Mon Sep 17 00:00:00 2001 From: Ivan K Date: Fri, 16 May 2025 23:30:23 +0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(podkop):=20move?= =?UTF-8?q?=20URL=20validation=20to=20config.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/view/podkop/networkUtils.js | 18 ------------------ .../view/podkop/sections/additional.js | 1 - .../resources/view/podkop/sections/config.js | 17 ++++++++++++++--- 3 files changed, 14 insertions(+), 22 deletions(-) delete mode 100644 luci-app-podkop/htdocs/luci-static/resources/view/podkop/networkUtils.js diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/networkUtils.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/networkUtils.js deleted file mode 100644 index e90f662..0000000 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/networkUtils.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; -'require baseclass'; - -function validateUrl(url, protocols = ['http:', 'https:']) { - try { - const parsedUrl = new URL(url); - if (!protocols.includes(parsedUrl.protocol)) { - return _('URL must use one of the following protocols: ') + protocols.join(', '); - } - return true; - } catch (e) { - return _('Invalid URL format'); - } -} - -return baseclass.extend({ - validateUrl -}); \ No newline at end of file diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/additional.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/additional.js index cca414a..c285518 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/additional.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/additional.js @@ -2,7 +2,6 @@ 'require form'; 'require baseclass'; 'require view.podkop.constants as constants'; -'require view.podkop.networkUtils as networkUtils'; 'require tools.widgets as widgets'; function createAdditionalSection(mainSection, network) { diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/config.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/config.js index 54ba6f1..b0d45c9 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/config.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/sections/config.js @@ -4,9 +4,20 @@ 'require ui'; 'require network'; 'require view.podkop.constants as constants'; -'require view.podkop.networkUtils as networkUtils'; 'require tools.widgets as widgets'; +function validateUrl(url, protocols = ['http:', 'https:']) { + try { + const parsedUrl = new URL(url); + if (!protocols.includes(parsedUrl.protocol)) { + return _('URL must use one of the following protocols: ') + protocols.join(', '); + } + return true; + } catch (e) { + return _('Invalid URL format'); + } +} + function createConfigSection(section, map, network) { const s = section; @@ -389,7 +400,7 @@ function createConfigSection(section, map, network) { o.ucisection = s.section; o.validate = function (section_id, value) { if (!value || value.length === 0) return true; - return networkUtils.validateUrl(value); + return validateUrl(value); }; o = s.taboption('basic', form.ListValue, 'custom_subnets_list_enabled', _('User Subnet List Type'), _('Select how to add your custom subnets')); @@ -491,7 +502,7 @@ function createConfigSection(section, map, network) { o.ucisection = s.section; o.validate = function (section_id, value) { if (!value || value.length === 0) return true; - return networkUtils.validateUrl(value); + return validateUrl(value); }; o = s.taboption('basic', form.Flag, 'all_traffic_from_ip_enabled', _('IP for full redirection'), _('Specify local IP addresses whose traffic will always use the configured route'));