feat: api tokens + deploy webhook
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
<?php
|
||||
|
||||
use App\Actions\Database\StartPostgresql;
|
||||
use App\Models\Application;
|
||||
use App\Models\Service;
|
||||
use App\Models\StandaloneMongodb;
|
||||
use App\Models\StandalonePostgresql;
|
||||
use App\Models\StandaloneRedis;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Visus\Cuid2\Cuid2;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -17,9 +25,46 @@ use Illuminate\Support\Facades\Route;
|
||||
Route::get('/health', function () {
|
||||
return 'OK';
|
||||
});
|
||||
Route::group([
|
||||
'middleware' => ['auth:sanctum'],
|
||||
'prefix' => 'v1'
|
||||
], function () {
|
||||
Route::get('/deploy', function (Request $request) {
|
||||
$token = auth()->user()->currentAccessToken();
|
||||
$teamId = data_get($token, 'team_id');
|
||||
$uuid = $request->query->get('uuid');
|
||||
$force = $request->query->get('force') ?? false;
|
||||
|
||||
if (is_null($teamId)) {
|
||||
return response()->json(['error' => 'Invalid token.'], 400);
|
||||
}
|
||||
if (!$uuid) {
|
||||
return response()->json(['error' => 'No UUID provided.'], 400);
|
||||
}
|
||||
$resource = getResourceByUuid($uuid, $teamId);
|
||||
if ($resource) {
|
||||
$type = $resource->getMorphClass();
|
||||
if ($type === 'App\Models\Application') {
|
||||
queue_application_deployment(
|
||||
application_id: $resource->id,
|
||||
deployment_uuid: new Cuid2(7),
|
||||
force_rebuild: $force,
|
||||
);
|
||||
return response()->json(['message' => 'Deployment queued.'], 200);
|
||||
} else if ($type === 'App\Models\StandalonePostgresql') {
|
||||
StartPostgresql::run($resource);
|
||||
$resource->update([
|
||||
'started_at' => now(),
|
||||
]);
|
||||
return response()->json(['message' => 'Database started.'], 200);
|
||||
}
|
||||
}
|
||||
return response()->json(['error' => 'No resource found.'], 404);
|
||||
});
|
||||
});
|
||||
|
||||
Route::middleware(['throttle:5'])->group(function () {
|
||||
Route::get('/unsubscribe/{token}', function() {
|
||||
Route::get('/unsubscribe/{token}', function () {
|
||||
try {
|
||||
$token = request()->token;
|
||||
$email = decrypt($token);
|
||||
@@ -34,6 +79,5 @@ Route::middleware(['throttle:5'])->group(function () {
|
||||
} catch (\Throwable $e) {
|
||||
return 'Something went wrong. Please try again or contact support.';
|
||||
}
|
||||
|
||||
})->name('unsubscribe.marketing.emails');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user