mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-09 21:17:03 +03:00
♻️ refactor(podkop): move URL validation to config.js
This commit is contained in:
@@ -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
|
|
||||||
});
|
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
'require form';
|
'require form';
|
||||||
'require baseclass';
|
'require baseclass';
|
||||||
'require view.podkop.constants as constants';
|
'require view.podkop.constants as constants';
|
||||||
'require view.podkop.networkUtils as networkUtils';
|
|
||||||
'require tools.widgets as widgets';
|
'require tools.widgets as widgets';
|
||||||
|
|
||||||
function createAdditionalSection(mainSection, network) {
|
function createAdditionalSection(mainSection, network) {
|
||||||
|
|||||||
@@ -4,9 +4,20 @@
|
|||||||
'require ui';
|
'require ui';
|
||||||
'require network';
|
'require network';
|
||||||
'require view.podkop.constants as constants';
|
'require view.podkop.constants as constants';
|
||||||
'require view.podkop.networkUtils as networkUtils';
|
|
||||||
'require tools.widgets as widgets';
|
'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) {
|
function createConfigSection(section, map, network) {
|
||||||
const s = section;
|
const s = section;
|
||||||
|
|
||||||
@@ -389,7 +400,7 @@ function createConfigSection(section, map, network) {
|
|||||||
o.ucisection = s.section;
|
o.ucisection = s.section;
|
||||||
o.validate = function (section_id, value) {
|
o.validate = function (section_id, value) {
|
||||||
if (!value || value.length === 0) return true;
|
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'));
|
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.ucisection = s.section;
|
||||||
o.validate = function (section_id, value) {
|
o.validate = function (section_id, value) {
|
||||||
if (!value || value.length === 0) return true;
|
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'));
|
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'));
|
||||||
|
|||||||
Reference in New Issue
Block a user