File tree Expand file tree Collapse file tree 3 files changed +25
-7
lines changed
Expand file tree Collapse file tree 3 files changed +25
-7
lines changed Original file line number Diff line number Diff line change 3434use OC \Files \Filesystem ;
3535use OC \Files \View ;
3636use OCA \Files_Sharing \SharedMount ;
37+ use OCP \Files \File ;
3738use OCP \Files \FileInfo ;
3839use OCP \Files \Folder ;
3940use OCP \Files \Node ;
@@ -1081,6 +1082,22 @@ private function getPreviewPath($fileId = null) {
10811082 return $ this ->getThumbnailsFolder () . '/ ' . $ fileId . '/ ' ;
10821083 }
10831084
1085+ /**
1086+ * @param File $file
1087+ * @return bool
1088+ * @throws \OCP\Files\InvalidPathException
1089+ * @throws \OCP\Files\NotFoundException
1090+ */
1091+ public static function isImageFileSizeTooBig (File $ file ): bool {
1092+ $ maxSizeForImages = \OC ::$ server ->getConfig ()->getSystemValue ('preview_max_filesize_image ' , 50 );
1093+ if ($ maxSizeForImages === -1 ) {
1094+ return false ;
1095+ }
1096+ $ size = $ file ->getSize ();
1097+
1098+ return $ size > ($ maxSizeForImages * 1024 * 1024 );
1099+ }
1100+
10841101 /**
10851102 * Asks the provider to send a preview of the file which respects the maximum dimensions
10861103 * defined in the configuration and after saving it in the cache, it is then resized to the
Original file line number Diff line number Diff line change 2525namespace OC \Preview ;
2626
2727use Imagick ;
28+ use OC \Preview ;
2829use OCP \Files \File ;
2930use OCP \Files \FileInfo ;
3031use OCP \Preview \IProvider2 ;
@@ -40,6 +41,9 @@ abstract class Bitmap implements IProvider2 {
4041 * {@inheritDoc}
4142 */
4243 public function getThumbnail (File $ file , $ maxX , $ maxY , $ scalingUp ) {
44+ if (Preview::isImageFileSizeTooBig ($ file )) {
45+ return false ;
46+ }
4347 $ stream = $ file ->fopen ('r ' );
4448
4549 // Creates \Imagick object from bitmap or vector file
@@ -78,9 +82,9 @@ public function isAvailable(FileInfo $file) {
7882 * @param int $maxX
7983 * @param int $maxY
8084 *
81- * @return \ Imagick
85+ * @return Imagick
8286 */
83- private function getResizedPreview ($ stream , $ maxX , $ maxY ) {
87+ private function getResizedPreview ($ stream , int $ maxX , int $ maxY ): Imagick {
8488 # file content can be SVG - we need to sanitize it first
8589 $ content = \stream_get_contents ($ stream );
8690 $ output = SVG ::sanitizeSVGContent ($ content );
Original file line number Diff line number Diff line change 2626 */
2727namespace OC \Preview ;
2828
29+ use OC \Preview ;
2930use OCP \Files \File ;
3031use OCP \Files \FileInfo ;
3132use OCP \Preview \IProvider2 ;
@@ -35,13 +36,9 @@ abstract class Image implements IProvider2 {
3536 * {@inheritDoc}
3637 */
3738 public function getThumbnail (File $ file , $ maxX , $ maxY , $ scalingUp ) {
38- $ maxSizeForImages = \OC ::$ server ->getConfig ()->getSystemValue ('preview_max_filesize_image ' , 50 );
39- $ size = $ file ->getSize ();
40-
41- if ($ maxSizeForImages !== -1 && $ size > ($ maxSizeForImages * 1024 * 1024 )) {
39+ if (Preview::isImageFileSizeTooBig ($ file )) {
4240 return false ;
4341 }
44-
4542 $ image = new \OC_Image ();
4643 $ handle = $ file ->fopen ('r ' );
4744 $ image ->load ($ handle );
You can’t perform that action at this time.
0 commit comments