]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
[CORE] Fixed bug where the http connection was using the wrong size for thumbnails...
authorMiguel Dantas <biodantasgs@gmail.com>
Sun, 30 Jun 2019 14:24:11 +0000 (15:24 +0100)
committerDiogo Cordeiro <diogo@fc.up.pt>
Sat, 3 Aug 2019 16:31:42 +0000 (17:31 +0100)
actions/attachment.php
actions/attachment_download.php
actions/attachment_thumbnail.php
actions/attachment_view.php
classes/File.php
classes/File_thumbnail.php

index 0851f1ee4e440686f37a7391c00a086b96c1e1c5..a7e1c5d161076a3d4c17e141897509d4c217dc4f 100644 (file)
@@ -204,7 +204,7 @@ class AttachmentAction extends ManagedAction
     /**
      * Include $filepath in the response, for viewing and downloading
      */
-    static function sendFile(string $filepath, int $filesize) {
+    static function sendFile(string $filepath, $filesize) {
         if (common_config('site', 'use_x_sendfile')) {
             header('X-Sendfile: ' . $filepath);
         } else {
index ebd5e5d956808f1cde67648eb703de6893eeb9c3..38ff046943ced557f05a4b1303d3fe8d8430403b 100644 (file)
@@ -17,7 +17,7 @@ class Attachment_downloadAction extends AttachmentAction
     {
         // Checks file exists or throws FileNotFoundException
         $filepath = $this->attachment->getFileOrThumbnailPath();
-        $filesize = $this->attachment->size ?: 0;
+        $filesize = $this->attachment->getFileOrThumbnailSize();
         $mimetype = $this->attachment->getFileOrThumbnailMimetype();
 
         if (empty($filepath)) {
index e54e99998329f02964020417cdea3b861d5b203d..8d4eb6f8842f449037655c53e02dfdc64da25657 100644 (file)
@@ -55,8 +55,6 @@ class Attachment_thumbnailAction extends AttachmentAction
 
     public function showPage()
     {
-        // Checks file exists or throws FileNotFoundException
-        $size = $this->attachment->size ?: 0;
 
         // Returns a File_thumbnail object or throws exception if not available
         try {
@@ -69,8 +67,10 @@ class Attachment_thumbnailAction extends AttachmentAction
             $this->clientError(_('No such attachment'), 404);
         }
 
-        $filepath = $file->getFileOrThumbnailPath();
-        $mimetype = $file->getFileOrThumbnailMimetype();
+        // Checks file exists or throws FileNotFoundException
+        $filepath = $file->getFileOrThumbnailPath($thumbnail);
+        $filesize = $this->attachment->getFileOrThumbnailSize($thumbnail);
+        $mimetype = $file->getFileOrThumbnailMimetype($thumbnail);
         $filename = MediaFile::getDisplayName($file);
 
         // Disable errors, to not mess with the file contents (suppress errors in case access to this
index 61aba9bd0f9867c8a7353f6edaef65fbdb4e12c0..e5f1c94da30165b9cc3fa6b6189f01fc80c0f600 100644 (file)
@@ -15,7 +15,7 @@ class Attachment_viewAction extends AttachmentAction
     {
         // Checks file exists or throws FileNotFoundException
         $filepath = $this->attachment->getFileOrThumbnailPath();
-        $filesize = $this->attachment->size ?: 0;
+        $filesize = $this->attachment->getFileOrThumbnailSize();
         $mimetype = $this->attachment->getFileOrThumbnailMimetype();
 
         if (empty($filepath)) {
index 113690b4b922a80a2d22ab7c03aad29aabbc63d4..564bdb00551f374a8c87040a4a87a4c490b32310 100644 (file)
@@ -603,8 +603,11 @@ class File extends Managed_DataObject
      * @throws InvalidFilenameException
      * @throws ServerException
      */
-    public function getFileOrThumbnailPath() : string
+    public function getFileOrThumbnailPath($thumbnail = null) : string
     {
+        if (!empty($thumbnail)) {
+            return $thumbnail->getPath();
+        }
         if (!empty($this->filename)) {
             $filepath = self::path($this->filename);
             if (file_exists($filepath)) {
@@ -630,19 +633,40 @@ class File extends Managed_DataObject
      * @throws ServerException
      * @throws UnsupportedMediaException
      */
-    public function getFileOrThumbnailMimetype() : string
+    public function getFileOrThumbnailMimetype($thumbnail = null) : string
     {
-        if (empty($this->filename)) {
+        if (!empty($thumbnail)) {
+            $filepath = $thumbnail->getPath();
+        } elseif (empty($this->filename)) {
             $filepath = File_thumbnail::byFile($this)->getPath();
-            $info = @getimagesize($filepath);
-            if ($info !== false) {
-                return $info['mime'];
-            } else {
-                throw new UnsupportedMediaException(_("Thumbnail is not an image."));
-            }
         } else {
             return $this->mimetype;
         }
+
+        $info = @getimagesize($filepath);
+        if ($info !== false) {
+            return $info['mime'];
+        } else {
+            throw new UnsupportedMediaException(_("Thumbnail is not an image."));
+        }
+    }
+
+    /**
+     * Return the size of the thumbnail if we have it, or, if not, of the File
+     * @return int
+     * @throws FileNotFoundException
+     * @throws NoResultException
+     * @throws ServerException
+     */
+    public function getFileOrThumbnailSize($thumbnail = null) : int
+    {
+        if (!empty($thumbnail)) {
+            return filesize($thumbnail->getPath());
+        } elseif (!empty($this->filename)) {
+            return $this->size;
+        } else {
+            return filesize(File_thumbnail::byFile($this)->getPath());
+        }
     }
 
     public function getAttachmentUrl()
index 68cb2a737fb2a939e34beebbcfb14e394de78ca2..5e751c3c4db9cff0b50ad9aeadd3a8e0c3a5b5c9 100644 (file)
@@ -172,9 +172,9 @@ class File_thumbnail extends Managed_DataObject
     }
 
     /**
-     *
      * @return  string  full filesystem path to the locally stored thumbnail file
-     * @throws  
+     * @throws FileNotFoundException
+     * @throws ServerException
      */
     public function getPath()
     {