Xboard/app/Http/Controllers/V1/Admin/Server/VmessController.php

80 lines
2.1 KiB
PHP
Raw Normal View History

2023-11-17 01:44:01 -05:00
<?php
namespace App\Http\Controllers\V1\Admin\Server;
2023-12-04 07:40:49 -05:00
use App\Exceptions\ApiException;
2023-11-17 01:44:01 -05:00
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\ServerVmessSave;
use App\Http\Requests\Admin\ServerVmessUpdate;
use App\Models\ServerVmess;
use Illuminate\Http\Request;
class VmessController extends Controller
{
public function save(ServerVmessSave $request)
{
$params = $request->validated();
if ($request->input('id')) {
$server = ServerVmess::find($request->input('id'));
if (!$server) {
return $this->fail([400202, '服务器不存在']);
2023-11-17 01:44:01 -05:00
}
try {
$server->update($params);
} catch (\Exception $e) {
\Log::error($e);
return $this->fail([500, '保存失败']);
2023-11-17 01:44:01 -05:00
}
return $this->success(true);
2023-11-17 01:44:01 -05:00
}
ServerVmess::create($params);
2023-11-17 01:44:01 -05:00
return $this->success(true);
2023-11-17 01:44:01 -05:00
}
public function drop(Request $request)
{
if ($request->input('id')) {
$server = ServerVmess::find($request->input('id'));
if (!$server) {
return $this->fail([400202, '节点不存在']);
2023-11-17 01:44:01 -05:00
}
}
return $this->success($server->delete());
2023-11-17 01:44:01 -05:00
}
public function update(ServerVmessUpdate $request)
{
$params = $request->only([
'show',
]);
$server = ServerVmess::find($request->input('id'));
if (!$server) {
return $this->fail([400202, '该服务器不存在']);
2023-11-17 01:44:01 -05:00
}
try {
$server->update($params);
} catch (\Exception $e) {
\Log::error($e);
return $this->fail([500, '保存失败']);
2023-11-17 01:44:01 -05:00
}
return $this->success(true);
2023-11-17 01:44:01 -05:00
}
public function copy(Request $request)
{
$server = ServerVmess::find($request->input('id'));
$server->show = 0;
if (!$server) {
return $this->fail([400202, '该服务器不存在']);
2023-11-17 01:44:01 -05:00
}
ServerVmess::create($server->toArray());
return $this->success(true);
2023-11-17 01:44:01 -05:00
}
}