mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Add getTemplate endpoint for sites
This commit is contained in:
@@ -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 => [
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Sites\Http\Sites;
|
||||
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Platform\Modules\Compute\Base;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Platform\Action;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
use Utopia\Validator\Text;
|
||||
|
||||
class GetTemplate extends Base
|
||||
{
|
||||
use HTTP;
|
||||
|
||||
public static function getName()
|
||||
{
|
||||
return 'getTemplate';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->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);
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user