diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php b/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php index 35cbe63a15..aeb3259645 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php @@ -8,14 +8,17 @@ use Appwrite\Event\Realtime; use Appwrite\Permission; use Appwrite\Role; use Exception; +use Utopia\Client; +use Utopia\Client\Adapter\Curl\Client as CurlAdapter; use Utopia\Compression\Compression; use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Query; -use Utopia\Fetch\Client as FetchClient; use Utopia\Platform\Action; +use Utopia\Psr7\Method; +use Utopia\Psr7\Request\Factory as RequestFactory; use Utopia\Queue\Message; use Utopia\Span\Span; use Utopia\Storage\Device; @@ -111,7 +114,7 @@ class Screenshots extends Action throw new \Exception("Rule for deployment not found"); } - $timeout = \intval($site->getAttribute('timeout', '15')) * 1000; + $timeout = \intval($site->getAttribute('timeout', '15')); $bucket = $dbForPlatform->getDocument('buckets', 'screenshots'); @@ -161,9 +164,13 @@ class Screenshots extends Action 'deploymentStatusIgnored' => true ]); + $browserEndpoint = System::getEnv('_APP_BROWSER_HOST', 'http://appwrite-browser:3000/v1'); + $client = (new Client(new CurlAdapter()))->withTimeout($timeout); + $factory = new RequestFactory(); + $screenshotError = null; - $screenshots = batch(\array_map(function ($key) use ($configs, $apiKey, $site, $timeout, &$screenshotError) { - return function () use ($key, $configs, $apiKey, $site, $timeout, &$screenshotError) { + $screenshots = batch(\array_map(function ($key) use ($configs, $apiKey, $site, $browserEndpoint, $client, $factory, &$screenshotError) { + return function () use ($key, $configs, $apiKey, $site, $browserEndpoint, $client, $factory, &$screenshotError) { try { $config = $configs[$key]; @@ -178,22 +185,13 @@ class Screenshots extends Action $config['sleep'] = $framework['screenshotSleep']; } - $browserEndpoint = System::getEnv('_APP_BROWSER_HOST', 'http://appwrite-browser:3000/v1'); - $client = new FetchClient(); - $client->setTimeout($timeout); - $client->addHeader('content-type', FetchClient::CONTENT_TYPE_APPLICATION_JSON); + $response = $client->sendRequest($factory->json(Method::POST, $browserEndpoint . '/screenshots', $config)); - $fetchResponse = $client->fetch( - url: $browserEndpoint . '/screenshots', - method: 'POST', - body: $config - ); - - if ($fetchResponse->getStatusCode() >= 400) { - throw new \Exception($fetchResponse->getBody()); + if ($response->getStatusCode() >= 400) { + throw new \Exception((string)$response->getBody()); } - $screenshot = $fetchResponse->getBody(); + $screenshot = (string)$response->getBody(); return ['key' => $key, 'screenshot' => $screenshot]; } catch (\Throwable $th) {