Merge pull request #9532 from appwrite/feat-site-deployment-details

Feat: Add screenshots to site
This commit is contained in:
Matej Bačo 2025-03-18 12:16:55 +01:00 committed by GitHub
commit 20d90e06f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 47 additions and 2 deletions

View file

@ -1003,6 +1003,29 @@ return [
'array' => false,
'filters' => [],
],
[
'$id' => ID::custom('deploymentScreenshotLight'), // File ID from 'screenshots' Console bucket
'type' => Database::VAR_STRING,
'format' => '',
'size' => 32,
'signed' => false,
'required' => false,
'default' => null,
'array' => false,
'filters' => [],
],
[
'$id' => ID::custom('deploymentScreenshotDark'), // File ID from 'screenshots' Console bucket
'type' => Database::VAR_STRING,
'format' => '',
'size' => 32,
'signed' => false,
'required' => false,
'default' => null,
'array' => false,
'filters' => [],
],
[
'$id' => ID::custom('vars'),
'type' => Database::VAR_STRING,

View file

@ -788,7 +788,7 @@ class Builds extends Action
]);
$config['sleep'] = 3000;
$frameworks = Config::getParam('frameworks', []);
$framework = $frameworks[$resource->getAttribute('framework', '')] ?? null;
if (!is_null($framework)) {
@ -898,6 +898,8 @@ class Builds extends Action
$resource->setAttribute('deploymentId', $deployment->getId());
$resource->setAttribute('deploymentInternalId', $deployment->getInternalId());
$resource->setAttribute('deploymentScreenshotDark', $deployment->getAttribute('screenshotDark', ''));
$resource->setAttribute('deploymentScreenshotLight', $deployment->getAttribute('screenshotLight', ''));
$resource = $dbForProject->updateDocument('sites', $resource->getId(), $resource);
$queries = [
Query::equal("projectInternalId", [$project->getInternalId()]),

View file

@ -100,6 +100,8 @@ class Delete extends Action
$site = $dbForProject->updateDocument('sites', $site->getId(), new Document(array_merge($site->getArrayCopy(), [
'deploymentId' => '',
'deploymentInternalId' => '',
'deploymentScreenshotDark' => '',
'deploymentScreenshotLight' => '',
])));
}

View file

@ -90,6 +90,8 @@ class Update extends Base
$site = $dbForProject->updateDocument('sites', $site->getId(), new Document(array_merge($site->getArrayCopy(), [
'deploymentInternalId' => $deployment->getInternalId(),
'deploymentId' => $deployment->getId(),
'deploymentScreenshotDark' => $deployment->getAttribute('screenshotDark', ''),
'deploymentScreenshotLight' => $deployment->getAttribute('screenshotLight', ''),
])));
$queries = [

View file

@ -58,6 +58,18 @@ class Site extends Model
'default' => '',
'example' => '5e5ea5c16897e',
])
->addRule('deploymentScreenshotLight', [
'type' => self::TYPE_STRING,
'description' => 'Screenshot of active deployment with light theme preference file ID.',
'default' => '',
'example' => '5e5ea5c16897e',
])
->addRule('deploymentScreenshotDark', [
'type' => self::TYPE_STRING,
'description' => 'Screenshot of active deployment with dark theme preference file ID.',
'default' => '',
'example' => '5e5ea5c16897e',
])
->addRule('vars', [
'type' => Response::MODEL_VARIABLE,
'description' => 'Site variables.',

View file

@ -1816,11 +1816,15 @@ class SitesCustomServerTest extends Scope
$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']);
$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']);
$screenshotId = $deployment['body']['screenshotLight'];
$file = $this->client->call(Client::METHOD_GET, "/storage/buckets/screenshots/files/$screenshotId/view?project=console", array_merge([
], $this->getHeaders()));