This commit is contained in:
Chirag Aggarwal
2026-02-21 20:21:08 +05:30
parent 4b63d3db86
commit a907c9df34
6 changed files with 42 additions and 27 deletions
+1 -1
View File
@@ -1120,7 +1120,7 @@ return [
'format' => '',
'filters' => [],
'required' => false,
'default' => true,
'default' => false,
'array' => false,
],
[
@@ -10,6 +10,16 @@ abstract class Action extends UtopiaAction
protected const LABEL_TEXT_X = 260;
protected const TEXT_PADDING = 10;
protected const FALLBACK_CHAR_WIDTH = 7;
protected const MESSAGE_WIDTHS = [
'not found' => 75,
'disabled' => 75,
'no deployment' => 112,
'unknown' => 74,
'ready' => 55,
'building' => 70,
'waiting' => 70,
'failed' => 60,
];
protected const COLOR_BRIGHTGREEN = '#4c1';
protected const COLOR_GREEN = '#97ca00';
protected const COLOR_YELLOW = '#dfb317';
@@ -6,23 +6,15 @@ use Appwrite\Platform\Modules\Badge\Http\Action;
use Appwrite\Template\Template;
use Appwrite\Utopia\Response;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Exception\NotFound as NotFoundException;
use Utopia\Database\Validator\Authorization;
use Utopia\Validator\Text;
use Utopia\Database\Validator\UID;
class Get extends Action
{
private const LABEL = 'appwrite functions';
private const LABEL_WIDTH = 137;
private const MESSAGE_WIDTHS = [
'not found' => 75,
'disabled' => 75,
'no deployment' => 112,
'unknown' => 74,
'ready' => 60,
'building' => 76,
'waiting' => 70,
'failed' => 60,
];
public static function getName(): string
{
@@ -40,7 +32,7 @@ class Get extends Action
->label('sdk.auth', [])
->label('sdk.namespace', 'badge')
->label('sdk.method', 'getFunction')
->param('functionId', '', new Text(36), 'Function ID')
->param('functionId', '', new UID(), 'Function ID')
->inject('response')
->inject('dbForProject')
->inject('authorization')
@@ -49,7 +41,11 @@ class Get extends Action
public function action(string $functionId, Response $response, Database $dbForProject, Authorization $authorization): void
{
$function = $authorization->skip(fn () => $dbForProject->getDocument('functions', $functionId));
try {
$function = $authorization->skip(fn () => $dbForProject->getDocument('functions', $functionId));
} catch (NotFoundException) {
$function = new Document();
}
$label = self::LABEL;
switch (true) {
@@ -6,23 +6,15 @@ use Appwrite\Platform\Modules\Badge\Http\Action;
use Appwrite\Template\Template;
use Appwrite\Utopia\Response;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Exception\NotFound as NotFoundException;
use Utopia\Database\Validator\Authorization;
use Utopia\Validator\Text;
use Utopia\Database\Validator\UID;
class Get extends Action
{
private const LABEL = 'appwrite sites';
private const LABEL_WIDTH = 110;
private const MESSAGE_WIDTHS = [
'not found' => 75,
'disabled' => 75,
'no deployment' => 112,
'unknown' => 74,
'ready' => 60,
'building' => 76,
'waiting' => 70,
'failed' => 60,
];
public static function getName(): string
{
@@ -40,7 +32,7 @@ class Get extends Action
->label('sdk.auth', [])
->label('sdk.namespace', 'badge')
->label('sdk.method', 'getSite')
->param('siteId', '', new Text(36), 'Site ID')
->param('siteId', '', new UID(), 'Site ID')
->inject('response')
->inject('dbForProject')
->inject('authorization')
@@ -49,7 +41,11 @@ class Get extends Action
public function action(string $siteId, Response $response, Database $dbForProject, Authorization $authorization): void
{
$site = $authorization->skip(fn () => $dbForProject->getDocument('sites', $siteId));
try {
$site = $authorization->skip(fn () => $dbForProject->getDocument('sites', $siteId));
} catch (NotFoundException) {
$site = new Document();
}
$label = self::LABEL;
switch (true) {
@@ -75,6 +75,7 @@ class Update extends Base
->param('buildRuntime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Runtime to use during build step.', true)
->param('adapter', '', new WhiteList(['static', 'ssr']), 'Framework adapter defining rendering strategy. Allowed values are: static, ssr', true)
->param('fallbackFile', '', new Text(255, 0), 'Fallback file for single page application sites.', true)
->param('deploymentBadge', null, new Boolean(), 'Whether to display deployment badge for this site.', true)
->param('installationId', '', new Text(128, 0), 'Appwrite Installation ID for VCS (Version Control System) deployment.', true)
->param('providerRepositoryId', '', new Text(128, 0), 'Repository ID of the repo linked to the site.', true)
->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the site.', true)
@@ -111,6 +112,7 @@ class Update extends Base
string $buildRuntime,
string $adapter,
string $fallbackFile,
?bool $deploymentBadge,
string $installationId,
?string $providerRepositoryId,
string $providerBranch,
@@ -161,6 +163,10 @@ class Update extends Base
$framework = $site->getAttribute('framework');
}
if ($request->getPayload('deploymentBadge', null) === null) {
$deploymentBadge = $site->getAttribute('deploymentBadge', true);
}
$enabled ??= $site->getAttribute('enabled', true);
$repositoryId = $site->getAttribute('repositoryId', '');
@@ -264,6 +270,7 @@ class Update extends Base
'buildRuntime' => $buildRuntime,
'adapter' => $adapter,
'fallbackFile' => $fallbackFile,
'deploymentBadge' => $deploymentBadge,
])));
// Redeploy logic
@@ -185,6 +185,12 @@ class Site extends Model
'default' => null,
'example' => 'index.html',
])
->addRule('deploymentBadge', [
'type' => self::TYPE_BOOLEAN,
'description' => 'Whether to display the deployment badge in the site response.',
'default' => true,
'example' => false,
])
;
}