refactor: migrate Outbound Configuration validation to modular

This commit is contained in:
divocat
2025-10-03 03:26:02 +03:00
parent 65d3a9253f
commit 8f9bff9a64
10 changed files with 55 additions and 15 deletions

View File

@@ -124,16 +124,18 @@ function createConfigSection(section, map, network) {
o.rows = 10;
o.ucisection = s.section;
o.validate = function (section_id, value) {
if (!value || value.length === 0) return true;
try {
const parsed = JSON.parse(value);
if (!parsed.type || !parsed.server || !parsed.server_port) {
return _('JSON must contain at least type, server and server_port fields');
}
return true;
} catch (e) {
return _('Invalid JSON format');
// Optional
if (!value || value.length === 0) {
return true
}
const validation = main.validateOutboundJson(value);
if (validation.valid) {
return true;
}
return _(validation.message)
};
o = s.taboption('basic', form.DynamicList, 'urltest_proxy_links', _('URLTest Proxy Links'));

View File

@@ -261,6 +261,22 @@ function validateVlessUrl(url) {
return { valid: true, message: "Valid" };
}
// src/validators/validateOutboundJson.ts
function validateOutboundJson(value) {
try {
const parsed = JSON.parse(value);
if (!parsed.type || !parsed.server || !parsed.server_port) {
return {
valid: false,
message: 'Outbound JSON must contain at least "type", "server" and "server_port" fields'
};
}
return { valid: true, message: "Valid" };
} catch {
return { valid: false, message: "Invalid JSON format" };
}
}
// src/helpers/getBaseUrl.ts
function getBaseUrl() {
const { protocol, hostname } = window.location;
@@ -405,6 +421,7 @@ return baseclass.extend({
validateDNS,
validateDomain,
validateIPV4,
validateOutboundJson,
validatePath,
validateShadowsocksUrl,
validateSubnet,