mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-08 20:46:50 +03:00
refactor: migrate Outbound Configuration validation to modular
This commit is contained in:
@@ -7,3 +7,4 @@ export * from './validateSubnet';
|
|||||||
export * from './bulkValidate';
|
export * from './bulkValidate';
|
||||||
export * from './validateShadowsocksUrl';
|
export * from './validateShadowsocksUrl';
|
||||||
export * from './validateVlessUrl';
|
export * from './validateVlessUrl';
|
||||||
|
export * from './validateOutboundJson';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { validateDomain } from './validateDomain';
|
import { validateDomain } from './validateDomain';
|
||||||
import { validateIPV4 } from './validateIp';
|
import { validateIPV4 } from './validateIp';
|
||||||
import { ValidationResult } from './types.js';
|
import { ValidationResult } from './types';
|
||||||
|
|
||||||
export function validateDNS(value: string): ValidationResult {
|
export function validateDNS(value: string): ValidationResult {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ValidationResult } from './types.js';
|
import { ValidationResult } from './types';
|
||||||
|
|
||||||
export function validateDomain(domain: string): ValidationResult {
|
export function validateDomain(domain: string): ValidationResult {
|
||||||
const domainRegex =
|
const domainRegex =
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ValidationResult } from './types.js';
|
import { ValidationResult } from './types';
|
||||||
|
|
||||||
export function validateIPV4(ip: string): ValidationResult {
|
export function validateIPV4(ip: string): ValidationResult {
|
||||||
const ipRegex =
|
const ipRegex =
|
||||||
|
|||||||
20
fe-app-podkop/src/validators/validateOutboundJson.ts
Normal file
20
fe-app-podkop/src/validators/validateOutboundJson.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { ValidationResult } from './types';
|
||||||
|
|
||||||
|
// TODO refactor current validation and add tests
|
||||||
|
export function validateOutboundJson(value: string): ValidationResult {
|
||||||
|
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' };
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ValidationResult } from './types.js';
|
import { ValidationResult } from './types';
|
||||||
|
|
||||||
// TODO refactor current validation and add tests
|
// TODO refactor current validation and add tests
|
||||||
export function validateShadowsocksUrl(url: string): ValidationResult {
|
export function validateShadowsocksUrl(url: string): ValidationResult {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ValidationResult } from './types.js';
|
import { ValidationResult } from './types';
|
||||||
import { validateIPV4 } from './validateIp';
|
import { validateIPV4 } from './validateIp';
|
||||||
|
|
||||||
export function validateSubnet(value: string): ValidationResult {
|
export function validateSubnet(value: string): ValidationResult {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ValidationResult } from './types.js';
|
import { ValidationResult } from './types';
|
||||||
|
|
||||||
export function validateUrl(
|
export function validateUrl(
|
||||||
url: string,
|
url: string,
|
||||||
|
|||||||
@@ -124,16 +124,18 @@ function createConfigSection(section, map, network) {
|
|||||||
o.rows = 10;
|
o.rows = 10;
|
||||||
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;
|
// Optional
|
||||||
try {
|
if (!value || value.length === 0) {
|
||||||
const parsed = JSON.parse(value);
|
return true
|
||||||
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');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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'));
|
o = s.taboption('basic', form.DynamicList, 'urltest_proxy_links', _('URLTest Proxy Links'));
|
||||||
|
|||||||
@@ -261,6 +261,22 @@ function validateVlessUrl(url) {
|
|||||||
return { valid: true, message: "Valid" };
|
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
|
// src/helpers/getBaseUrl.ts
|
||||||
function getBaseUrl() {
|
function getBaseUrl() {
|
||||||
const { protocol, hostname } = window.location;
|
const { protocol, hostname } = window.location;
|
||||||
@@ -405,6 +421,7 @@ return baseclass.extend({
|
|||||||
validateDNS,
|
validateDNS,
|
||||||
validateDomain,
|
validateDomain,
|
||||||
validateIPV4,
|
validateIPV4,
|
||||||
|
validateOutboundJson,
|
||||||
validatePath,
|
validatePath,
|
||||||
validateShadowsocksUrl,
|
validateShadowsocksUrl,
|
||||||
validateSubnet,
|
validateSubnet,
|
||||||
|
|||||||
Reference in New Issue
Block a user