mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 01:18:37 +00:00
AI code quality fixes
This commit is contained in:
parent
d502ab0cd5
commit
52ccbfcdf7
1 changed files with 18 additions and 11 deletions
|
|
@ -32,8 +32,15 @@ class Screenshot extends Action
|
||||||
|
|
||||||
public function action(string $templateId, string $variables): void
|
public function action(string $templateId, string $variables): void
|
||||||
{
|
{
|
||||||
$variables = \json_decode($variables, true);
|
if (empty($variables)) {
|
||||||
if(!\is_array($variables)) {
|
$variables = [];
|
||||||
|
} else {
|
||||||
|
$variables = \json_decode($variables, true);
|
||||||
|
if (!\is_array($variables)) {
|
||||||
|
throw new \Exception('Invalid JSON in --variables flag');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($variables === null) {
|
||||||
throw new \Exception('Invalid JSON in --variables flag');
|
throw new \Exception('Invalid JSON in --variables flag');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,7 +147,7 @@ class Screenshot extends Action
|
||||||
$projectId = $project['body']['$id'];
|
$projectId = $project['body']['$id'];
|
||||||
|
|
||||||
$framework = $template['frameworks'][0];
|
$framework = $template['frameworks'][0];
|
||||||
|
|
||||||
// Use best specifications to prevent out-of-memory during build
|
// Use best specifications to prevent out-of-memory during build
|
||||||
$specifications = Config::getParam('specifications', []);
|
$specifications = Config::getParam('specifications', []);
|
||||||
$specifications = array_keys($specifications);
|
$specifications = array_keys($specifications);
|
||||||
|
|
@ -175,7 +182,7 @@ class Screenshot extends Action
|
||||||
Console::info("Site created");
|
Console::info("Site created");
|
||||||
|
|
||||||
$siteId = $site['body']['$id'];
|
$siteId = $site['body']['$id'];
|
||||||
|
|
||||||
// Prepare API key, incase it's needed as variable
|
// Prepare API key, incase it's needed as variable
|
||||||
$response = $client->call(Client::METHOD_POST, '/projects/' . $projectId . '/keys', [
|
$response = $client->call(Client::METHOD_POST, '/projects/' . $projectId . '/keys', [
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
|
|
@ -185,32 +192,32 @@ class Screenshot extends Action
|
||||||
'name' => 'Screenshot API key',
|
'name' => 'Screenshot API key',
|
||||||
'scopes' => \array_keys(Config::getParam('scopes', []))
|
'scopes' => \array_keys(Config::getParam('scopes', []))
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($response['headers']['status-code'] !== 201) {
|
if ($response['headers']['status-code'] !== 201) {
|
||||||
Console::error(\json_encode($response));
|
Console::error(\json_encode($response));
|
||||||
throw new \Exception("Failed to create API key");
|
throw new \Exception("Failed to create API key");
|
||||||
}
|
}
|
||||||
|
|
||||||
$apiKey = $response['body']['secret'];
|
$apiKey = $response['body']['secret'];
|
||||||
|
|
||||||
Console::info("API key created");
|
Console::info("API key created");
|
||||||
|
|
||||||
$variables['APPWRITE_API_KEY'] = $apiKey;
|
$variables['APPWRITE_API_KEY'] = $apiKey;
|
||||||
|
|
||||||
// Create variables
|
// Create variables
|
||||||
if (!empty($template['variables'] ?? [])) {
|
if (!empty($template['variables'] ?? [])) {
|
||||||
foreach ($template['variables'] as $variable) {
|
foreach ($template['variables'] as $variable) {
|
||||||
$name = $variable['name'];
|
$name = $variable['name'];
|
||||||
|
|
||||||
$value = $variable['value'];
|
$value = $variable['value'];
|
||||||
$value = \str_replace('{projectName}', $projectName, $value);
|
$value = \str_replace('{projectName}', $projectName, $value);
|
||||||
$value = \str_replace('{projectId}', $projectId, $value);
|
$value = \str_replace('{projectId}', $projectId, $value);
|
||||||
$value = \str_replace('{apiEndpoint}', 'http://' . System::getEnv('_APP_DOMAIN', '') . '/v1', $value);
|
$value = \str_replace('{apiEndpoint}', 'http://' . System::getEnv('_APP_DOMAIN', '') . '/v1', $value);
|
||||||
|
|
||||||
if(\array_key_exists($name, $variables)) {
|
if (\array_key_exists($name, $variables)) {
|
||||||
$value = $variables[$name];
|
$value = $variables[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($value)) {
|
if (empty($value)) {
|
||||||
if (($variable['required'] ?? false) === true) {
|
if (($variable['required'] ?? false) === true) {
|
||||||
throw new \Exception("Missing required variable: {$variable['name']}. Provide it using the --variables flag to resolve this.");
|
throw new \Exception("Missing required variable: {$variable['name']}. Provide it using the --variables flag to resolve this.");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue