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 $preset = AosrPresetCommand::presetByName($presetName);
38 $seed = AosSeed::generateSurge($preset['value'], $preset['settings'], $race);
39 Artisan::call('aos:generate '.intval($seed->id));
41 $seed = $this->censor($seed->fresh());
42 return $seed->toJson();
45 public function presets() {
46 return array_values(AosrPresetCommand::$presets);
49 public function retry($hash) {
50 $seed = AosSeed::where('hash', '=', $hash)->firstOrFail();
52 if ($seed->status == 'error') {
53 $seed->status = 'pending';
55 Artisan::call('aos:generate '.intval($seed->id));
58 $seed = $this->censor($seed->fresh());
59 return $seed->toJson();
62 private function censor(AosSeed $seed) {
64 $seed->makeHidden('seed');
67 $seed->makeHidden('settings');