]> git.mxchange.org Git - friendica.git/commitdiff
Improved support for "Page" type
authorMichael <heluecht@pirati.ca>
Thu, 27 Jan 2022 17:51:23 +0000 (17:51 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 27 Jan 2022 17:51:23 +0000 (17:51 +0000)
src/Model/Post/Media.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php

index c9e3128c4e53710fcdb2945b2ed255d300263418..07cad9cf6f09ee0d5ee8f0fa4ce2d87d56c87ec2 100644 (file)
@@ -169,6 +169,12 @@ class Media
                if (empty($media['mimetype']) || empty($media['size'])) {
                        $timeout = DI::config()->get('system', 'xrd_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] ?? '';
index 38999eb0dacd8602b820166fecffc6d09289c36f..4a9dc352d41639bfc21ed201d86fc650f475b476 100644 (file)
@@ -125,7 +125,7 @@ class Processor
                $data = ['uri-id' => $uriid];
                $data['type'] = Post\Media::UNKNOWN;
                $data['url'] = $attachment['url'];
-               $data['mimetype'] = $attachment['mediaType'];
+               $data['mimetype'] = $attachment['mediaType'] ?? null;
                $data['height'] = $attachment['height'] ?? null;
                $data['width'] = $attachment['width'] ?? null;
                $data['size'] = $attachment['size'] ?? null;
index 4504cee4c49367b7e587d0b2d767ba21a0e55aff..a28cc96170a1d7a5311fa873bf0a0af7bd7be5b7 100644 (file)
@@ -1454,6 +1454,14 @@ class Receiver
                        $object_data['attachments'] = array_merge($object_data['attachments'], self::processAttachmentUrls($object['as:url'] ?? []));
                }
 
+               // For page types we expect that the alternate url posts to some page.
+               // So we add this to the attachments if it differs from the id.
+               // Currently only Lemmy is using the page type.
+               if (($object_data['object_type'] == 'as:Page') && !empty($object_data['alternate-url']) && !Strings::compareLink($object_data['alternate-url'], $object_data['id'])) {
+                       $object_data['attachments'][] = ['url' => $object_data['alternate-url']];
+                       $object_data['alternate-url'] = null;
+               }
+
                $receiverdata = self::getReceivers($object, $object_data['actor'], $object_data['tags'], true);
                $receivers = $reception_types = [];
                foreach ($receiverdata as $key => $data) {