Improved support for "Page" type

This commit is contained in:
Michael 2022-01-27 17:51:23 +00:00
parent 9d25c3a8f6
commit 9eec2bf5f3
3 changed files with 15 additions and 1 deletions

View File

@ -169,6 +169,12 @@ class Media
if (empty($media['mimetype']) || empty($media['size'])) { if (empty($media['mimetype']) || empty($media['size'])) {
$timeout = DI::config()->get('system', 'xrd_timeout'); $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 ($curlResult->isSuccess()) {
if (empty($media['mimetype'])) { if (empty($media['mimetype'])) {
$media['mimetype'] = $curlResult->getHeader('Content-Type')[0] ?? ''; $media['mimetype'] = $curlResult->getHeader('Content-Type')[0] ?? '';

View File

@ -125,7 +125,7 @@ class Processor
$data = ['uri-id' => $uriid]; $data = ['uri-id' => $uriid];
$data['type'] = Post\Media::UNKNOWN; $data['type'] = Post\Media::UNKNOWN;
$data['url'] = $attachment['url']; $data['url'] = $attachment['url'];
$data['mimetype'] = $attachment['mediaType']; $data['mimetype'] = $attachment['mediaType'] ?? null;
$data['height'] = $attachment['height'] ?? null; $data['height'] = $attachment['height'] ?? null;
$data['width'] = $attachment['width'] ?? null; $data['width'] = $attachment['width'] ?? null;
$data['size'] = $attachment['size'] ?? null; $data['size'] = $attachment['size'] ?? null;

View File

@ -1454,6 +1454,14 @@ class Receiver
$object_data['attachments'] = array_merge($object_data['attachments'], self::processAttachmentUrls($object['as:url'] ?? [])); $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); $receiverdata = self::getReceivers($object, $object_data['actor'], $object_data['tags'], true);
$receivers = $reception_types = []; $receivers = $reception_types = [];
foreach ($receiverdata as $key => $data) { foreach ($receiverdata as $key => $data) {