瀏覽代碼

Update StatusRemoteUpdatePipeline, fix missing mime and size attributes that cause empty media previews on our mobile app

Daniel Supernault 2 年之前
父節點
當前提交
ea54413e95
共有 1 個文件被更改,包括 14 次插入0 次删除
  1. 14 0
      app/Jobs/StatusPipeline/StatusRemoteUpdatePipeline.php

+ 14 - 0
app/Jobs/StatusPipeline/StatusRemoteUpdatePipeline.php

@@ -15,6 +15,7 @@ use App\Status;
 use App\Models\StatusEdit;
 use App\Services\StatusService;
 use Purify;
+use Illuminate\Support\Facades\Http;
 
 class StatusRemoteUpdatePipeline implements ShouldQueue
 {
@@ -89,13 +90,26 @@ class StatusRemoteUpdatePipeline implements ShouldQueue
 			]);
 
 		$nm->each(function($n, $key) use($status) {
+			$res = Http::retry(3, 100, throw: false)->head($n['url']);
+
+			if(!$res->successful()) {
+				return;
+			}
+
+			if(!in_array($res->header('content-type'), explode(',',config('pixelfed.media_types')))) {
+				return;
+			}
+
 			$m = new Media;
 			$m->status_id = $status->id;
 			$m->profile_id = $status->profile_id;
 			$m->remote_media = true;
 			$m->media_path = $n['url'];
+            $m->mime = $res->header('content-type');
+            $m->size = $res->hasHeader('content-length') ? $res->header('content-length') : null;
 			$m->caption = isset($n['name']) && !empty($n['name']) ? Purify::clean($n['name']) : null;
 			$m->remote_url = $n['url'];
+            $m->blurhash = isset($n['blurhash']) && (strlen($n['blurhash']) < 50) ? $n['blurhash'] : null;
 			$m->width = isset($n['width']) && !empty($n['width']) ? $n['width'] : null;
 			$m->height = isset($n['height']) && !empty($n['height']) ? $n['height'] : null;
 			$m->skip_optimize = true;