22
33namespace App \Http \Controllers ;
44
5+ use App \Actions \Server \ClearServiceLog ;
6+ use App \Actions \Server \DownloadServiceLog ;
7+ use App \Actions \Server \GetServiceLogs ;
8+ use App \Actions \Server \ReadServiceLog ;
59use App \Actions \ServerLog \CreateLog ;
610use App \Actions \ServerLog \UpdateLog ;
11+ use App \DTOs \ServiceLog ;
712use App \Helpers \QueryBuilder ;
813use App \Http \Resources \ServerLogResource ;
914use App \Models \Server ;
1015use App \Models \ServerLog ;
1116use App \Models \Site ;
17+ use Illuminate \Http \JsonResponse ;
1218use Illuminate \Http \RedirectResponse ;
1319use Illuminate \Http \Request ;
1420use Illuminate \Http \Resources \Json \ResourceCollection ;
@@ -50,7 +56,7 @@ public function remote(Server $server): Response
5056 $ this ->authorize ('viewAny ' , [ServerLog::class, $ server ]);
5157
5258 return Inertia::render ('server-logs/index ' , [
53- 'title ' => 'Remote logs ' ,
59+ 'title ' => 'Custom logs ' ,
5460 'logs ' => ServerLogResource::collection ($ server ->logs ()->where ('is_remote ' , 1 )->latest ()->simplePaginate (config ('web.pagination_size ' ))),
5561 'remote ' => true ,
5662 ]);
@@ -69,6 +75,56 @@ public function json(Request $request, Server $server, ?Site $site = null): Reso
6975 return ServerLogResource::collection ($ logs );
7076 }
7177
78+ #[Get('/services ' , name: 'logs.services ' )]
79+ public function services (Server $ server ): Response
80+ {
81+ $ this ->authorize ('viewAny ' , [ServerLog::class, $ server ]);
82+
83+ $ catalogue = array_map (
84+ fn (ServiceLog $ log ): array => [
85+ 'key ' => $ log ->key ,
86+ 'service_label ' => $ log ->serviceLabel ,
87+ 'label ' => $ log ->label ,
88+ 'display_target ' => $ log ->displayTarget (),
89+ 'source ' => $ log ->source ,
90+ ],
91+ app (GetServiceLogs::class)->handle ($ server ),
92+ );
93+
94+ return Inertia::render ('server-logs/services ' , [
95+ 'title ' => 'Service logs ' ,
96+ 'catalogue ' => $ catalogue ,
97+ ]);
98+ }
99+
100+ #[Post('/services/read ' , name: 'logs.services.read ' )]
101+ public function readServiceLog (Request $ request , Server $ server ): JsonResponse
102+ {
103+ $ this ->authorize ('viewAny ' , [ServerLog::class, $ server ]);
104+
105+ return response ()->json (
106+ app (ReadServiceLog::class)->run ($ server , $ request ->only ('key ' , 'lines ' , 'search ' )),
107+ );
108+ }
109+
110+ #[Get('/services/download ' , name: 'logs.services.download ' )]
111+ public function downloadServiceLog (Request $ request , Server $ server ): StreamedResponse
112+ {
113+ $ this ->authorize ('viewAny ' , [ServerLog::class, $ server ]);
114+
115+ return app (DownloadServiceLog::class)->run ($ server , $ request ->only ('key ' ));
116+ }
117+
118+ #[Post('/services/clear ' , name: 'logs.services.clear ' )]
119+ public function clearServiceLog (Request $ request , Server $ server ): RedirectResponse
120+ {
121+ $ this ->authorize ('deleteMany ' , [ServerLog::class, $ server ]);
122+
123+ app (ClearServiceLog::class)->run ($ server , $ request ->only ('key ' ));
124+
125+ return back ()->with ('success ' , 'Log cleared successfully ' );
126+ }
127+
72128 #[Get('/{log} ' , name: 'logs.show ' )]
73129 public function show (Server $ server , ServerLog $ log ): string
74130 {
0 commit comments