From a6bcc3ce97f3e9e3183d0053ed1e1638fa9ba2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 15 Feb 2025 01:57:41 +0100 Subject: [PATCH] Fix bugs --- app/controllers/general.php | 2 +- app/http.php | 3 +++ app/init.php | 3 ++- docker-compose.yml | 1 + .../Modules/Functions/Workers/Builds.php | 18 ++++++++++++------ 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index c9efc90426..eb9a02f8ca 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -585,7 +585,7 @@ App::init() */ App::init() - ->groups(['database', 'functions', 'storage', 'messaging']) + ->groups(['database', 'functions', 'messaging']) ->inject('project') ->inject('request') ->action(function (Document $project, Request $request) { diff --git a/app/http.php b/app/http.php index 8562962977..b8852e9f74 100644 --- a/app/http.php +++ b/app/http.php @@ -269,6 +269,9 @@ $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $reg 'fileSecurity' => true, '$permissions' => [ Permission::create(Role::any()), + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), ], 'search' => 'buckets Screenshots', ])); diff --git a/app/init.php b/app/init.php index fbffc4b3ad..971986920b 100644 --- a/app/init.php +++ b/app/init.php @@ -1911,8 +1911,9 @@ App::setResource( ); App::setResource('previewHostname', function (Request $request) { + // TODO: @Meldiron Allow in production too for internal communication (authorized with secret) if (App::isDevelopment()) { - $host = $request->getQuery('appwrite-hostname') ?? ''; + $host = $request->getQuery('appwrite-hostname', $request->getHeader('x-appwrite-hostname', '')); if (!empty($host)) { return $host; } diff --git a/docker-compose.yml b/docker-compose.yml index 277f82aafb..a8caddfeae 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -433,6 +433,7 @@ services: volumes: - appwrite-functions:/storage/functions:rw - appwrite-builds:/storage/builds:rw + - appwrite-uploads:/storage/uploads:rw - ./app:/usr/src/code/app - ./src:/usr/src/code/src depends_on: diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 916c987da5..809f3f4ce9 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -717,16 +717,22 @@ class Builds extends Action Query::equal("resourceInternalId", [$deployment->getInternalId()]) ])); - if(!$rule->isEmpty()) { + if($rule->isEmpty()) { throw new \Exception("Rule for build not found"); } $client = new FetchClient(); $client->addHeader('Authorization', 'Bearer ' . App::getEnv('_APP_OPENSSL_KEY_V1', '')); - $response = $client->fetch('http://appwrite-browser/screenshot', query: [ - 'url' => 'http://' . $rule->getAttribute('domain') . '/' + $response = $client->fetch('http://appwrite-browser:3000/screenshot', query: [ + 'hostname' => $rule->getAttribute('domain'), + 'path' => '/', ]); + + if($response->getStatusCode() >= 400) { + throw new \Exception("Screenshot failed to generate: " . $response->getBody()); + } + $screenshot = $response->getBody(); $bucket = $dbForPlatform->getDocument('buckets', 'screenshots'); @@ -736,7 +742,7 @@ class Builds extends Action $fileName = $fileId . '.png'; $path = $deviceForFiles->getPath($fileName); $path = str_ireplace($deviceForFiles->getRoot(), $deviceForFiles->getRoot() . DIRECTORY_SEPARATOR . $bucket->getId(), $path); // Add bucket id to path after root - $success = $deviceForFiles->write($path, $screenshot, "image/png"); + $success = $deviceForFiles->write($path, $screenshot, "image/png"); if(!$success) { throw new \Exception("Screenshot failed to save"); @@ -769,9 +775,9 @@ class Builds extends Action 'openSSLTag' => null, 'openSSLIV' => null, 'search' => implode(' ', [$fileId, $fileName]), - 'metadata' => ['content_type' => $deviceForFiles->getFileMimeType($fileName)], + 'metadata' => ['content_type' => $deviceForFiles->getFileMimeType($path)], ]); - $file = $dbForProject->createDocument('bucket_' . $bucket->getInternalId(), $file); + $file = Authorization::skip(fn () => $dbForPlatform->createDocument('bucket_' . $bucket->getInternalId(), $file)); $deployment->setAttribute('screenshot', $fileId); $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment);