mirror of
https://github.com/itdoginfo/podkop.git
synced 2026-05-14 00:41:10 +03:00
32 lines
836 B
TypeScript
32 lines
836 B
TypeScript
import { ValidationResult } from './types';
|
|
import { validateShadowsocksUrl } from './validateShadowsocksUrl';
|
|
import { validateVlessUrl } from './validateVlessUrl';
|
|
import { validateTrojanUrl } from './validateTrojanUrl';
|
|
import { validateSocksUrl } from './validateSocksUrl';
|
|
|
|
// TODO refactor current validation and add tests
|
|
export function validateProxyUrl(url: string): ValidationResult {
|
|
if (url.startsWith('ss://')) {
|
|
return validateShadowsocksUrl(url);
|
|
}
|
|
|
|
if (url.startsWith('vless://')) {
|
|
return validateVlessUrl(url);
|
|
}
|
|
|
|
if (url.startsWith('trojan://')) {
|
|
return validateTrojanUrl(url);
|
|
}
|
|
|
|
if (/^socks(4|4a|5):\/\//.test(url)) {
|
|
return validateSocksUrl(url);
|
|
}
|
|
|
|
return {
|
|
valid: false,
|
|
message: _(
|
|
'URL must start with vless://, ss://, trojan://, or socks4/5://',
|
|
),
|
|
};
|
|
}
|