1
0
Fork 0
mirror of synced 2024-05-20 04:32:37 +12:00

Added latest versions endpoint

This commit is contained in:
Eldad Fux 2021-02-24 20:31:43 +02:00
parent bf2a17139a
commit b8518ed6f5
2 changed files with 75 additions and 0 deletions

View file

@ -375,4 +375,40 @@ App::get('/specs/:format')
$response
->json($specs->parse());
});
App::get('/versions')
->desc('Get Version')
->groups(['web', 'home'])
->label('scope', 'public')
->inject('response')
->action(function ($response) {
/** @var Appwrite\Utopia\Response $response */
$platforms = Config::getParam('platforms');
$versions = [
'server' => APP_VERSION_STABLE,
];
foreach($platforms as $platform) {
$languages = $platform['languages'] ?? [];
foreach ($languages as $key => $language) {
if(isset($language['dev']) && $language['dev']) {
continue;
}
if(isset($language['enabled']) && !$language['enabled']) {
continue;
}
$platformKey = $platform['key'] ?? '';
$languageKey = $language['key'] ?? '';
$version = $language['version'] ?? '';
$versions[$platformKey . '-' . $languageKey] = $version;
}
}
$response->json($versions);
});

View file

@ -186,4 +186,43 @@ class HTTPTest extends Scope
$this->assertEquals($body['continents']['AN'], 'Antarctica');
$this->assertEquals($body['continents']['AS'], 'Asia');
}
public function testVersions() {
/**
* Test without header
*/
$response = $this->client->call(Client::METHOD_GET, '/versions', array_merge([
'content-type' => 'application/json',
], $this->getHeaders()));
$body = $response['body'];
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsString($body['server']);
$this->assertIsString($body['client-web']);
$this->assertIsString($body['client-flutter']);
$this->assertIsString($body['console-web']);
$this->assertIsString($body['server-nodejs']);
$this->assertIsString($body['server-deno']);
$this->assertIsString($body['server-php']);
$this->assertIsString($body['server-python']);
$this->assertIsString($body['server-ruby']);
$this->assertIsString($body['server-cli']);
/**
* Test with header
*/
$response = $this->client->call(Client::METHOD_GET, '/locale/continents', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => 'console',
'x-appwrite-response-format' => '0.6.2'
], $this->getHeaders()));
$body = $response['body'];
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals($body['sum'], 7);
$this->assertEquals($body['continents']['AF'], 'Africa');
$this->assertEquals($body['continents']['AN'], 'Antarctica');
$this->assertEquals($body['continents']['AS'], 'Asia');
}
}