]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Post/Media.php
Don't cache local avatars
[friendica.git] / src / Model / Post / Media.php
index 087a36cb167aa50bab3c9817f6e8e7fc8e2630e1..07cad9cf6f09ee0d5ee8f0fa4ce2d87d56c87ec2 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -30,7 +30,7 @@ use Friendica\DI;
 use Friendica\Model\Item;
 use Friendica\Model\Photo;
 use Friendica\Model\Post;
-use Friendica\Network\HTTPClientOptions;
+use Friendica\Network\HTTPClient\Client\HttpClientOptions;
 use Friendica\Util\Images;
 use Friendica\Util\Network;
 use Friendica\Util\ParseUrl;
@@ -168,7 +168,13 @@ class Media
                // Fetch the mimetype or size if missing.
                if (empty($media['mimetype']) || empty($media['size'])) {
                        $timeout = DI::config()->get('system', 'xrd_timeout');
-                       $curlResult = DI::httpClient()->head($media['url'], [HTTPClientOptions::TIMEOUT => $timeout]);
+                       $curlResult = DI::httpClient()->head($media['url'], [HttpClientOptions::TIMEOUT => $timeout]);
+
+                       // Workaround for systems that can't handle a HEAD request
+                       if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {
+                               $curlResult = DI::httpClient()->get($media['url'], [HttpClientOptions::TIMEOUT => $timeout]);
+                       }
+
                        if ($curlResult->isSuccess()) {
                                if (empty($media['mimetype'])) {
                                        $media['mimetype'] = $curlResult->getHeader('Content-Type')[0] ?? '';
@@ -388,6 +394,10 @@ class Media
                }
 
                foreach ($attachments as $attachment) {
+                       if (Post\Link::exists($uriid, $attachment['preview'] ?? $attachment['url'])) {
+                               continue;
+                       }
+
                        // Only store attachments that are part of the unshared body
                        if (Item::containsLink($unshared_body, $attachment['preview'] ?? $attachment['url'], $attachment['type'])) {
                                self::insert($attachment);
@@ -547,7 +557,6 @@ class Media
                        return $attachments;
                }
 
-               $height = 0;
                $heights = [];
                $selected = '';
                $previews = [];
@@ -683,7 +692,7 @@ class Media
         * Get preview link for given media id
         *
         * @param integer $id   media id
-        * @param string  $size One of the ProxyUtils::SIZE_* constants
+        * @param string  $size One of the Proxy::SIZE_* constants
         * @return string preview link
         */
        public static function getPreviewUrlForId(int $id, string $size = ''):string
@@ -713,7 +722,7 @@ class Media
         * Get media link for given media id
         *
         * @param integer $id   media id
-        * @param string  $size One of the ProxyUtils::SIZE_* constants
+        * @param string  $size One of the Proxy::SIZE_* constants
         * @return string media link
         */
        public static function getUrlForId(int $id, string $size = ''):string