feat: 兼容V2bx 的Hysteria2

This commit is contained in:
xboard 2023-11-19 09:54:40 +08:00
parent b489f8f6f1
commit e0eac8f703
2 changed files with 14 additions and 5 deletions

View File

@ -22,7 +22,7 @@ class UniProxyController extends Controller
{
$this->serverService = $serverService;
$this->nodeId = $request->input('node_id');
$this->nodeType = $request->input('node_type') === 'v2ray' ? 'vmess' : $request->input('node_type');
$this->nodeType = $request->input('node_type');
$this->nodeInfo = $this->serverService->getServer($this->nodeId, $this->nodeType);
if(!$this->nodeInfo) {
Log::channel("daily")->info("$this->nodeId $this->nodeType $this->nodeInfo");

View File

@ -16,22 +16,31 @@ class Server
*/
public function handle(Request $request, Closure $next)
{
// alias
$aliasTypes = [
'v2ray' => 'vmess',
'hysteria2' => 'hysteria'
];
$request->validate([
'token' => ['required','string',function ($attribute, $value, $fail) {
if ($value != admin_setting('server_token')) {
$fail("The $attribute is error.");
}
}],
'node_id' => 'required',
'node_type' => [
'nullable',
'string',
'regex:/^(?i)(hysteria|vless|trojan|vmess|v2ray|tuic|shadowsocks|shadowsocks-plugin)$/',
function ($attribute, $value, $fail) {
'regex:/^(?i)(hysteria|hysteria2|vless|trojan|vmess|v2ray|tuic|shadowsocks|shadowsocks-plugin)$/',
function ($attribute, $value, $fail)use($aliasTypes) {
// 将值转换为小写
request()->merge([$attribute => strtolower($value)]);
// 类别别名
if (in_array($value, array_keys($aliasTypes))){
request()->merge([$attribute => $aliasTypes[$value]]);
}
},
],
'node_id' => 'required'
]
]);
return $next($request);