Merge branch 'master' of https://github.com/appwrite/appwrite into chore-prepare-0-13-1

This commit is contained in:
Torsten Dittmann 2022-03-04 14:22:29 +01:00
commit 2fd6dc9fa1
11 changed files with 62 additions and 60 deletions

View file

@ -63,7 +63,7 @@ return [
[
'key' => 'flutter',
'name' => 'Flutter',
'version' => '4.0.0',
'version' => '4.0.1',
'url' => 'https://github.com/appwrite/sdk-for-flutter',
'package' => 'https://pub.dev/packages/appwrite',
'enabled' => true,
@ -352,7 +352,7 @@ return [
[
'key' => 'dart',
'name' => 'Dart',
'version' => '4.0.0',
'version' => '4.0.1',
'url' => 'https://github.com/appwrite/sdk-for-dart',
'package' => 'https://pub.dev/packages/dart_appwrite',
'enabled' => true,

View file

@ -252,7 +252,7 @@ App::post('/v1/mock/tests/general/upload')
$end = $request->getContentRangeEnd();
$size = $request->getContentRangeSize();
$id = $request->getHeader('x-appwrite-id', '');
$file['size'] = (\is_array($file['size'])) ? $file['size'] : [$file['size']];
$file['size'] = (\is_array($file['size'])) ? $file['size'][0] : $file['size'];
if(is_null($start) || is_null($end) || is_null($size)) {
throw new Exception('Invalid content-range header', 400, Exception::GENERAL_MOCK);
@ -274,15 +274,14 @@ App::post('/v1/mock/tests/general/upload')
throw new Exception('Chunk size must be 5MB (except last chunk)', 400, Exception::GENERAL_MOCK);
}
foreach ($file['size'] as $i => $sz) {
if ($end !== $size && $sz !== $chunkSize) {
throw new Exception('Wrong chunk size', 400, Exception::GENERAL_MOCK);
}
if($sz > $chunkSize) {
throw new Exception('Chunk size must be 5MB or less', 400, Exception::GENERAL_MOCK);
}
if ($end !== $size && $file['size'] !== $chunkSize) {
throw new Exception('Wrong chunk size', 400, Exception::GENERAL_MOCK);
}
if($file['size'] > $chunkSize) {
throw new Exception('Chunk size must be 5MB or less', 400, Exception::GENERAL_MOCK);
}
if($end !== $size) {
$response->json([
'$id'=> 'newfileid',
@ -291,26 +290,20 @@ App::post('/v1/mock/tests/general/upload')
]);
}
} else {
$file['tmp_name'] = (\is_array($file['tmp_name'])) ? $file['tmp_name'] : [$file['tmp_name']];
$file['name'] = (\is_array($file['name'])) ? $file['name'] : [$file['name']];
$file['size'] = (\is_array($file['size'])) ? $file['size'] : [$file['size']];
$file['tmp_name'] = (\is_array($file['tmp_name'])) ? $file['tmp_name'][0] : $file['tmp_name'];
$file['name'] = (\is_array($file['name'])) ? $file['name'][0] : $file['name'];
$file['size'] = (\is_array($file['size'])) ? $file['size'][0] : $file['size'];
foreach ($file['name'] as $i => $name) {
if ($name !== 'file.png') {
throw new Exception('Wrong file name', 400, Exception::GENERAL_MOCK);
}
if ($file['name'] !== 'file.png') {
throw new Exception('Wrong file name', 400, Exception::GENERAL_MOCK);
}
foreach ($file['size'] as $i => $size) {
if ($size !== 38756) {
if ($file['size'] !== 38756) {
throw new Exception('Wrong file size', 400, Exception::GENERAL_MOCK);
}
}
foreach ($file['tmp_name'] as $i => $tmpName) {
if (\md5(\file_get_contents($tmpName)) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') {
throw new Exception('Wrong file uploaded', 400, Exception::GENERAL_MOCK);
}
if (\md5(\file_get_contents($file['tmp_name'])) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') {
throw new Exception('Wrong file uploaded', 400, Exception::GENERAL_MOCK);
}
}
});

View file

@ -25,14 +25,14 @@ use Utopia\Swoole\Response;
use Utopia\Validator\ArrayList;
use Utopia\Validator\Assoc;
use Utopia\Validator\Boolean;
use Utopia\Validator\Range as ValidatorRange;
use Utopia\Validator\Range;
use Utopia\Validator\Text;
Runtime::enableCoroutine(true, SWOOLE_HOOK_ALL);
/** Constants */
const MAINTENANCE_INTERVAL = 1200; // 20 minutes
const MAINTENANCE_INTERVAL = 3600; // 3600 seconds = 1 hour
/**
* Create a Swoole table to store runtime information
@ -395,9 +395,9 @@ App::delete('/v1/runtimes/:runtimeId')
App::post('/v1/execution')
->desc('Create an execution')
->param('runtimeId', '', new Text(64), 'The runtimeID to execute')
->param('vars', [], new Assoc(), 'Environment variables required for the build', false)
->param('data', '', new Text(8192), 'Data to be forwarded to the function, this is user specified.', true)
->param('timeout', 15, new ValidatorRange(1, 900), 'Function maximum execution time in seconds.', true)
->param('vars', [], new Assoc(), 'Environment variables required for the build')
->param('data', '{}', new Text(8192), 'Data to be forwarded to the function, this is user specified.', true)
->param('timeout', 15, new Range(1, (int) App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900)), 'Function maximum execution time in seconds.')
->inject('activeRuntimes')
->inject('response')
->action(
@ -423,17 +423,19 @@ App::post('/v1/execution')
$errNo = -1;
$executorResponse = '';
$timeout ??= (int) App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900);
$ch = \curl_init();
$body = \json_encode([
'env' => $vars,
'payload' => $data,
'timeout' => $timeout ?? (int) App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900)
'timeout' => $timeout
]);
\curl_setopt($ch, CURLOPT_URL, "http://" . $runtimeId . ":3000/");
\curl_setopt($ch, CURLOPT_POST, true);
\curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
\curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ?? (int) App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900));
\curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
\curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
\curl_setopt($ch, CURLOPT_HTTPHEADER, [

View file

@ -12,7 +12,7 @@ void main() { // Init SDK
Future result = storage.createFile(
bucketId: '[BUCKET_ID]',
fileId: '[FILE_ID]',
file: await MultipartFile.fromPath('file', './path-to-files/image.jpg', 'image.jpg'),
file: InputFile(path: './path-to-files/image.jpg', filename: 'image.jpg'),
);
result

View file

@ -13,7 +13,7 @@ void main() { // Init SDK
Future result = functions.createDeployment(
functionId: '[FUNCTION_ID]',
entrypoint: '[ENTRYPOINT]',
code: await MultipartFile.fromPath('code', './path-to-files/image.jpg', 'image.jpg'),
code: InputFile(path: './path-to-files/image.jpg', filename: 'image.jpg'),
activate: false,
);

View file

@ -14,7 +14,7 @@ void main() { // Init SDK
Future result = storage.createFile(
bucketId: '[BUCKET_ID]',
fileId: '[FILE_ID]',
file: await MultipartFile.fromPath('file', './path-to-files/image.jpg', 'image.jpg'),
file: InputFile(path: './path-to-files/image.jpg', filename: 'image.jpg'),
);
result

View file

@ -1,3 +1,7 @@
## 4.0.1
* Fix InputFile filename param
* Fix examples
## 4.0.0
* Support for Appwrite 0.13
* **BREAKING** **Tags** have been renamed to **Deployments**

View file

@ -41,7 +41,7 @@ Upload File:
```dart
Storage storage = Storage(client);
InputFile file = InputFile(path: './path-to-file/image.jpg', fileName: 'image.jpg');
InputFile file = InputFile(path: './path-to-file/image.jpg', filename: 'image.jpg');
storage.createFile(
bucketId: '[BUCKET_ID]',

View file

@ -1,3 +1,7 @@
## 4.0.1
* Fix InputFile filename param
* Fix examples
## 4.0.0
* Support for Appwrite 0.13
* **BREAKING** **Tags** have been renamed to **Deployments**

View file

@ -40,9 +40,9 @@ Storage storage = Storage(client);
late InputFile file;
if(kIsWeb) {
file = InputFile(file: MultipartFile.fromFile('./path-to-file/image.jpg', filename: 'image.jpg'));
file = InputFile(file: await MultipartFile.fromFile('file', './path-to-file/image.jpg', filename: 'image.jpg'));
} else {
file = InputFile(path: './path-to-file/image.jpg', fileName: 'image.jpg');
file = InputFile(path: './path-to-file/image.jpg', filename: 'image.jpg');
}
storage.createFile(

View file

@ -82,7 +82,9 @@ class Executor
'commands' => $commands
];
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900));
$timeout = (int) App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900);
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, $timeout);
$status = $response['headers']['status-code'];
if ($status >= 400) {
@ -159,13 +161,18 @@ class Executor
'timeout' => $timeout,
];
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, 30);
/* Add 2 seconds as a buffer to the actual timeout value since there can be a slight variance*/
$requestTimeout = $timeout + 2;
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, $requestTimeout);
$status = $response['headers']['status-code'];
if ($status >= 400) {
for ($attempts = 0; $attempts < 10; $attempts++) {
switch ($status) {
case 404:
for ($attempts = 0; $attempts < 10; $attempts++) {
try {
switch (true) {
case $status < 400:
return $response['body'];
case $status === 404:
$response = $this->createRuntime(
deploymentId: $deploymentId,
projectId: $projectId,
@ -176,31 +183,23 @@ class Executor
entrypoint: $entrypoint,
commands: []
);
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, 30);
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, $requestTimeout);
$status = $response['headers']['status-code'];
break;
case 406:
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, 30);
case $status === 406:
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, $requestTimeout);
$status = $response['headers']['status-code'];
break;
default:
throw new \Exception($response['body']['message'], $status);
}
if ($status < 400) {
return $response['body'];
}
if ($status != 406) {
throw new \Exception($response['body']['message'], $status);
}
sleep(2);
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), $e->getCode());
}
throw new Exception($response['body']['message'], 503);
sleep(2);
}
return $response['body'];
throw new Exception($response['body']['message'], 503);
}
/**