♻️ refactor(podkop): move URL validation to config.js

This commit is contained in:
Ivan K
2025-05-16 23:30:23 +03:00
parent c0571320f1
commit 10f246ea61
3 changed files with 14 additions and 22 deletions

View File

@@ -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
});

View File

@@ -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) {

View File

@@ -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'));