From 4ed08cefa7c97e2a236d47e3356b9604440cd6b0 Mon Sep 17 00:00:00 2001
From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com>
Date: Fri, 25 Oct 2024 18:04:32 +0200
Subject: [PATCH] Fix getTemplate endpoint
---
app/config/site-templates.php | 40 +++++++++++++------
app/controllers/api/functions.php | 4 +-
.../Modules/Sites/Http/Sites/GetTemplate.php | 4 +-
3 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/app/config/site-templates.php b/app/config/site-templates.php
index baaf78469f..f1454433af 100644
--- a/app/config/site-templates.php
+++ b/app/config/site-templates.php
@@ -9,18 +9,16 @@ const TEMPLATE_FRAMEWORKS = [
],
];
-function getFrameworks($framework, $installCommand, $buildCommand, $outputDirectory, $fallbackRedirect, $providerRootDirectory)
+function getFramework($framework, $installCommand, $buildCommand, $outputDirectory, $fallbackRedirect, $providerRootDirectory)
{
- return array_map(function ($version) use ($framework, $installCommand, $buildCommand, $outputDirectory, $fallbackRedirect, $providerRootDirectory) {
- return [
- 'name' => $framework['name'],
- 'installCommand' => $installCommand,
- 'buildCommand' => $buildCommand,
- 'outputDirectory' => $outputDirectory,
- 'fallbackRedirect' => $fallbackRedirect,
- 'providerRootDirectory' => $providerRootDirectory
- ];
- }, $framework);
+ return [
+ 'name' => $framework['name'],
+ 'installCommand' => $installCommand,
+ 'buildCommand' => $buildCommand,
+ 'outputDirectory' => $outputDirectory,
+ 'fallbackRedirect' => $fallbackRedirect,
+ 'providerRootDirectory' => $providerRootDirectory
+ ];
}
return [
@@ -32,7 +30,25 @@ return [
'A simple site to get started. Edit this site to explore endless possibilities with Appwrite Sites.',
'useCases' => ['starter'],
'frameworks' => [
- ...getFrameworks(TEMPLATE_FRAMEWORKS['SVELTEKIT'], 'npm install', 'npm run build', 'build', 'index.html', 'node/starter')
+ ...getFramework(TEMPLATE_FRAMEWORKS['SVELTEKIT'], 'npm install', 'npm run build', 'build', 'index.html', 'node/starter')
+ ],
+ 'instructions' => 'For documentation and instructions check out file.',
+ 'vcsProvider' => 'github',
+ 'providerRepositoryId' => 'templates',
+ 'providerOwner' => 'appwrite',
+ 'providerVersion' => '0.2.*',
+ 'variables' => [],
+ 'scopes' => ['users.read']
+ ],
+ [
+ 'icon' => 'icon-lightning-bolt',
+ 'id' => 'starter1',
+ 'name' => 'Starter1 site',
+ 'tagline' =>
+ 'A simple site to get started. Edit this site to explore endless possibilities with Appwrite Sites.',
+ 'useCases' => ['messaging'],
+ 'frameworks' => [
+ ...getFramework(TEMPLATE_FRAMEWORKS['SVELTEKIT'], 'npm install', 'npm run build', 'build', 'index.html', 'node/starter1')
],
'instructions' => 'For documentation and instructions check out file.',
'vcsProvider' => 'github',
diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php
index a942a18f35..8cfa9320f9 100644
--- a/app/controllers/api/functions.php
+++ b/app/controllers/api/functions.php
@@ -2615,8 +2615,8 @@ App::get('/v1/functions/templates/:templateId')
->action(function (string $templateId, Response $response) {
$templates = Config::getParam('function-templates', []);
- $template = array_shift(\array_filter($templates, function ($template) use ($templateId) {
- return $template['id'] === $templateId;
+ $template = array_shift(array_filter($templates, function ($item) use ($templateId) {
+ return $item['id'] === $templateId;
}));
if (empty($template)) {
diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/GetTemplate.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/GetTemplate.php
index f8134f71c8..56277fb7d3 100644
--- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/GetTemplate.php
+++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/GetTemplate.php
@@ -44,8 +44,8 @@ class GetTemplate extends Base
{
$templates = Config::getParam('site-templates', []);
- $template = array_shift(\array_filter($templates, function ($template) use ($templateId) {
- return $template['id'] === $templateId;
+ $template = array_shift(\array_filter($templates, function ($item) use ($templateId) {
+ return $item['id'] === $templateId;
}));
if (empty($template)) {