mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
AI PR review
This commit is contained in:
@@ -956,7 +956,7 @@ App::get('/v1/health/queue/failed/:name')
|
||||
System::getEnv('_APP_WEBHOOK_QUEUE_NAME', Event::WEBHOOK_QUEUE_NAME),
|
||||
System::getEnv('_APP_CERTIFICATES_QUEUE_NAME', Event::CERTIFICATES_QUEUE_NAME),
|
||||
System::getEnv('_APP_BUILDS_QUEUE_NAME', Event::BUILDS_QUEUE_NAME),
|
||||
System::getEnv('_APP_SCREENSHOTS_QUEUE_NAME', Event::SCREENSHOTS_CLASS_NAME),
|
||||
System::getEnv('_APP_SCREENSHOTS_QUEUE_NAME', Event::SCREENSHOTS_QUEUE_NAME),
|
||||
System::getEnv('_APP_MESSAGING_QUEUE_NAME', Event::MESSAGING_QUEUE_NAME),
|
||||
System::getEnv('_APP_MIGRATIONS_QUEUE_NAME', Event::MIGRATIONS_QUEUE_NAME)
|
||||
]), 'The name of the queue')
|
||||
@@ -1007,7 +1007,7 @@ App::get('/v1/health/queue/failed/:name')
|
||||
System::getEnv('_APP_WEBHOOK_QUEUE_NAME', Event::WEBHOOK_QUEUE_NAME) => $queueForWebhooks,
|
||||
System::getEnv('_APP_CERTIFICATES_QUEUE_NAME', Event::CERTIFICATES_QUEUE_NAME) => $queueForCertificates,
|
||||
System::getEnv('_APP_BUILDS_QUEUE_NAME', Event::BUILDS_QUEUE_NAME) => $queueForBuilds,
|
||||
System::getEnv('_APP_SCREENSHOTS_QUEUE_NAME', Event::SCREENSHOTS_CLASS_NAME) => $queueForScreenshots,
|
||||
System::getEnv('_APP_SCREENSHOTS_QUEUE_NAME', Event::SCREENSHOTS_QUEUE_NAME) => $queueForScreenshots,
|
||||
System::getEnv('_APP_MESSAGING_QUEUE_NAME', Event::MESSAGING_QUEUE_NAME) => $queueForMessaging,
|
||||
System::getEnv('_APP_MIGRATIONS_QUEUE_NAME', Event::MIGRATIONS_QUEUE_NAME) => $queueForMigrations,
|
||||
};
|
||||
|
||||
@@ -15,8 +15,8 @@ class Screenshot extends Event
|
||||
parent::__construct($publisher);
|
||||
|
||||
$this
|
||||
->setQueue(System::getEnv('_APP_BUILDS_QUEUE_NAME', Event::SCREENSHOTS_QUEUE_NAME))
|
||||
->setClass(System::getEnv('_APP_BUILDS_CLASS_NAME', Event::SCREENSHOTS_CLASS_NAME));
|
||||
->setQueue(System::getEnv('_APP_SCREENSHOTS_QUEUE_NAME', Event::SCREENSHOTS_QUEUE_NAME))
|
||||
->setClass(System::getEnv('_APP_SCREENSHOTS_CLASS_NAME', Event::SCREENSHOTS_CLASS_NAME));
|
||||
}
|
||||
|
||||
public function setDeploymentId(string $deploymentId): self
|
||||
|
||||
@@ -13,7 +13,6 @@ use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Database\Validator\Authorization;
|
||||
use Utopia\Fetch\Client as FetchClient;
|
||||
use Utopia\Platform\Action;
|
||||
use Utopia\Queue\Message;
|
||||
@@ -55,7 +54,7 @@ class Screenshots extends Action
|
||||
Document $project,
|
||||
Device $deviceForFiles
|
||||
): void {
|
||||
Console::log('Build action started');
|
||||
Console::log('Screenshot action started');
|
||||
|
||||
$payload = $message->getPayload() ?? [];
|
||||
|
||||
@@ -67,9 +66,18 @@ class Screenshots extends Action
|
||||
|
||||
$deploymentId = $payload['deploymentId'] ?? null;
|
||||
$deployment = $dbForProject->getDocument('deployments', $deploymentId);
|
||||
|
||||
if ($deployment->isEmpty()) {
|
||||
throw new \Exception('Deployment not found');
|
||||
}
|
||||
|
||||
$siteId = $deployment->getAttribute('resourceId');
|
||||
$site = $dbForProject->getDocument('sites', $siteId);
|
||||
|
||||
if ($site->isEmpty()) {
|
||||
throw new \Exception('Site not found');
|
||||
}
|
||||
|
||||
// Realtime preparation
|
||||
$event = "sites.[siteId].deployments.[deploymentId].update";
|
||||
$queueForRealtime
|
||||
@@ -83,21 +91,25 @@ class Screenshots extends Action
|
||||
$this->appendToLogs($dbForProject, $deployment->getId(), $queueForRealtime, "[90m[$date] [90m[[0mappwrite[90m][97m Screenshot capturing started. [0m\n");
|
||||
|
||||
try {
|
||||
$rule = Authorization::skip(fn () => $dbForPlatform->findOne('rules', [
|
||||
$rule = $dbForPlatform->findOne('rules', [
|
||||
Query::equal("projectInternalId", [$project->getSequence()]),
|
||||
Query::equal("type", ["deployment"]),
|
||||
Query::equal('deploymentInternalId', [$deployment->getSequence()]),
|
||||
]));
|
||||
]);
|
||||
|
||||
if ($rule->isEmpty()) {
|
||||
throw new \Exception("Rule for build not found");
|
||||
throw new \Exception("Rule for deployment not found");
|
||||
}
|
||||
|
||||
$client = new FetchClient();
|
||||
$client->setTimeout(\intval($site->getAttribute('timeout', '15')) * 1000);
|
||||
$client->addHeader('content-type', FetchClient::CONTENT_TYPE_APPLICATION_JSON);
|
||||
|
||||
$bucket = Authorization::skip(fn () => $dbForPlatform->getDocument('buckets', 'screenshots'));
|
||||
$bucket = $dbForPlatform->getDocument('buckets', 'screenshots');
|
||||
|
||||
if ($bucket->isEmpty()) {
|
||||
throw new \Exception('Bucket not found');
|
||||
}
|
||||
|
||||
$configs = [
|
||||
'screenshotLight' => [
|
||||
@@ -220,7 +232,7 @@ class Screenshots extends Action
|
||||
'metadata' => ['content_type' => $mimeType],
|
||||
]);
|
||||
|
||||
Authorization::skip(fn () => $dbForPlatform->createDocument('bucket_' . $bucket->getSequence(), $file));
|
||||
$dbForPlatform->createDocument('bucket_' . $bucket->getSequence(), $file);
|
||||
|
||||
$updates->setAttribute($key, $fileId);
|
||||
}
|
||||
|
||||
@@ -54,15 +54,22 @@ class SitesConsoleClientTest extends Scope
|
||||
$this->assertStringContainsString("Themed website", $response['body']);
|
||||
$this->assertStringContainsString("@media (prefers-color-scheme: dark)", $response['body']);
|
||||
|
||||
$deployment = $this->getDeployment($siteId, $deploymentId);
|
||||
$this->assertEquals(200, $deployment['headers']['status-code']);
|
||||
$this->assertNotEmpty($deployment['body']['screenshotLight']);
|
||||
$this->assertNotEmpty($deployment['body']['screenshotDark']);
|
||||
$deployment = null;
|
||||
$site = null;
|
||||
$this->assertEventually(function () use ($siteId, $deploymentId, &$deployment, &$site) {
|
||||
$deployment = $this->getDeployment($siteId, $deploymentId);
|
||||
$this->assertEquals(200, $deployment['headers']['status-code']);
|
||||
$this->assertNotEmpty($deployment['body']['screenshotLight']);
|
||||
$this->assertNotEmpty($deployment['body']['screenshotDark']);
|
||||
|
||||
$site = $this->getSite($siteId);
|
||||
$this->assertEquals(200, $site['headers']['status-code']);
|
||||
$this->assertEquals($deployment['body']['screenshotLight'], $site['body']['deploymentScreenshotLight']);
|
||||
$this->assertEquals($deployment['body']['screenshotDark'], $site['body']['deploymentScreenshotDark']);
|
||||
$site = $this->getSite($siteId);
|
||||
$this->assertEquals(200, $site['headers']['status-code']);
|
||||
$this->assertEquals($deployment['body']['screenshotLight'], $site['body']['deploymentScreenshotLight']);
|
||||
$this->assertEquals($deployment['body']['screenshotDark'], $site['body']['deploymentScreenshotDark']);
|
||||
});
|
||||
|
||||
$this->assertNotNull($site);
|
||||
$this->assertNotNull($deployment);
|
||||
|
||||
$screenshotId = $deployment['body']['screenshotLight'];
|
||||
$file = $this->client->call(Client::METHOD_GET, "/storage/buckets/screenshots/files/$screenshotId/view?project=console", array_merge($this->getHeaders(), [
|
||||
|
||||
Reference in New Issue
Block a user