3 namespace App\Http\Controllers;
5 use App\DiscordAppCommands\AosrPresetCommand;
6 use App\Models\AosSeed;
7 use Illuminate\Http\Request;
8 use Illuminate\Support\Facades\Artisan;
10 class AosSeedController extends Controller
13 public function byHash($hash) {
14 $seed = AosSeed::where('hash', '=', $hash)->firstOrFail();
17 $seed->makeHidden('seed');
20 $seed->makeHidden('settings');
23 return $seed->toJson();
26 public function generate(Request $request) {
27 $validatedData = $request->validate([
28 'preset' => 'string|required',
31 $presetName = $validatedData['preset'];
32 $race = $validatedData['race'] ?? false;
34 if (!isset(AosrPresetCommand::$presets[$presetName])) {
37 $preset = AosrPresetCommand::$presets[$presetName];
38 $seed = AosSeed::generateSurge($presetName, $preset['settings'], $race);
39 Artisan::call('aos:generate '.intval($seed->id));
41 $seed = $this->censor($seed->fresh());
42 return $seed->toJson();
45 public function retry($hash) {
46 $seed = AosSeed::where('hash', '=', $hash)->firstOrFail();
48 if ($seed->status == 'error') {
49 $seed->status = 'pending';
51 Artisan::call('aos:generate '.intval($seed->id));
54 $seed = $this->censor($seed->fresh());
55 return $seed->toJson();
58 private function censor(AosSeed $seed) {
60 $seed->makeHidden('seed');
63 $seed->makeHidden('settings');