From b3fbb7c40dd3389c4fa0d43028edaedec3b8067f Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 4 Mar 2022 11:57:44 +0545 Subject: [PATCH 1/3] fix mock upload --- app/controllers/mock.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/controllers/mock.php b/app/controllers/mock.php index 8d85b94578..0d02bab183 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -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', From 57f410cb5fc2976b9f85c62a960b44f1fc5108d6 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 4 Mar 2022 11:59:20 +0545 Subject: [PATCH 2/3] fix mock upload --- app/controllers/mock.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/controllers/mock.php b/app/controllers/mock.php index 0d02bab183..d04ad016d0 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -290,9 +290,9 @@ 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') { @@ -305,11 +305,9 @@ App::post('/v1/mock/tests/general/upload') 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); } } }); From 2096c5c8b85d22eaf1e91a8ab5549f68464469a1 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 4 Mar 2022 12:03:10 +0545 Subject: [PATCH 3/3] fix --- app/controllers/mock.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/controllers/mock.php b/app/controllers/mock.php index d04ad016d0..69bbe8d68a 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -294,16 +294,12 @@ App::post('/v1/mock/tests/general/upload') $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); - } } if (\md5(\file_get_contents($file['tmp_name'])) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') {