+ /**
+ * Store attached media files in the post-media table
+ *
+ * @param int $uriid
+ * @param array $attachment
+ * @return void
+ */
+ private static function storeAttachmentAsMedia(int $uriid, array $attachment)
+ {
+ if (empty($attachment['url'])) {
+ return;
+ }
+
+ $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['url'] = $attachment['url'];
+ $data['mimetype'] = $attachment['mediaType'];
+ $data['height'] = $attachment['height'] ?? null;
+ $data['size'] = $attachment['size'] ?? null;
+ $data['preview'] = $attachment['image'] ?? null;
+ $data['description'] = $attachment['name'] ?? null;
+
+ Post\Media::insert($data);
+ }
+