mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-12 23:48:53 +00:00
🚀 Refactor Blade
- Optimize Blade JavaScript code. - Refactored multiple admin controllers for improved validation, error handling, and query efficiency. - Added ProxyConfig trait to centralize proxy configuration options. - Updated NodeStatusDetection to use model relationships for heartbeat checks. - Improved category, label, and country management logic and error logging. - Added new Blade components for admin UI and updated language files and assets for better localization and frontend support. - Bug fixed & introduced more bug :)
This commit is contained in:
@@ -5,29 +5,40 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Node;
|
||||
use App\Models\NodeAuth;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Log;
|
||||
use Str;
|
||||
|
||||
class NodeAuthController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{ // 节点授权列表
|
||||
return view('admin.node.auth', ['authorizations' => NodeAuth::with('node:id,name,type,server,ip,ipv6')->has('node')->orderBy('node_id')->paginate()->appends(request('page'))]);
|
||||
$authorizations = NodeAuth::with(['node:id,name,type,server,ip,ipv6'])
|
||||
->orderBy('node_id')
|
||||
->paginate()
|
||||
->appends(request('page'));
|
||||
|
||||
return view('admin.node.auth', compact('authorizations'));
|
||||
}
|
||||
|
||||
public function store(): JsonResponse
|
||||
{ // 添加节点授权
|
||||
$nodes = Node::whereStatus(1)->doesntHave('auth')->orderBy('id')->get();
|
||||
$nodes = Node::whereStatus(1)->doesntHave('auth')->pluck('id');
|
||||
|
||||
if ($nodes->isEmpty()) {
|
||||
return response()->json(['status' => 'success', 'message' => trans('admin.node.auth.empty')]);
|
||||
}
|
||||
$nodes->each(function ($node) {
|
||||
$node->auth()->create(['key' => Str::random(), 'secret' => Str::random(8)]);
|
||||
});
|
||||
|
||||
$authData = [];
|
||||
foreach ($nodes as $node_id) {
|
||||
$authData[] = [
|
||||
'node_id' => $node_id,
|
||||
'key' => Str::random(),
|
||||
'secret' => Str::random(8),
|
||||
];
|
||||
}
|
||||
|
||||
NodeAuth::insert($authData);
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => trans('common.success_item', ['attribute' => trans('common.generate')])]);
|
||||
}
|
||||
@@ -43,14 +54,8 @@ class NodeAuthController extends Controller
|
||||
|
||||
public function destroy(NodeAuth $auth): JsonResponse
|
||||
{ // 删除节点授权
|
||||
try {
|
||||
if ($auth->delete()) {
|
||||
return response()->json(['status' => 'success', 'message' => trans('common.success_item', ['attribute' => trans('common.delete')])]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Log::error(trans('common.error_action_item', ['action' => trans('common.delete'), 'attribute' => trans('admin.menu.node.auth')]).': '.$e->getMessage());
|
||||
|
||||
return response()->json(['status' => 'fail', 'message' => trans('common.error_action_item', ['action' => trans('common.delete'), 'attribute' => trans('admin.menu.node.auth')]).', '.$e->getMessage()]);
|
||||
if ($auth->delete()) {
|
||||
return response()->json(['status' => 'success', 'message' => trans('common.success_item', ['attribute' => trans('common.delete')])]);
|
||||
}
|
||||
|
||||
return response()->json(['status' => 'fail', 'message' => trans('common.failed_item', ['attribute' => trans('common.delete')])]);
|
||||
|
||||
Reference in New Issue
Block a user