]> git.localhorst.tv Git - alttp.git/commitdiff
faster implementation for generating AoSR seeds
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 25 May 2022 17:06:01 +0000 (19:06 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 25 May 2022 17:06:01 +0000 (19:06 +0200)
.env.example
app/Console/Commands/GenerateAosSeed.php
composer.json
composer.lock
config/aos.php
config/filesystems.php

index 8105545c327f60ec75dfe0eebab43523bc795a28..f5fea82b8428f5a2a5210326b74d698e6a048821 100644 (file)
@@ -65,6 +65,7 @@ ALTTP_BASE_ROM=
 ALTTP_DOORS_CLI=
 
 AOS_BASE_ROM=
+AOS_CLI=
 AOS_HOSTNAME=aos.localhorst.tv
 AOS_SURGE_URL=https://aosrando.surge.sh
 AOS_URL=https://aos.localhorst.tv
index c51ce29a09a04a7acfe55e44fa6d1ab950994d84..fa390c8f4c35e6f9b5e2df16583a510205a3aebb 100644 (file)
@@ -4,9 +4,9 @@ namespace App\Console\Commands;
 
 use App\Beat\Encoder;
 use App\Models\AosSeed;
-use HeadlessChromium\BrowserFactory;
 use Illuminate\Console\Command;
 use Illuminate\Support\Facades\Storage;
+use Symfony\Component\Process\Process;
 
 class GenerateAosSeed extends Command
 {
@@ -41,39 +41,14 @@ class GenerateAosSeed extends Command
                        $temp_dir = sys_get_temp_dir();
 
                        $params = array_merge(['seed' => $seed->seed], $seed->settings);
-                       $url = config('aos.surge_url').'/?'.http_build_query($params, '', '&');
+                       $settings = http_build_query($params, '', '&');
 
-                       $fac = new BrowserFactory('chromium');
-                       $fac->addOptions(['noSandbox' => true]);
-                       $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();
-
-                       $stage = 'waiting for rom';
                        $romFile = $temp_dir.'/'.$seed->hash.'.gba';
-                       for ($i = 0; $i < 100; ++$i) {
-                               clearstatcache();
-                               if (is_file($romFile) && filesize($romFile) >= 8388608) {
-                                       break;
-                               }
-                               usleep(100_000);
-                       }
+                       $spoilerFile = $temp_dir.'/'.$seed->hash.'.txt';
+
+                       $stage = 'randomizing';
+                       $proc = new Process([config('aos.cli'), config('aos.base_rom'), $romFile, $settings]);
+                       $proc->mustRun();
 
                        $stage = 'calculating patch';
                        $encoder = new Encoder(file_get_contents(config('aos.base_rom')));
@@ -81,11 +56,12 @@ class GenerateAosSeed extends Command
                        Storage::disk('aos-seeds')->put($seed->hash.'.bps', $patch);
                        unlink($romFile);
 
+                       $stage = 'saving spoiler';
+                       Storage::disk('aos-spoilers')->put($seed->hash.'.txt', $proc->getOutput());
+
                        $stage = 'done';
                        $seed->status = 'generated';
                        $seed->save();
-
-                       $browser->close();
                } catch (\Throwable $e) {
                        $seed->status = 'error';
                        $seed->error_detail = [
index 20611d7d3cb266c18cdbb3261e17825741d755eb..3c7d625e85d2adbb3f9ba9de3c7b376f1fd59899 100644 (file)
@@ -7,7 +7,6 @@
     "require": {
         "php": "^8.0.2",
         "beyondcode/laravel-websockets": "^1.13",
-        "chrome-php/chrome": "^1.6",
         "doctrine/dbal": "^3.3",
         "guzzlehttp/guzzle": "^7.2",
         "jakyeru/larascord": "^3.0",
index 1ba6b8e53421bf1445d6b7f7ce936d64e7402a7e..2a90da20a0db206e7a9aca0fd312f9caef88c071 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "6782a76fb7c2451b20cb57f93be704df",
+    "content-hash": "a370e7a3f5ba178c836caec3a7ac4879",
     "packages": [
         {
             "name": "beyondcode/laravel-websockets",
             },
             "time": "2021-12-14T00:20:41+00:00"
         },
-        {
-            "name": "chrome-php/chrome",
-            "version": "v1.6.0",
-            "source": {
-                "type": "git",
-                "url": "https://github.com/chrome-php/chrome.git",
-                "reference": "e8264cb33a02053caf8877c1566e54f09c60d10c"
-            },
-            "dist": {
-                "type": "zip",
-                "url": "https://api.github.com/repos/chrome-php/chrome/zipball/e8264cb33a02053caf8877c1566e54f09c60d10c",
-                "reference": "e8264cb33a02053caf8877c1566e54f09c60d10c",
-                "shasum": ""
-            },
-            "require": {
-                "chrome-php/wrench": "^1.2",
-                "evenement/evenement": "^3.0.1",
-                "monolog/monolog": "^1.26 || ^2.2",
-                "php": "^7.3 || ^8.0",
-                "psr/log": "^1.1 || ^2.0 || ^3.0",
-                "symfony/filesystem": "^4.4 || ^5.0 || ^6.0",
-                "symfony/polyfill-mbstring": "^1.23",
-                "symfony/process": "^4.4 || ^5.0 || ^6.0"
-            },
-            "require-dev": {
-                "bamarni/composer-bin-plugin": "^1.4.1",
-                "phpunit/phpunit": "^9.5.10",
-                "symfony/var-dumper": "^4.4 || ^5.0 || ^6.0"
-            },
-            "type": "library",
-            "autoload": {
-                "psr-4": {
-                    "HeadlessChromium\\": "src/"
-                }
-            },
-            "notification-url": "https://packagist.org/downloads/",
-            "license": [
-                "MIT"
-            ],
-            "authors": [
-                {
-                    "name": "Graham Campbell",
-                    "email": "hello@gjcampbell.co.uk",
-                    "homepage": "https://github.com/GrahamCampbell"
-                },
-                {
-                    "name": "Enrico Dias",
-                    "email": "enricodias@gmail.com",
-                    "homepage": "https://github.com/enricodias"
-                }
-            ],
-            "description": "Instrument headless chrome/chromium instances from PHP",
-            "keywords": [
-                "browser",
-                "chrome",
-                "chromium",
-                "crawl",
-                "headless",
-                "pdf",
-                "puppeteer",
-                "screenshot"
-            ],
-            "support": {
-                "issues": "https://github.com/chrome-php/chrome/issues",
-                "source": "https://github.com/chrome-php/chrome/tree/v1.6.0"
-            },
-            "time": "2022-03-30T09:50:16+00:00"
-        },
-        {
-            "name": "chrome-php/wrench",
-            "version": "v1.2.0",
-            "source": {
-                "type": "git",
-                "url": "https://github.com/chrome-php/wrench.git",
-                "reference": "e8a34b54df8c9cd4f6d166bdb9df475988e17ce4"
-            },
-            "dist": {
-                "type": "zip",
-                "url": "https://api.github.com/repos/chrome-php/wrench/zipball/e8a34b54df8c9cd4f6d166bdb9df475988e17ce4",
-                "reference": "e8a34b54df8c9cd4f6d166bdb9df475988e17ce4",
-                "shasum": ""
-            },
-            "require": {
-                "ext-sockets": "*",
-                "php": "^7.3 || ^8.0",
-                "psr/log": "^1.1 || ^2.0 || ^3.0",
-                "symfony/polyfill-php80": "^1.22"
-            },
-            "conflict": {
-                "wrench/wrench": "*"
-            },
-            "require-dev": {
-                "bamarni/composer-bin-plugin": "^1.4.1",
-                "phpunit/phpunit": "^9.5.5"
-            },
-            "type": "library",
-            "autoload": {
-                "psr-4": {
-                    "Wrench\\": "src/"
-                }
-            },
-            "notification-url": "https://packagist.org/downloads/",
-            "license": [
-                "MIT"
-            ],
-            "authors": [
-                {
-                    "name": "Graham Campbell",
-                    "email": "hello@gjcampbell.co.uk",
-                    "homepage": "https://github.com/GrahamCampbell"
-                }
-            ],
-            "description": "A simple PHP WebSocket implementation",
-            "keywords": [
-                "WebSockets",
-                "hybi",
-                "websocket"
-            ],
-            "support": {
-                "issues": "https://github.com/chrome-php/wrench/issues",
-                "source": "https://github.com/chrome-php/wrench/tree/v1.2.0"
-            },
-            "time": "2022-03-30T09:35:45+00:00"
-        },
         {
             "name": "dflydev/dot-access-data",
             "version": "v3.0.1",
             ],
             "time": "2022-01-02T09:55:41+00:00"
         },
-        {
-            "name": "symfony/filesystem",
-            "version": "v6.0.7",
-            "source": {
-                "type": "git",
-                "url": "https://github.com/symfony/filesystem.git",
-                "reference": "6c9e4c41f2c51dfde3db298594ed9cba55dbf5ff"
-            },
-            "dist": {
-                "type": "zip",
-                "url": "https://api.github.com/repos/symfony/filesystem/zipball/6c9e4c41f2c51dfde3db298594ed9cba55dbf5ff",
-                "reference": "6c9e4c41f2c51dfde3db298594ed9cba55dbf5ff",
-                "shasum": ""
-            },
-            "require": {
-                "php": ">=8.0.2",
-                "symfony/polyfill-ctype": "~1.8",
-                "symfony/polyfill-mbstring": "~1.8"
-            },
-            "type": "library",
-            "autoload": {
-                "psr-4": {
-                    "Symfony\\Component\\Filesystem\\": ""
-                },
-                "exclude-from-classmap": [
-                    "/Tests/"
-                ]
-            },
-            "notification-url": "https://packagist.org/downloads/",
-            "license": [
-                "MIT"
-            ],
-            "authors": [
-                {
-                    "name": "Fabien Potencier",
-                    "email": "fabien@symfony.com"
-                },
-                {
-                    "name": "Symfony Community",
-                    "homepage": "https://symfony.com/contributors"
-                }
-            ],
-            "description": "Provides basic utilities for the filesystem",
-            "homepage": "https://symfony.com",
-            "support": {
-                "source": "https://github.com/symfony/filesystem/tree/v6.0.7"
-            },
-            "funding": [
-                {
-                    "url": "https://symfony.com/sponsor",
-                    "type": "custom"
-                },
-                {
-                    "url": "https://github.com/fabpot",
-                    "type": "github"
-                },
-                {
-                    "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
-                    "type": "tidelift"
-                }
-            ],
-            "time": "2022-04-01T12:54:51+00:00"
-        },
         {
             "name": "symfony/finder",
             "version": "v6.0.8",
index b6eaf2ae129b17f82fb59f5767e00af9bc0687c9..450524d8cf9c664b8d7d22470636e76530317532 100644 (file)
@@ -2,6 +2,7 @@
 
 return [
        'base_rom' => env('AOS_BASE_ROM', ''),
+       'cli' => env('AOS_CLI', ''),
        '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'),
index e743e9ff6c5bac072032a45ef584eb30a9afa33e..4076fb54077e0b08eb33dac2550634d6af99d90c 100644 (file)
@@ -63,6 +63,11 @@ return [
                        'visibility' => 'public',
                ],
 
+               'aos-spoilers' => [
+                       'driver' => 'local',
+                       'root' => storage_path('app/aos-spoilers'),
+               ],
+
                's3' => [
                        'driver' => 's3',
                        'key' => env('AWS_ACCESS_KEY_ID'),