From 2f49722092aafa12581d250eaae70bec286bfc16 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Thu, 28 Aug 2025 19:17:07 +0530 Subject: [PATCH] Revert to use deployment preview --- app/controllers/api/vcs.php | 2 +- .../Modules/Functions/Workers/Builds.php | 28 +++++-------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 85b63916d7..5541b99318 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -271,6 +271,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', ''); $domain = ID::unique() . "." . $sitesDomain; $ruleId = md5($domain); + $previewRuleId = $ruleId; Authorization::skip( fn () => $dbForPlatform->createDocument('rules', new Document([ '$id' => $ruleId, @@ -303,7 +304,6 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId $resourceProjectHash = substr(hash('sha256', $resource->getId() . $project->getId()), 0, 7); $domain = "branch-{$branchPrefix}-{$resourceProjectHash}.{$sitesDomain}"; $ruleId = md5($domain); - $previewRuleId = $ruleId; try { Authorization::skip( fn () => $dbForPlatform->createDocument('rules', new Document([ diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 18c746e9cd..9547a752ef 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1554,30 +1554,16 @@ class Builds extends Action default => throw new \Exception('Invalid resource type') }; + $rule = Authorization::skip(fn () => $dbForPlatform->findOne('rules', [ + Query::equal("projectInternalId", [$project->getSequence()]), + Query::equal("type", ["deployment"]), + Query::equal("deploymentInternalId", [$deployment->getSequence()]), + ])); + $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https'; $previewUrl = match($resource->getCollection()) { 'functions' => '', - 'sites' => (function () use ($deployment, $project, $dbForPlatform, $protocol, $resource) { - $providerBranch = $deployment->getAttribute('providerBranch', ''); - if (!empty($providerBranch)) { - $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', ''); - $branchPrefix = substr($providerBranch, 0, 16); - if (strlen($providerBranch) > 16) { - $remainingChars = substr($providerBranch, 16); - $branchPrefix .= '-' . substr(hash('sha256', $remainingChars), 0, 7); - } - $resourceProjectHash = substr(hash('sha256', $resource->getId() . $project->getId()), 0, 7); - $domain = "branch-{$branchPrefix}-{$resourceProjectHash}.{$sitesDomain}"; - $ruleId = md5($domain); - - $branchRule = Authorization::skip(fn () => $dbForPlatform->getDocument('rules', $ruleId)); - - if (!empty($branchRule) && !$branchRule->isEmpty()) { - return "{$protocol}://" . $branchRule->getAttribute('domain', ''); - } - } - return ''; - })(), + 'sites' => !empty($rule) ? ("{$protocol}://" . $rule->getAttribute('domain', '')) : '', default => throw new \Exception('Invalid resource type') };