mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-14 11:20:53 +08:00
refactor: 规范状态码、抛出异常的使用
This commit is contained in:
@@ -22,10 +22,10 @@ class DeepbworkController extends Controller
|
||||
{
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
throw new ApiException(500, 'token is null');
|
||||
throw new ApiException('token is null');
|
||||
}
|
||||
if ($token !== admin_setting('server_token')) {
|
||||
throw new ApiException(500, 'token is error');
|
||||
throw new ApiException('token is error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class DeepbworkController extends Controller
|
||||
$nodeId = $request->input('node_id');
|
||||
$server = ServerVmess::find($nodeId);
|
||||
if (!$server) {
|
||||
throw new ApiException(500, 'fail');
|
||||
return $this->fail([400,'节点不存在']);
|
||||
}
|
||||
Cache::put(CacheKey::get('SERVER_VMESS_LAST_CHECK_AT', $server->id), time(), 3600);
|
||||
$serverService = new ServerService();
|
||||
@@ -93,15 +93,18 @@ class DeepbworkController extends Controller
|
||||
// 后端获取配置
|
||||
public function config(Request $request)
|
||||
{
|
||||
$nodeId = $request->input('node_id');
|
||||
$localPort = $request->input('local_port');
|
||||
if (empty($nodeId) || empty($localPort)) {
|
||||
throw new ApiException(422, '参数错误');
|
||||
}
|
||||
$request->validate([
|
||||
'node_id' => 'required',
|
||||
'local_port' => 'required'
|
||||
],[
|
||||
'node_id.required' => '节点ID不能为空',
|
||||
'local_port.required' => '本地端口不能为空'
|
||||
]);
|
||||
try {
|
||||
$json = $this->getV2RayConfig($nodeId, $localPort);
|
||||
$json = $this->getV2RayConfig($request->input('node_id'), $request->input('local_port'));
|
||||
} catch (\Exception $e) {
|
||||
throw new ApiException(500, $e->getMessage());
|
||||
\Log::error($e);
|
||||
throw new ApiException($e->getMessage());
|
||||
}
|
||||
|
||||
return(json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
@@ -111,7 +114,7 @@ class DeepbworkController extends Controller
|
||||
{
|
||||
$server = ServerVmess::find($nodeId);
|
||||
if (!$server) {
|
||||
throw new ApiException(500, '节点不存在');
|
||||
return $this->fail([400,'节点不存在']);
|
||||
}
|
||||
$json = json_decode(self::V2RAY_CONFIG);
|
||||
$json->log->loglevel = (int)admin_setting('server_log_enable') ? 'debug' : 'none';
|
||||
|
||||
@@ -21,10 +21,10 @@ class ShadowsocksTidalabController extends Controller
|
||||
{
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
throw new ApiException(500, 'token is null');
|
||||
throw new ApiException('token is null');
|
||||
}
|
||||
if ($token !== admin_setting('server_token')) {
|
||||
throw new ApiException(500, 'token is error');
|
||||
throw new ApiException('token is error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class ShadowsocksTidalabController extends Controller
|
||||
$nodeId = $request->input('node_id');
|
||||
$server = ServerShadowsocks::find($nodeId);
|
||||
if (!$server) {
|
||||
throw new ApiException(500, 'fail');
|
||||
return $this->fail([400,'节点不存在']);
|
||||
}
|
||||
Cache::put(CacheKey::get('SERVER_SHADOWSOCKS_LAST_CHECK_AT', $server->id), time(), 3600);
|
||||
$serverService = new ServerService();
|
||||
|
||||
@@ -22,10 +22,10 @@ class TrojanTidalabController extends Controller
|
||||
{
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
throw new ApiException(500, 'token is null');
|
||||
throw new ApiException('token is null');
|
||||
}
|
||||
if ($token !== admin_setting('server_token')) {
|
||||
throw new ApiException(500, 'token is error');
|
||||
throw new ApiException('token is error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class TrojanTidalabController extends Controller
|
||||
$nodeId = $request->input('node_id');
|
||||
$server = ServerTrojan::find($nodeId);
|
||||
if (!$server) {
|
||||
throw new ApiException(500, 'fail');
|
||||
return $this->fail([400,'节点不存在']);
|
||||
}
|
||||
Cache::put(CacheKey::get('SERVER_TROJAN_LAST_CHECK_AT', $server->id), time(), 3600);
|
||||
$serverService = new ServerService();
|
||||
@@ -89,15 +89,18 @@ class TrojanTidalabController extends Controller
|
||||
// 后端获取配置
|
||||
public function config(Request $request)
|
||||
{
|
||||
$nodeId = $request->input('node_id');
|
||||
$localPort = $request->input('local_port');
|
||||
if (empty($nodeId) || empty($localPort)) {
|
||||
throw new ApiException(422, '参数错误');
|
||||
}
|
||||
$request->validate([
|
||||
'node_id' => 'required',
|
||||
'local_port' => 'required'
|
||||
],[
|
||||
'node_id.required' => '节点ID不能为空',
|
||||
'local_port.required' => '本地端口不能为空'
|
||||
]);
|
||||
try {
|
||||
$json = $this->getTrojanConfig($nodeId, $localPort);
|
||||
$json = $this->getTrojanConfig($request->input('node_id'), $request->input('local_port'));
|
||||
} catch (\Exception $e) {
|
||||
throw new ApiException(500, $e->getMessage());
|
||||
\Log::error($e);
|
||||
return $this->fail([500,'配置获取失败']);
|
||||
}
|
||||
|
||||
return(json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
@@ -107,7 +110,7 @@ class TrojanTidalabController extends Controller
|
||||
{
|
||||
$server = ServerTrojan::find($nodeId);
|
||||
if (!$server) {
|
||||
throw new ApiException(500, '节点不存在');
|
||||
return $this->fail([400, '节点不存在']);
|
||||
}
|
||||
|
||||
$json = json_decode(self::TROJAN_CONFIG);
|
||||
|
||||
@@ -92,9 +92,7 @@ class UniProxyController extends Controller
|
||||
$userService = new UserService();
|
||||
$userService->trafficFetch($this->nodeInfo->toArray(), $this->nodeType, $data , $ip);
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
return $this->success(true);
|
||||
}
|
||||
|
||||
// 后端获取配置
|
||||
@@ -174,8 +172,6 @@ class UniProxyController extends Controller
|
||||
// 后端提交在线数据
|
||||
public function alive(Request $request)
|
||||
{
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
return $this->success(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user