]> git.localhorst.tv Git - alttp.git/commitdiff
configurable surge URL
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 12 May 2022 22:07:25 +0000 (00:07 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 12 May 2022 22:07:25 +0000 (00:07 +0200)
.env.example
.gitignore
app/Jobs/GenerateAosSeed.php
config/aos.php

index c1b602fa2bd93b919c2c44b4337cf367cc0dbb7a..381184516838d1c2dcf101095a6cb95d7c58fc91 100644 (file)
@@ -63,4 +63,5 @@ DISCORD_BOT_ENABLE_COMMANDS=
 
 AOS_BASE_ROM=
 AOS_HOSTNAME=aos.localhorst.tv
+AOS_SURGE_URL=https://aosrando.surge.sh
 AOS_URL=https://aos.localhorst.tv
index 42465fed9adbd77ba696c6422df0e0f4456e3ef8..3165581562ad42b5d94a8b551f65524497d4f6b3 100644 (file)
@@ -15,6 +15,7 @@
 /public/js/vendor.js.map
 /public/mix-manifest.json
 /public/storage
+/public/surge
 /reports
 /storage/*.key
 /vendor
index 7169c3610f90f4714796329d809fb25bf65e05e1..a95c372bd1f79ad2736f46a5b53ed4ef4c8e45d4 100644 (file)
@@ -34,37 +34,52 @@ class GenerateAosSeed implements ShouldQueue
         */
        public function handle()
        {
+               $stage = 'initial';
                try {
                        $temp_dir = sys_get_temp_dir();
 
                        $seed = $this->seed;
                        $params = array_merge(['seed' => $seed->seed], $seed->settings);
-                       $url = 'https://aosrando.surge.sh/?'.http_build_query($params, '', '&');
+                       $url = config('aos.surge_url').'/?'.http_build_query($params, '', '&');
 
                        $fac = new BrowserFactory('chromium');
                        $browser = $fac->createBrowser();
 
+                       $stage = 'loading page';
                        $page = $browser->createPage();
                        $page->setDownloadPath($temp_dir);
                        $page->navigate($url)->waitForNavigation();
 
+                       $stage = 'selecting rom';
                        $fileInput = $page->dom()->querySelector('input[type=file]');
                        $fileInput->sendFile(config('aos.base_rom'));
                        $page->waitUntilContainsElement('select');
 
+                       $stage = 'clicking randomize';
                        $page->mouse()->find('button', 2)->click();
                        $page->waitUntilContainsElement('a[download]');
 
+                       $stage = 'clicking download';
                        $page->dom()->querySelector('a[download]')->setAttributeValue('download', $seed->hash.'.gba');
                        $page->mouse()->find('a[download]')->click();
 
-                       sleep(2);
-
+                       $stage = 'waiting for rom';
+                       $romFile = $temp_dir.'/'.$seed->hash.'.gba';
+                       for ($i = 0; $i < 20; ++$i) {
+                               clearstatcache();
+                               if (is_file($romFile) && filesize($romFile) >= 8388608) {
+                                       break;
+                               }
+                               usleep(100_000);
+                       }
+
+                       $stage = 'calculating patch';
                        $encoder = new Encoder(file_get_contents(config('aos.base_rom')));
-                       $patch = $encoder->createPatch(file_get_contents($temp_dir.'/'.$seed->hash.'.gba'));
+                       $patch = $encoder->createPatch(file_get_contents($romFile));
                        Storage::disk('aos-seeds')->put($seed->hash.'.bps', $patch);
-                       unlink($temp_dir.'/'.$seed->hash.'.gba');
+                       unlink($romFile);
 
+                       $stage = 'done';
                        $seed->status = 'generated';
                        $seed->save();
 
@@ -72,6 +87,7 @@ class GenerateAosSeed implements ShouldQueue
                } catch (\Throwable $e) {
                        $seed->status = 'error';
                        $seed->error_detail = [
+                               'stage' => $stage,
                                'type' => get_class($e),
                                'message' => $e->getMessage(),
                        ];
index 7f98a904a642d77c2668e1035f7d6f976f7f7d19..b6eaf2ae129b17f82fb59f5767e00af9bc0687c9 100644 (file)
@@ -3,5 +3,6 @@
 return [
        'base_rom' => env('AOS_BASE_ROM', ''),
        'hostname' => env('AOS_HOSTNAME', 'aos.localhorst.tv'),
+       'surge_url' => env('AOS_SURGE_URL', 'https://aosrando.surge.sh'),
        'url' => env('AOS_URL', 'https://aos.localhorst.tv'),
 ];