mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Formatting fix
This commit is contained in:
@@ -208,7 +208,7 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw
|
||||
'site' => $runtimes[$resource->getAttribute('buildRuntime')] ?? null,
|
||||
default => null
|
||||
};
|
||||
|
||||
|
||||
// Static site enforced runtime
|
||||
if ($resource->getAttribute('adapter', '') === 'static') {
|
||||
$runtime = $runtimes['static-1'] ?? null;
|
||||
|
||||
@@ -6,7 +6,6 @@ use Appwrite\ID;
|
||||
use Tests\E2E\Client;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Domains\Contact;
|
||||
use Utopia\Platform\Action;
|
||||
use Utopia\Validator\Text;
|
||||
|
||||
@@ -28,7 +27,7 @@ class Screenshot extends Action
|
||||
public function action(string $templateId): void
|
||||
{
|
||||
$templates = Config::getParam('site-templates', []);
|
||||
|
||||
|
||||
$allowedTemplates = \array_filter($templates, function ($item) use ($templateId) {
|
||||
return $item['key'] === $templateId;
|
||||
});
|
||||
@@ -37,13 +36,13 @@ class Screenshot extends Action
|
||||
if (empty($template)) {
|
||||
throw new \Exception("Template {$templateId} not found. Find correct ID in app/config/site-templates.php");
|
||||
}
|
||||
|
||||
|
||||
Console::info("Found: " . $template['name']);
|
||||
|
||||
|
||||
$client = new Client();
|
||||
$client->setEndpoint('http://localhost/v1');
|
||||
$client->addHeader('origin', 'http://localhost');
|
||||
|
||||
|
||||
// Register
|
||||
$email = uniqid() . 'user@localhost.test';
|
||||
$password = 'password';
|
||||
@@ -55,14 +54,14 @@ class Screenshot extends Action
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
|
||||
if($user['headers']['status-code'] !== 201) {
|
||||
|
||||
if ($user['headers']['status-code'] !== 201) {
|
||||
Console::error(\json_encode($user));
|
||||
throw new \Exception("Failed to register user");
|
||||
}
|
||||
|
||||
|
||||
Console::info("User created");
|
||||
|
||||
|
||||
// Login
|
||||
$session = $client->call(Client::METHOD_POST, '/account/sessions/email', [
|
||||
'content-type' => 'application/json',
|
||||
@@ -71,17 +70,17 @@ class Screenshot extends Action
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
|
||||
if($session['headers']['status-code'] !== 201) {
|
||||
|
||||
if ($session['headers']['status-code'] !== 201) {
|
||||
Console::error(\json_encode($session));
|
||||
throw new \Exception("Failed to login user");
|
||||
}
|
||||
|
||||
|
||||
Console::info("Session created");
|
||||
|
||||
|
||||
$secret = $session['cookies']['a_session_console'];
|
||||
$cookieConsole = 'a_session_console=' . $secret;
|
||||
|
||||
$cookieConsole = 'a_session_console=' . $secret;
|
||||
|
||||
// Create organization
|
||||
$team = $client->call(Client::METHOD_POST, '/teams', [
|
||||
'content-type' => 'application/json',
|
||||
@@ -91,17 +90,17 @@ class Screenshot extends Action
|
||||
'teamId' => ID::unique(),
|
||||
'name' => 'Demo Project Team',
|
||||
]);
|
||||
|
||||
if($team['headers']['status-code'] !== 201) {
|
||||
|
||||
if ($team['headers']['status-code'] !== 201) {
|
||||
Console::error(\json_encode($team));
|
||||
throw new \Exception("Failed to create team");
|
||||
}
|
||||
|
||||
|
||||
Console::info("Team created");
|
||||
|
||||
|
||||
$projectName = 'Demo Project';
|
||||
$projectId = ID::unique();
|
||||
|
||||
|
||||
// Create project
|
||||
$project = $client->call(Client::METHOD_POST, '/projects', [
|
||||
'content-type' => 'application/json',
|
||||
@@ -116,17 +115,17 @@ class Screenshot extends Action
|
||||
'url' => 'https://appwrite.io',
|
||||
]);
|
||||
|
||||
if($project['headers']['status-code'] !== 201) {
|
||||
if ($project['headers']['status-code'] !== 201) {
|
||||
Console::error(\json_encode($project));
|
||||
throw new \Exception("Failed to create project");
|
||||
}
|
||||
|
||||
|
||||
Console::info("Project created");
|
||||
|
||||
$projectId = $project['body']['$id'];
|
||||
|
||||
|
||||
$framework = $template['frameworks'][0];
|
||||
|
||||
|
||||
// Create site
|
||||
$site = $client->call(Client::METHOD_POST, '/sites', [
|
||||
'content-type' => 'application/json',
|
||||
@@ -146,32 +145,32 @@ class Screenshot extends Action
|
||||
'providerRootDirectory' => $framework['providerRootDirectory'],
|
||||
'timeout' => 60
|
||||
]);
|
||||
|
||||
if($site['headers']['status-code'] !== 201) {
|
||||
|
||||
if ($site['headers']['status-code'] !== 201) {
|
||||
Console::error(\json_encode($site));
|
||||
throw new \Exception("Failed to create site");
|
||||
}
|
||||
|
||||
|
||||
Console::info("Site created");
|
||||
|
||||
|
||||
$siteId = $site['body']['$id'];
|
||||
|
||||
// Create variables
|
||||
if(!empty($template['variables'] ?? [])) {
|
||||
foreach($template['variables'] as $variable) {
|
||||
if(empty($variable['value'] ?? '')) {
|
||||
if(($variable['required'] ?? false) === true) {
|
||||
if (!empty($template['variables'] ?? [])) {
|
||||
foreach ($template['variables'] as $variable) {
|
||||
if (empty($variable['value'] ?? '')) {
|
||||
if (($variable['required'] ?? false) === true) {
|
||||
throw new \Exception("Missing required variable: {$variable['name']}");
|
||||
}
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$value = $variable['value'];
|
||||
$value = \str_replace('{projectName}', $projectName, $value);
|
||||
$value = \str_replace('{projectId}', $projectId, $value);
|
||||
$value = \str_replace('{apiEndpoint}', 'http://localhost/v1', $value);
|
||||
|
||||
|
||||
$response = $client->call(Client::METHOD_POST, '/sites/' . $siteId . '/variables', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
@@ -181,8 +180,8 @@ class Screenshot extends Action
|
||||
'key' => $variable['name'],
|
||||
'value' => $value
|
||||
]);
|
||||
|
||||
if($response['headers']['status-code'] !== 201) {
|
||||
|
||||
if ($response['headers']['status-code'] !== 201) {
|
||||
Console::error(\json_encode($response));
|
||||
throw new \Exception("Failed to create variable");
|
||||
}
|
||||
@@ -190,7 +189,7 @@ class Screenshot extends Action
|
||||
|
||||
Console::info("Variables created");
|
||||
}
|
||||
|
||||
|
||||
// Create deployment
|
||||
$deployment = $client->call(Client::METHOD_POST, '/sites/' . $siteId . '/deployments/template', [
|
||||
'content-type' => 'application/json',
|
||||
@@ -204,98 +203,98 @@ class Screenshot extends Action
|
||||
'version' => $template['providerVersion'],
|
||||
'activate' => true,
|
||||
]);
|
||||
|
||||
if($deployment['headers']['status-code'] !== 202) {
|
||||
|
||||
if ($deployment['headers']['status-code'] !== 202) {
|
||||
Console::error(\json_encode($deployment));
|
||||
throw new \Exception("Failed to create deployment");
|
||||
}
|
||||
|
||||
|
||||
Console::info("Deployment created");
|
||||
|
||||
|
||||
$deploymentId = $deployment['body']['$id'];
|
||||
|
||||
|
||||
// Await screenshot
|
||||
$attempts = 50;
|
||||
$sleep = 5;
|
||||
|
||||
|
||||
$idLight = '';
|
||||
$idDark = '';
|
||||
|
||||
|
||||
Console::log("Awaiting deployment (every $sleep seconds, $attempts attempts)");
|
||||
|
||||
for($i = 0; $i < $attempts; $i++) {
|
||||
|
||||
for ($i = 0; $i < $attempts; $i++) {
|
||||
$deployment = $client->call(Client::METHOD_GET, '/sites/' . $siteId . '/deployments/' . $deploymentId, [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-mode' => 'admin',
|
||||
'cookie' => $cookieConsole
|
||||
]);
|
||||
|
||||
if($deployment['headers']['status-code'] !== 200) {
|
||||
|
||||
if ($deployment['headers']['status-code'] !== 200) {
|
||||
Console::error(\json_encode($deployment));
|
||||
throw new \Exception("Failed to get deployment");
|
||||
}
|
||||
|
||||
if($deployment['body']['status'] === 'failed') {
|
||||
|
||||
if ($deployment['body']['status'] === 'failed') {
|
||||
Console::error(\json_encode($deployment));
|
||||
throw new \Exception("Deployment build failed");
|
||||
}
|
||||
|
||||
if($deployment['body']['status'] !== 'ready') {
|
||||
|
||||
if ($deployment['body']['status'] !== 'ready') {
|
||||
Console::log("Deployment not ready yet, status: " . $deployment['body']['status']);
|
||||
\sleep($sleep);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if(empty($deployment['body']['screenshotLight'])) {
|
||||
|
||||
if (empty($deployment['body']['screenshotLight'])) {
|
||||
Console::log("Light screenshot not available yet");
|
||||
\sleep($sleep);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(empty($deployment['body']['screenshotDark'])) {
|
||||
|
||||
if (empty($deployment['body']['screenshotDark'])) {
|
||||
Console::log("Dark screenshot not available yet");
|
||||
\sleep($sleep);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$idLight = $deployment['body']['screenshotLight'];
|
||||
$idDark = $deployment['body']['screenshotDark'];
|
||||
break;
|
||||
}
|
||||
|
||||
if(empty($idLight) || empty($idDark)) {
|
||||
|
||||
if (empty($idLight) || empty($idDark)) {
|
||||
Console::error(\json_encode($deployment));
|
||||
throw new \Exception("Failed to get deployment screenshot");
|
||||
}
|
||||
|
||||
|
||||
Console::info("Screenshots created");
|
||||
|
||||
|
||||
$themes = [
|
||||
[ 'fileId' => $idLight, 'suffix' => 'light' ],
|
||||
[ 'fileId' => $idDark, 'suffix' => 'dark' ]
|
||||
];
|
||||
|
||||
foreach($themes as $theme) {
|
||||
|
||||
foreach ($themes as $theme) {
|
||||
$file = $client->call(Client::METHOD_GET, '/storage/buckets/screenshots/files/' . $theme['fileId'] . '/download', [
|
||||
'x-appwrite-project' => 'console',
|
||||
'x-appwrite-mode' => 'admin',
|
||||
'cookie' => $cookieConsole
|
||||
]);
|
||||
|
||||
if($file['headers']['status-code'] !== 200) {
|
||||
|
||||
if ($file['headers']['status-code'] !== 200) {
|
||||
Console::error(\json_encode($file));
|
||||
throw new \Exception("Failed to download {$theme['suffix']} screenshot");
|
||||
}
|
||||
|
||||
|
||||
$path = "/usr/src/code/public/images/sites/templates/{$template['key']}-{$theme['suffix']}.png";
|
||||
|
||||
if(!\file_put_contents($path, $file['body'])) {
|
||||
|
||||
if (!\file_put_contents($path, $file['body'])) {
|
||||
throw new \Exception("Failed to save {$theme['suffix']} screenshot");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Console::success("Screenshots saved");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user