v2board/app/Http/Controllers/Admin/Server/V2rayController.php

93 lines
2.2 KiB
PHP
Raw Normal View History

2020-06-11 20:47:02 +08:00
<?php
namespace App\Http\Controllers\Admin\Server;
use App\Http\Requests\Admin\ServerV2raySave;
use App\Http\Requests\Admin\ServerV2rayUpdate;
use App\Services\ServerService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
2021-09-21 18:07:53 +08:00
use App\Models\ServerV2ray;
2020-06-11 20:47:02 +08:00
class V2rayController extends Controller
{
public function save(ServerV2raySave $request)
{
2020-07-15 15:57:12 +08:00
$params = $request->validated();
2020-06-11 20:47:02 +08:00
if ($request->input('id')) {
2021-09-21 18:07:53 +08:00
$server = ServerV2ray::find($request->input('id'));
2020-06-11 20:47:02 +08:00
if (!$server) {
abort(500, '服务器不存在');
}
try {
$server->update($params);
} catch (\Exception $e) {
abort(500, '保存失败');
}
return response([
'data' => true
]);
}
2021-09-21 18:07:53 +08:00
if (!ServerV2ray::create($params)) {
2020-06-11 20:47:02 +08:00
abort(500, '创建失败');
}
return response([
'data' => true
]);
}
public function drop(Request $request)
{
if ($request->input('id')) {
2021-09-21 18:07:53 +08:00
$server = ServerV2ray::find($request->input('id'));
2020-06-11 20:47:02 +08:00
if (!$server) {
abort(500, '节点ID不存在');
}
}
return response([
'data' => $server->delete()
]);
}
public function update(ServerV2rayUpdate $request)
{
$params = $request->only([
'show',
]);
2021-09-21 18:07:53 +08:00
$server = ServerV2ray::find($request->input('id'));
2020-06-11 20:47:02 +08:00
if (!$server) {
abort(500, '该服务器不存在');
}
try {
$server->update($params);
} catch (\Exception $e) {
abort(500, '保存失败');
}
return response([
'data' => true
]);
}
public function copy(Request $request)
{
2021-09-21 18:07:53 +08:00
$server = ServerV2ray::find($request->input('id'));
2020-06-18 17:39:29 +08:00
$server->show = 0;
2020-06-11 20:47:02 +08:00
if (!$server) {
abort(500, '服务器不存在');
}
2021-09-21 18:07:53 +08:00
if (!ServerV2ray::create($server->toArray())) {
2020-06-11 20:47:02 +08:00
abort(500, '复制失败');
}
return response([
'data' => true
]);
}
}