From 947d9dc57a9a040a2a67d7e8a4f998cb73a9523c Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 16 Feb 2022 09:39:06 +0000 Subject: [PATCH 1/5] limit preview to 10 MB --- app/controllers/api/storage.php | 4 ++++ app/init.php | 1 + docs/references/storage/get-file-preview.md | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index ff0ae96aa..c8441c971 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -909,6 +909,10 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview') throw new Exception('File not found', 404); } + if($file->getAttribute('sizeActual') > APP_LIMIT_PREVIEW) { + throw new Exception('Preview not supported for file above ' . Storage::human(APP_LIMIT_PREVIEW) . ' in size.'); + } + $path = $file->getAttribute('path'); $type = \strtolower(\pathinfo($path, PATHINFO_EXTENSION)); $algorithm = $file->getAttribute('algorithm'); diff --git a/app/init.php b/app/init.php index 1b4b0f18b..92ae380fb 100644 --- a/app/init.php +++ b/app/init.php @@ -67,6 +67,7 @@ const APP_LIMIT_USERS = 10000; const APP_LIMIT_ANTIVIRUS = 20000000; //20MB const APP_LIMIT_ENCRYPTION = 20000000; //20MB const APP_LIMIT_COMPRESSION = 20000000; //20MB +const APP_LIMIT_PREVIEW = 10000000; //10MB file size limit for preview endpoint const APP_CACHE_BUSTER = 201; const APP_VERSION_STABLE = '0.13.0'; const APP_DATABASE_ATTRIBUTE_EMAIL = 'email'; diff --git a/docs/references/storage/get-file-preview.md b/docs/references/storage/get-file-preview.md index a6f4a6186..415250b80 100644 --- a/docs/references/storage/get-file-preview.md +++ b/docs/references/storage/get-file-preview.md @@ -1 +1 @@ -Get a file preview image. Currently, this method supports preview for image files (jpg, png, and gif), other supported formats, like pdf, docs, slides, and spreadsheets, will return the file icon image. You can also pass query string arguments for cutting and resizing your preview image. \ No newline at end of file +Get a file preview image. Currently, this method supports preview for image files (jpg, png, and gif), other supported formats, like pdf, docs, slides, and spreadsheets, will return the file icon image. You can also pass query string arguments for cutting and resizing your preview image. We do not support preview for file size above 10MB. \ No newline at end of file From e7a36f43025145ba20b46c57423c64ae9325ab63 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 16 Feb 2022 09:44:52 +0000 Subject: [PATCH 2/5] error code --- app/controllers/api/storage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index c8441c971..d0e8cb089 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -910,7 +910,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview') } if($file->getAttribute('sizeActual') > APP_LIMIT_PREVIEW) { - throw new Exception('Preview not supported for file above ' . Storage::human(APP_LIMIT_PREVIEW) . ' in size.'); + throw new Exception('Preview not supported for file above ' . Storage::human(APP_LIMIT_PREVIEW) . ' in size.', 400); } $path = $file->getAttribute('path'); From 54383d0fb9a6f492e08176a48577de19af0015f1 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 16 Feb 2022 15:45:40 +0545 Subject: [PATCH 3/5] added new image icon --- app/config/storage/logos/image.png | Bin 0 -> 9287 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 app/config/storage/logos/image.png diff --git a/app/config/storage/logos/image.png b/app/config/storage/logos/image.png new file mode 100644 index 0000000000000000000000000000000000000000..c046b4e6039fcb2a6ee254a59487bd12880e19c9 GIT binary patch literal 9287 zcmeI1dpOkF_s93pC?rZF(h2DtMNZRI7neyll^C~3G@}%$b8@;-8Kw?hP@JTzq7Z{Z zQXMoVC6_`SLq~EKnbPDk$t3ezYx4a*{rUa-_vCqcdiLkD-+R5*+G}4vYfdulR;#H@ zRw0C_t+83*NXV!xLKOAKD8Z9?&6gG6KV^TLje7}E)x>`kaw$$59#Zx?uC^w(DyMWo zW0cRb^~(s!j#3@+q7q{Gdd-Su&ViKf2G2bnK37V5WPd%DT%bj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+4Pv5Fvk4wgo1k)?h$@*}1GNy4}UKu5SZ?7P)YMtEIP`8GV?zaavk5tF%u5?RR z&LZ=Z;tvK9hOsA!eioBbBD*B>HzM3uS1j*`eC#9gD&Ja9_##eF+uTQym-F`3hCsRO zzvaBtcZaZ^r_loul9kw*@`69uBik{(0eSc$IvH0L6TeE|3`20z0rkZ z$QdUrpGJM2MYxCFKkg&!iNN~T`-;|TC{|{FS#Ca#tb!}Kc3Dfy!yWq?c~tJ?evYhr zDEI61Z-v$s9Pt%*l4|{OW;$h6yTJ!yc(}KsC*Va1RD{agTe=}X!2+Io+m@>u9jfLe=Q2WwLLY$$i| z;a3(Erfp&Wi9S-iS~;Mq^}(RMy&@@n*qf`v9Sd1EH~aJU#6HVm4I*fl{u=a7pRo!k zbOyifR_FJd!G+s>F{$D+nf{kz7j%GdKxOv%Oj5GiJ!F!%rq4QHd<{p8w>6Qs*NMJ+wkXxrSd}g zDRGDFPNO=}KlQS$W(|pk>IQg10A+KR4mPC!DFSZc3J%{mrfkOC0^VdI-4fu;pF$C7RxvX0Db>DDQ zf0P3Gd~!IaVdH?WXGyu|Ju4W>=+!sTkb3PhQcpQ29s9S7T=?Nf~hFq2G8Kmov`eDRjDYS#k);r zJnjm*BYpO$j`9lXD88?+mxsT#dVl?J$nb9QDAL|GKkviFrU4f3ru+xI=6{|>X@45% z*jk&}A>LD{OXz&~+03Nr(+i7v?vyMTp?PgYl+M*|(^VP6ABGyl0oMz)?@V+jV|Vm8 z2qyKtyd=)Q@}am=Ryn+G@2xPWg7h6?z)vMpeewpVW>%5*;*Wwu|yd+&mVt3BJd*u|9b@P_R73;tL+M= RKdM5}nw54dZdtRB{vX2%6gB_= literal 0 HcmV?d00001 From 193426e34b34d1ed5da6c65da656e2550d363a26 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 16 Feb 2022 10:04:49 +0000 Subject: [PATCH 4/5] show default image icon for large image files --- app/config/storage/logos.php | 1 + app/controllers/api/storage.php | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/config/storage/logos.php b/app/config/storage/logos.php index 3170762dc..39d8a40fa 100644 --- a/app/config/storage/logos.php +++ b/app/config/storage/logos.php @@ -2,6 +2,7 @@ return [ // Based on this list @see http://stackoverflow.com/a/4212908/2299554 'default' => __DIR__.'/logos/none.png', + 'default_image' => __DIR__.'/logos/image.png', // Video Files 'video/mp4' => __DIR__.'/logos/video.png', diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index d0e8cb089..a29901354 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -909,18 +909,20 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview') throw new Exception('File not found', 404); } - if($file->getAttribute('sizeActual') > APP_LIMIT_PREVIEW) { - throw new Exception('Preview not supported for file above ' . Storage::human(APP_LIMIT_PREVIEW) . ' in size.', 400); - } - $path = $file->getAttribute('path'); $type = \strtolower(\pathinfo($path, PATHINFO_EXTENSION)); $algorithm = $file->getAttribute('algorithm'); $cipher = $file->getAttribute('openSSLCipher'); $mime = $file->getAttribute('mimeType'); - if (!\in_array($mime, $inputs)) { - $path = (\array_key_exists($mime, $fileLogos)) ? $fileLogos[$mime] : $fileLogos['default']; + if (!\in_array($mime, $inputs) || $file->getAttribute('sizeActual') > APP_LIMIT_PREVIEW) { + if(!\in_array($mime, $inputs)) { + $path = (\array_key_exists($mime, $fileLogos)) ? $fileLogos[$mime] : $fileLogos['default']; + } else { + // it was an image but the file size exceeded the limit + $path = $fileLogos['default_image']; + } + $algorithm = null; $cipher = null; $background = (empty($background)) ? 'eceff1' : $background; @@ -928,6 +930,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview') $key = \md5($path . $width . $height . $gravity . $quality . $borderWidth . $borderColor . $borderRadius . $opacity . $rotation . $background . $output); } + $compressor = new GZIP(); if (!$deviceFiles->exists($path)) { From c567c818bb5ce9fc5479500af08604361e76ec4b Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 16 Feb 2022 16:01:36 +0545 Subject: [PATCH 5/5] Update docs/references/storage/get-file-preview.md Co-authored-by: Eldad A. Fux --- docs/references/storage/get-file-preview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/storage/get-file-preview.md b/docs/references/storage/get-file-preview.md index 415250b80..3876fd02e 100644 --- a/docs/references/storage/get-file-preview.md +++ b/docs/references/storage/get-file-preview.md @@ -1 +1 @@ -Get a file preview image. Currently, this method supports preview for image files (jpg, png, and gif), other supported formats, like pdf, docs, slides, and spreadsheets, will return the file icon image. You can also pass query string arguments for cutting and resizing your preview image. We do not support preview for file size above 10MB. \ No newline at end of file +Get a file preview image. Currently, this method supports preview for image files (jpg, png, and gif), other supported formats, like pdf, docs, slides, and spreadsheets, will return the file icon image. You can also pass query string arguments for cutting and resizing your preview image. Preview is supported only for image files smaller than 10MB. \ No newline at end of file