Fix getTemplate endpoint

This commit is contained in:
Khushboo Verma
2024-10-25 18:04:32 +02:00
parent 1a33a0c4d1
commit 4ed08cefa7
3 changed files with 32 additions and 16 deletions
+28 -12
View File
@@ -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 <a target="_blank" rel="noopener noreferrer" class="link" href="https://github.com/appwrite/templates/tree/main/node/starter">file</a>.',
'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 <a target="_blank" rel="noopener noreferrer" class="link" href="https://github.com/appwrite/templates/tree/main/node/starter">file</a>.',
'vcsProvider' => 'github',
+2 -2
View File
@@ -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)) {
@@ -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)) {