diff --git a/app/config/errors.php b/app/config/errors.php index df8cb45c98..d38f816136 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -546,6 +546,11 @@ return [ 'description' => 'The requested framework is either inactive or unsupported. Please check the value of the _APP_SITES_FRAMEWORKS environment variable.', 'code' => 404, ], + Exception::SITE_TEMPLATE_NOT_FOUND => [ + 'name' => Exception::SITE_TEMPLATE_NOT_FOUND, + 'description' => 'Site Template with the requested ID could not be found.', + 'code' => 404, + ], /** Builds */ Exception::BUILD_NOT_FOUND => [ diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 4412505cae..86f02316bc 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -154,6 +154,7 @@ class Exception extends \Exception /** Sites */ public const SITE_NOT_FOUND = 'site_not_found'; public const SITE_FRAMEWORK_UNSUPPORTED = 'site_framework_unsupported'; + public const SITE_TEMPLATE_NOT_FOUND = 'site_template_not_found'; /** Functions */ public const FUNCTION_NOT_FOUND = 'function_not_found'; diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/GetTemplate.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/GetTemplate.php new file mode 100644 index 0000000000..f9233ea4b5 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/GetTemplate.php @@ -0,0 +1,56 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_GET) + ->setHttpPath('/v1/sites/templates/:templateId') + ->desc('Get site template') + ->label('scope', 'public') + ->label('sdk.namespace', 'sites') + ->label('sdk.method', 'getTemplate') + ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN]) + ->label('sdk.description', '/docs/references/sites/get-template.md') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_TEMPLATE_SITE) + ->param('templateId', '', new Text(128), 'Template ID.') + ->inject('response') + ->callback([$this, 'action']); + } + + public function action(string $templateId, Response $response) + { + $templates = Config::getParam('site-templates', []); + + $template = array_shift(\array_filter($templates, function ($template) use ($templateId) { + return $template['id'] === $templateId; + })); + + if (empty($template)) { + throw new Exception(Exception::SITE_TEMPLATE_NOT_FOUND); + } + + $response->dynamic(new Document($template), Response::MODEL_TEMPLATE_SITE); + } +} diff --git a/src/Appwrite/Platform/Modules/Sites/Services/Http.php b/src/Appwrite/Platform/Modules/Sites/Services/Http.php index 5adbdf3029..b66866a2a6 100644 --- a/src/Appwrite/Platform/Modules/Sites/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Sites/Services/Http.php @@ -16,6 +16,7 @@ use Appwrite\Platform\Modules\Sites\Http\Sites\DeleteSite; use Appwrite\Platform\Modules\Sites\Http\Sites\GetSite; use Appwrite\Platform\Modules\Sites\Http\Sites\GetSitesUsage; use Appwrite\Platform\Modules\Sites\Http\Sites\GetSiteUsage; +use Appwrite\Platform\Modules\Sites\Http\Sites\GetTemplate; use Appwrite\Platform\Modules\Sites\Http\Sites\ListFrameworks; use Appwrite\Platform\Modules\Sites\Http\Sites\ListSites; use Appwrite\Platform\Modules\Sites\Http\Sites\ListTemplates; @@ -60,7 +61,10 @@ class Http extends Service $this->addAction(ListVariables::getName(), new ListVariables()); $this->addAction(UpdateVariable::getName(), new UpdateVariable()); $this->addAction(DeleteVariable::getName(), new DeleteVariable()); + + // Templates $this->addAction(ListTemplates::getName(), new ListTemplates()); + $this->addAction(GetTemplate::getName(), new GetTemplate()); // Usage $this->addAction(GetSiteUsage::getName(), new GetSiteUsage());