mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-06 11:36:50 +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 baseclass';
|
||||
'require view.podkop.constants as constants';
|
||||
'require view.podkop.networkUtils as networkUtils';
|
||||
'require tools.widgets as widgets';
|
||||
|
||||
function createAdditionalSection(mainSection, network) {
|
||||
|
||||
@@ -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'));
|
||||
|
||||
Reference in New Issue
Block a user