mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-14 15:36:52 +03:00
feat: add trojan link support to Proxy Configuration URL validation
This commit is contained in:
@@ -8,3 +8,4 @@ export * from './bulkValidate';
|
||||
export * from './validateShadowsocksUrl';
|
||||
export * from './validateVlessUrl';
|
||||
export * from './validateOutboundJson';
|
||||
export * from './validateTrojanUrl';
|
||||
|
||||
26
fe-app-podkop/src/validators/validateTrojanUrl.ts
Normal file
26
fe-app-podkop/src/validators/validateTrojanUrl.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { ValidationResult } from './types';
|
||||
|
||||
// TODO refactor current validation and add tests
|
||||
export function validateTrojanUrl(url: string): ValidationResult {
|
||||
if (!url.startsWith('trojan://')) {
|
||||
return {
|
||||
valid: false,
|
||||
message: 'Invalid Trojan URL: must start with trojan://',
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const parsedUrl = new URL(url);
|
||||
|
||||
if (!parsedUrl.username || !parsedUrl.hostname || !parsedUrl.port) {
|
||||
return {
|
||||
valid: false,
|
||||
message: 'Invalid Trojan URL: must contain username, hostname and port',
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
return { valid: false, message: 'Invalid Trojan URL: parsing failed' };
|
||||
}
|
||||
|
||||
return { valid: true, message: 'Valid' };
|
||||
}
|
||||
Reference in New Issue
Block a user