From: Daniel Karbach Date: Sat, 28 May 2022 12:11:33 +0000 (+0200) Subject: add aos generate api endpoint X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=ca11676f7b9efab82f1cf014f9c34e4b961c0519;p=alttp.git add aos generate api endpoint --- diff --git a/app/Http/Controllers/AosSeedController.php b/app/Http/Controllers/AosSeedController.php index 7c7e5f9..1e2aa73 100644 --- a/app/Http/Controllers/AosSeedController.php +++ b/app/Http/Controllers/AosSeedController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\DiscordAppCommands\AosrPresetCommand; use App\Models\AosSeed; use Illuminate\Http\Request; use Illuminate\Support\Facades\Artisan; @@ -22,6 +23,25 @@ class AosSeedController extends Controller return $seed->toJson(); } + public function generate(Request $request) { + $validatedData = $request->validate([ + 'preset' => 'string|required', + 'race' => 'boolean', + ]); + $presetName = $validatedData['preset']; + $race = $validatedData['race'] ?? false; + + if (!isset(AosrPresetCommand::$presets[$presetName])) { + abort(404); + } + $preset = AosrPresetCommand::$presets[$presetName]; + $seed = AosSeed::generateSurge($presetName, $preset['settings'], $race); + Artisan::call('aos:generate '.intval($seed->id)); + + $seed = $this->censor($seed->fresh()); + return $seed->toJson(); + } + public function retry($hash) { $seed = AosSeed::where('hash', '=', $hash)->firstOrFail(); @@ -31,7 +51,18 @@ class AosSeedController extends Controller Artisan::call('aos:generate '.intval($seed->id)); } + $seed = $this->censor($seed->fresh()); return $seed->toJson(); } + private function censor(AosSeed $seed) { + if ($seed->race) { + $seed->makeHidden('seed'); + } + if ($seed->mystery) { + $seed->makeHidden('settings'); + } + return $seed; + } + } diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index 9e86521..c06c06b 100644 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -12,6 +12,6 @@ class VerifyCsrfToken extends Middleware * @var array */ protected $except = [ - // + 'api/aos-generate', ]; } diff --git a/routes/api.php b/routes/api.php index c5f18ee..ad624c3 100644 --- a/routes/api.php +++ b/routes/api.php @@ -21,6 +21,7 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) { Route::get('alttp-seed/{hash}', 'App\Http\Controllers\AlttpSeedController@byHash'); Route::post('alttp-seed/{hash}/retry', 'App\Http\Controllers\AlttpSeedController@retry'); +Route::post('aos-generate', 'App\Http\Controllers\AosSeedController@generate'); Route::get('aos-seed/{hash}', 'App\Http\Controllers\AosSeedController@byHash'); Route::post('aos-seed/{hash}/retry', 'App\Http\Controllers\AosSeedController@retry');