]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
[CORE] Fixed bug where all thumbnails were using the original file
authorMiguel Dantas <biodantasgs@gmail.com>
Thu, 27 Jun 2019 01:20:39 +0000 (02:20 +0100)
committerDiogo Cordeiro <diogo@fc.up.pt>
Sat, 3 Aug 2019 16:31:41 +0000 (17:31 +0100)
actions/attachment.php
actions/attachment_download.php
actions/attachment_thumbnail.php
actions/attachment_view.php

index 2a967c72b7bd3bf2ba410d8316caa41ab36ae15c..04b261506bab61a0ebb732fb6275c3c8ab81530e 100644 (file)
@@ -179,18 +179,17 @@ class AttachmentAction extends ManagedAction
     }
 
     /**
-     * Include $this as a file read from $filepath, for viewing and downloading
+     * Include $filepath in the response, for viewing and downloading
      */
-    public function sendFile(string $filepath) {
+    static function sendFile(string $filepath, int $size) {
         if (common_config('site', 'use_x_sendfile')) {
             header('X-Sendfile: ' . $filepath);
         } else {
-            $filesize = $this->attachment->size;
-            // 'if available', it says, so ensure we have it
-            if (empty($filesize)) {
-                $filesize = filesize($filepath);
+            // ensure we have a file size
+            if (empty($size)) {
+                $size = filesize($filepath);
             }
-            header("Content-Length: {$filesize}");
+            header("Content-Length: {$size}");
             // header('Cache-Control: private, no-transform, no-store, must-revalidate');
 
             $ret = @readfile($filepath);
index 35c0ecb5d5f587f601943a356786e99beebdb183..b4b01389d8354b32bda680a5967a0cda8e51814e 100644 (file)
@@ -17,7 +17,7 @@ class Attachment_downloadAction extends AttachmentAction
     {
         // Checks file exists or throws FileNotStoredLocallyException
         $filepath = $this->attachment->getPath();
-
+        $filesize = $this->attachment->size;
         $filename = MediaFile::getDisplayName($this->attachment);
 
         // Disable errors, to not mess with the file contents (suppress errors in case access to this
@@ -31,6 +31,6 @@ class Attachment_downloadAction extends AttachmentAction
         header('Expires: 0');
         header('Content-Transfer-Encoding: binary'); // FIXME? Can this be different?
 
-        $this->sendFile($filepath);
+        parent::sendFile($filepath, $filesize);
     }
 }
index 85ffb7e5df191620a4734dcfc4b4e56026d286b4..f7cc17f3470ad75de9c4eb5fb26ecc02c8ad7d7f 100644 (file)
@@ -57,13 +57,21 @@ class Attachment_thumbnailAction extends AttachmentAction
     {
         // Returns a File_thumbnail object or throws exception if not available
         try {
-            $file = $this->attachment->getThumbnail($this->thumb_w, $this->thumb_h, $this->thumb_c)->getFile();
+            $thumb = $this->attachment->getThumbnail($this->thumb_w, $this->thumb_h, $this->thumb_c);
+            $file = $thumb->getFile();
         } catch (UseFileAsThumbnailException $e) {
             // With this exception, the file exists locally
             $file = $e->file;
         }
 
-        $filepath = $this->attachment->getPath();
+        if (!empty($thumb)) {
+            $filepath = $thumb->getPath();
+            $filesize = 0;
+        } else {
+            $filepath = $file->getPath();
+            $filesize = $file->size;
+        }
+
         $filename = MediaFile::getDisplayName($file);
 
         // Disable errors, to not mess with the file contents (suppress errors in case access to this
@@ -76,19 +84,7 @@ class Attachment_thumbnailAction extends AttachmentAction
         header("Content-Disposition: inline; filename=\"{$filename}\"");
         header('Expires: 0');
         header('Content-Transfer-Encoding: binary');
-        $filesize = $this->file->size;
-        // 'if available', it says, so ensure we have it
-        if (empty($filesize)) {
-            $filesize = filesize($this->attachment->filename);
-        }
-        header("Content-Length: {$filesize}");
-        // header('Cache-Control: private, no-transform, no-store, must-revalidate');
 
-        $ret = @readfile($filepath);
-
-        if ($ret === false || $ret !== $filesize) {
-            common_log(LOG_ERR, "The lengths of the file as recorded on the DB (or on disk) for the file " .
-                       "{$filepath}, with id={$this->attachment->id} differ from what was sent to the user.");
-        }
+        parent::sendFile($filepath, $filesize);
     }
 }
index d6a7c1c50d583f5908a5088d360b4331942adf21..71e1e0fd6c77ca785404a0ba95b2636f802f85f2 100644 (file)
@@ -15,6 +15,7 @@ class Attachment_viewAction extends AttachmentAction
     {
         // Checks file exists or throws FileNotStoredLocallyException
         $filepath = $this->attachment->getPath();
+        $filesize = $this->attachment->size;
 
         $filename = MediaFile::getDisplayName($this->attachment);
 
@@ -33,6 +34,6 @@ class Attachment_viewAction extends AttachmentAction
         header('Expires: 0');
         header('Content-Transfer-Encoding: binary');
 
-        $this->sendFile($filepath);
+        parrent::sendFile($filepath, $filesize);
     }
 }