]> source.dussan.org Git - nextcloud-server.git/commitdiff
movie previews: use file directly when it's stored locally and encryption is not...
authorGeorg Ehrke <developer@georgehrke.com>
Tue, 10 Jun 2014 20:08:12 +0000 (22:08 +0200)
committerGeorg Ehrke <developer@georgehrke.com>
Tue, 10 Jun 2014 20:08:27 +0000 (22:08 +0200)
lib/private/preview/movies.php

index 72ccfadc6e993de90820a4bfe53439855a03d190..2a23c2141c14cd838cffea46d20a1e0e735da5dd 100644 (file)
@@ -41,14 +41,22 @@ if (!\OC_Util::runningOnWindows()) {
 
                        public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
                                // TODO: use proc_open() and stream the source file ?
-                               $absPath = \OC_Helper::tmpFile();
 
-                               $handle = $fileview->fopen($path, 'rb');
+                               $fileInfo = $fileview->getFileInfo($path);
+                               $useFileDirectly = (!$fileInfo->isEncrypted() && !$fileInfo->isMounted());
 
-                               // we better use 5MB (1024 * 1024 * 5 = 5242880) instead of 1MB.
-                               // in some cases 1MB was no enough to generate thumbnail
-                               $firstmb = stream_get_contents($handle, 5242880);
-                               file_put_contents($absPath, $firstmb);
+                               if ($useFileDirectly) {
+                                       $absPath = $fileview->getLocalFile($path);
+                               } else {
+                                       $absPath = \OC_Helper::tmpFile();
+
+                                       $handle = $fileview->fopen($path, 'rb');
+
+                                       // we better use 5MB (1024 * 1024 * 5 = 5242880) instead of 1MB.
+                                       // in some cases 1MB was no enough to generate thumbnail
+                                       $firstmb = stream_get_contents($handle, 5242880);
+                                       file_put_contents($absPath, $firstmb);
+                               }
 
                                $result = $this->generateThumbNail($maxX, $maxY, $absPath, 5);
                                if ($result === false) {
@@ -58,8 +66,9 @@ if (!\OC_Util::runningOnWindows()) {
                                        }
                                }
 
-                               unlink($absPath);
-
+                               if (!$useFileDirectly) {
+                                       unlink($absPath);
+                               }
 
                                return $result;
                        }