1
0
Fork 0
mirror of synced 2024-07-05 22:51:24 +12:00

Merge pull request #2896 from appwrite/fix-mock-chunked-upload

fix mock upload
This commit is contained in:
Eldad A. Fux 2022-03-04 11:56:05 +02:00 committed by GitHub
commit 2bdd158b74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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