-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReceiveBundleController.php
More file actions
48 lines (39 loc) · 1.33 KB
/
ReceiveBundleController.php
File metadata and controls
48 lines (39 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace App\Http\Controllers\Guest;
use App\Models\PendingClientResponse;
use App\Models\Server;
use Illuminate\Http\Request;
class ReceiveBundleController
{
public function post(Request $request)
{
if ($request->bearerToken() !== config('watchtower.client_auth_token')) {
abort(401);
}
['server_uuid' => $serverUuid, 'bundle' => $bundle] = $request->validate([
'server_uuid' => 'required|uuid',
'bundle' => 'required|file',
]);
Server::receiveBundle($bundle->getRealPath());
$responses = PendingClientResponse::query()
->select(['id', 'message'])
->where('server_uuid', $serverUuid)
->get();
if ($responses->isNotEmpty()) {
PendingClientResponse::query()
->whereIn('id', $responses->pluck('id'))
->delete();
}
return implode("\n", [
'Acknowledged!',
'Current-client-version: '.sha1_file(public_path('watchtower-client.tar.gz')),
...$responses->map(fn (PendingClientResponse $response) => $response->message),
]);
}
public function isAvailable(Request $request)
{
if ($request->bearerToken() !== config('watchtower.client_auth_token')) {
abort(401);
}
}
}