*/
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();
} catch (\Throwable $e) {
$seed->status = 'error';
$seed->error_detail = [
+ 'stage' => $stage,
'type' => get_class($e),
'message' => $e->getMessage(),
];
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'),
];