Improved mimeType detection and setting of the "type" field

This commit is contained in:
Michael 2021-04-14 19:12:01 +00:00
parent 0b239f368b
commit b65f73e348
3 changed files with 104 additions and 38 deletions

View file

@ -123,21 +123,7 @@ class Processor
}
$data = ['uri-id' => $uriid];
$filetype = strtolower(substr($attachment['mediaType'], 0, strpos($attachment['mediaType'], '/')));
if ($filetype == 'image') {
$data['type'] = Post\Media::IMAGE;
} elseif ($filetype == 'video') {
$data['type'] = Post\Media::VIDEO;
} elseif ($filetype == 'audio') {
$data['type'] = Post\Media::AUDIO;
} elseif (in_array($attachment['mediaType'], ['application/x-bittorrent', 'application/x-bittorrent;x-scheme-handler/magnet'])) {
$data['type'] = Post\Media::TORRENT;
} else {
Logger::info('Unknown type', ['attachment' => $attachment]);
return;
}
$data['type'] = Post\Media::UNKNOWN;
$data['url'] = $attachment['url'];
$data['mimetype'] = $attachment['mediaType'];
$data['height'] = $attachment['height'] ?? null;