mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
use request filters for 1.8.0 to convert into and
This commit is contained in:
@@ -23,6 +23,7 @@ use Appwrite\Utopia\Request\Filters\V17 as RequestV17;
|
||||
use Appwrite\Utopia\Request\Filters\V18 as RequestV18;
|
||||
use Appwrite\Utopia\Request\Filters\V19 as RequestV19;
|
||||
use Appwrite\Utopia\Request\Filters\V20 as RequestV20;
|
||||
use Appwrite\Utopia\Request\Filters\V21 as RequestV21;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Filters\V16 as ResponseV16;
|
||||
use Appwrite\Utopia\Response\Filters\V17 as ResponseV17;
|
||||
@@ -906,6 +907,9 @@ App::init()
|
||||
$dbForProject = $getProjectDB($project);
|
||||
$request->addFilter(new RequestV20($dbForProject, $route->getPathValues($request)));
|
||||
}
|
||||
if (version_compare($requestFormat, '1.8.1', '<')) {
|
||||
$request->addFilter(new RequestV21());
|
||||
}
|
||||
}
|
||||
|
||||
$domain = $request->getHostname();
|
||||
|
||||
@@ -66,9 +66,8 @@ class Create extends Base
|
||||
->param('repository', '', new Text(128, 0), 'Repository name of the template.')
|
||||
->param('owner', '', new Text(128, 0), 'The name of the owner of the template.')
|
||||
->param('rootDirectory', '', new Text(128, 0), 'Path to function code in the template repo.')
|
||||
->param('version', '', new Text(128, 0), 'Version (tag) for the repo linked to the function template.', true)
|
||||
->param('type', '', new WhiteList(['commit', 'branch', 'tag']), 'Type for the reference provided. Can be commit, branch, or version', true)
|
||||
->param('reference', '', new Text(128, 0), 'Reference value, can be a commit hash, branch name, or release tag', true)
|
||||
->param('type', '', new WhiteList(['commit', 'branch', 'tag']), 'Type for the reference provided. Can be commit, branch, or tag')
|
||||
->param('reference', '', new Text(128, 0), 'Reference value, can be a commit hash, branch name, or release tag')
|
||||
->param('activate', false, new Boolean(), 'Automatically activate the deployment when it is finished building.', true)
|
||||
->inject('request')
|
||||
->inject('response')
|
||||
@@ -86,7 +85,6 @@ class Create extends Base
|
||||
string $repository,
|
||||
string $owner,
|
||||
string $rootDirectory,
|
||||
string $version,
|
||||
string $type,
|
||||
string $reference,
|
||||
bool $activate,
|
||||
@@ -105,22 +103,15 @@ class Create extends Base
|
||||
throw new Exception(Exception::FUNCTION_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (empty($version) && empty($type) && empty($reference)) {
|
||||
throw new Exception("Either version or type & reference must be provided");
|
||||
}
|
||||
|
||||
$referenceType = !empty($version) ? GitHub::CLONE_TYPE_TAG : $type;
|
||||
$referenceValue = !empty($version) ? $version : $reference;
|
||||
|
||||
$branchUrl = $type == GitHub::CLONE_TYPE_BRANCH ? "https://github.com/$owner/$repository/tree/$referenceValue" : "";
|
||||
$branchUrl = $type == GitHub::CLONE_TYPE_BRANCH ? "https://github.com/$owner/$repository/tree/$reference" : "";
|
||||
$repositoryUrl = "https://github.com/$owner/$repository";
|
||||
|
||||
$template = new Document([
|
||||
'repositoryName' => $repository,
|
||||
'ownerName' => $owner,
|
||||
'rootDirectory' => $rootDirectory,
|
||||
'referenceType' => $referenceType,
|
||||
'referenceValue' => $referenceValue,
|
||||
'referenceType' => $type,
|
||||
'referenceValue' => $reference,
|
||||
]);
|
||||
|
||||
if (!empty($function->getAttribute('providerRepositoryId'))) {
|
||||
@@ -166,7 +157,7 @@ class Create extends Base
|
||||
'providerRepositoryOwner' => $owner,
|
||||
'providerRepositoryUrl' => $repositoryUrl,
|
||||
'providerBranchUrl' => $branchUrl,
|
||||
'providerBranch' => $type == GitHub::CLONE_TYPE_BRANCH ? $referenceValue : '',
|
||||
'providerBranch' => $type == GitHub::CLONE_TYPE_BRANCH ? $reference : '',
|
||||
'type' => 'vcs',
|
||||
'activate' => $activate,
|
||||
]));
|
||||
|
||||
@@ -68,9 +68,8 @@ class Create extends Base
|
||||
->param('repository', '', new Text(128, 0), 'Repository name of the template.')
|
||||
->param('owner', '', new Text(128, 0), 'The name of the owner of the template.')
|
||||
->param('rootDirectory', '', new Text(128, 0), 'Path to site code in the template repo.')
|
||||
->param('version', '', new Text(128, 0), 'Version (tag) for the repo linked to the function template.', true)
|
||||
->param('type', '', new WhiteList(['branch', 'commit', 'tag']), 'Type for the reference provided. Can be commit, branch, or version', true)
|
||||
->param('reference', '', new Text(128, 0), 'Reference value, can be a commit hash, branch name, or release tag', true)
|
||||
->param('type', '', new WhiteList(['branch', 'commit', 'tag']), 'Type for the reference provided. Can be commit, branch, or tag')
|
||||
->param('reference', '', new Text(128, 0), 'Reference value, can be a commit hash, branch name, or release tag')
|
||||
->param('activate', false, new Boolean(), 'Automatically activate the deployment when it is finished building.', true)
|
||||
->inject('request')
|
||||
->inject('response')
|
||||
@@ -88,7 +87,6 @@ class Create extends Base
|
||||
string $repository,
|
||||
string $owner,
|
||||
string $rootDirectory,
|
||||
string $version,
|
||||
string $type,
|
||||
string $reference,
|
||||
bool $activate,
|
||||
@@ -107,22 +105,15 @@ class Create extends Base
|
||||
throw new Exception(Exception::SITE_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (empty($version) && empty($type) && empty($reference)) {
|
||||
throw new Exception("Either version or type & reference must be provided");
|
||||
}
|
||||
|
||||
$referenceType = !empty($version) ? GitHub::CLONE_TYPE_TAG : $type;
|
||||
$referenceValue = !empty($version) ? $version : $reference;
|
||||
|
||||
$branchUrl = $type == GitHub::CLONE_TYPE_BRANCH ? "https://github.com/$owner/$repository/tree/$referenceValue" : "";
|
||||
$branchUrl = $type == GitHub::CLONE_TYPE_BRANCH ? "https://github.com/$owner/$repository/tree/$reference" : "";
|
||||
$repositoryUrl = "https://github.com/$owner/$repository";
|
||||
|
||||
$template = new Document([
|
||||
'repositoryName' => $repository,
|
||||
'ownerName' => $owner,
|
||||
'rootDirectory' => $rootDirectory,
|
||||
'referenceType' => $referenceType,
|
||||
'referenceValue' => $referenceValue
|
||||
'referenceType' => $type,
|
||||
'referenceValue' => $reference
|
||||
]);
|
||||
|
||||
if (!empty($site->getAttribute('providerRepositoryId'))) {
|
||||
@@ -177,7 +168,7 @@ class Create extends Base
|
||||
'providerRepositoryOwner' => $owner,
|
||||
'providerRepositoryUrl' => $repositoryUrl,
|
||||
'providerBranchUrl' => $branchUrl,
|
||||
'providerBranch' => $type == GitHub::CLONE_TYPE_BRANCH ? $referenceValue : '',
|
||||
'providerBranch' => $type == GitHub::CLONE_TYPE_BRANCH ? $reference : '',
|
||||
'adapter' => $site->getAttribute('adapter', ''),
|
||||
'fallbackFile' => $site->getAttribute('fallbackFile', ''),
|
||||
'type' => 'vcs',
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Request\Filters;
|
||||
|
||||
use Appwrite\Utopia\Request\Filter;
|
||||
|
||||
class V21 extends Filter
|
||||
{
|
||||
// Convert 1.8.0 params to 1.8.1
|
||||
public function parse(array $content, string $model): array
|
||||
{
|
||||
switch ($model) {
|
||||
case 'functions.createTemplateDeployment':
|
||||
case 'sites.createTemplateDeployment':
|
||||
$content = $this->convertVersionToTypeAndReference($content);
|
||||
break;
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert version parameter to type and reference for backwards compatibility
|
||||
* with 1.8.0 template deployment endpoints
|
||||
*/
|
||||
protected function convertVersionToTypeAndReference(array $content): array
|
||||
{
|
||||
if (!empty($content['version'])) {
|
||||
$content['type'] = 'tag';
|
||||
$content['reference'] = $content['version'];
|
||||
unset($content['version']);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user