From 7956b47aa82e9197efbbcc45bfb058b564018eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 18 Feb 2026 11:06:56 +0100 Subject: [PATCH] Target rule for screenshot --- docker-compose.yml | 1 + .../Modules/Functions/Workers/Screenshots.php | 38 ++++--------------- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 635b1cb2cf..df9f6246fd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -565,6 +565,7 @@ services: # Specific - _APP_BROWSER_HOST - _APP_WORKER_SCREENSHOTS_ROUTER + - _APP_OPTIONS_FORCE_HTTPS # Basic - _APP_ENV - _APP_WORKER_PER_CORE diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php b/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php index 485078af88..8e0d54dc1b 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php @@ -111,52 +111,28 @@ class Screenshots extends Action throw new \Exception('Bucket not found'); } - $routerHost = System::getEnv('_APP_WORKER_SCREENSHOTS_ROUTER', 'http://appwrite'); + $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https'; + $routerHost = "$protocol://{$rule->getAttribute('domain')}"; $configs = [ 'screenshotLight' => [ - 'headers' => [ 'x-appwrite-hostname' => $rule->getAttribute('domain') ], + 'headers' => [], 'url' => $routerHost . '/?appwrite-preview=1&appwrite-theme=light', 'theme' => 'light' ], 'screenshotDark' => [ - 'headers' => [ 'x-appwrite-hostname' => $rule->getAttribute('domain') ], + 'headers' => [], 'url' => $routerHost . '/?appwrite-preview=1&appwrite-theme=dark', 'theme' => 'dark' ], ]; - $jwtObj = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', 900, 0); - $apiKey = $jwtObj->encode([ - 'hostnameOverride' => true, - 'disabledMetrics' => [ - METRIC_EXECUTIONS, - METRIC_EXECUTIONS_COMPUTE, - METRIC_EXECUTIONS_MB_SECONDS, - METRIC_NETWORK_REQUESTS, - METRIC_NETWORK_INBOUND, - METRIC_NETWORK_OUTBOUND, - str_replace(["{resourceType}"], [RESOURCE_TYPE_SITES], METRIC_RESOURCE_TYPE_EXECUTIONS), - str_replace(["{resourceType}"], [RESOURCE_TYPE_SITES], METRIC_RESOURCE_TYPE_EXECUTIONS_COMPUTE), - str_replace(["{resourceType}"], [RESOURCE_TYPE_SITES], METRIC_RESOURCE_TYPE_EXECUTIONS_MB_SECONDS), - str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS), - str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_COMPUTE), - str_replace(["{resourceType}", "{resourceInternalId}"], [RESOURCE_TYPE_SITES, $site->getSequence()], METRIC_RESOURCE_TYPE_ID_EXECUTIONS_MB_SECONDS), - ], - 'bannerDisabled' => true, - 'projectCheckDisabled' => true, - 'previewAuthDisabled' => true, - 'deploymentStatusIgnored' => true - ]); - $screenshotError = null; - $screenshots = batch(\array_map(function ($key) use ($configs, $apiKey, $site, $client, &$screenshotError) { - return function () use ($key, $configs, $apiKey, $site, $client, &$screenshotError) { + $screenshots = batch(\array_map(function ($key) use ($configs, $site, $client, &$screenshotError) { + return function () use ($key, $configs, $site, $client, &$screenshotError) { try { $config = $configs[$key]; - $config['headers'] = \array_merge($config['headers'] ?? [], [ - 'x-appwrite-key' => API_KEY_DYNAMIC . '_' . $apiKey - ]); + $config['headers'] = $config['headers'] ?? []; $config['sleep'] = 3000; $frameworks = Config::getParam('frameworks', []);