diff --git a/CHANGELOG.md b/CHANGELOG.md index 001f88711..f13985ce0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Update console kernel, add import upload gc ([afe6948d](https://github.com/pixelfed/pixelfed/commit/afe6948d)) - Update ImportService, filter deleted posts from getImportedPosts endpoint ([10dd348c](https://github.com/pixelfed/pixelfed/commit/10dd348c)) - Update FixStatusCount, improve command and support remote count resync ([04f4f8ba](https://github.com/pixelfed/pixelfed/commit/04f4f8ba)) +- Update StatusRemoteUpdatePipeline, fix missing mime and size attributes that cause empty media previews on our mobile app ([ea54413e](https://github.com/pixelfed/pixelfed/commit/ea54413e)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.8 (2023-05-29)](https://github.com/pixelfed/pixelfed/compare/v0.11.7...v0.11.8) diff --git a/app/Console/Commands/FetchMissingMediaMimeType.php b/app/Console/Commands/FetchMissingMediaMimeType.php new file mode 100644 index 000000000..16aeb5f59 --- /dev/null +++ b/app/Console/Commands/FetchMissingMediaMimeType.php @@ -0,0 +1,56 @@ +whereNull('mime')->lazyByIdDesc(50, 'id') as $media) { + $res = Http::retry(2, 100, throw: false)->head($media->remote_url); + + if(!$res->successful()) { + continue; + } + + if(!in_array($res->header('content-type'), explode(',',config('pixelfed.media_types')))) { + continue; + } + + $media->mime = $res->header('content-type'); + + if($res->hasHeader('content-length')) { + $media->size = $res->header('content-length'); + } + + $media->save(); + + MediaService::del($media->status_id); + StatusService::del($media->status_id); + $this->info('mid:'.$media->id . ' (' . $res->header('content-type') . ':' . $res->header('content-length') . ' bytes)'); + } + } +} diff --git a/app/Jobs/StatusPipeline/StatusRemoteUpdatePipeline.php b/app/Jobs/StatusPipeline/StatusRemoteUpdatePipeline.php index 07e2e9a37..6cb11ddc6 100644 --- a/app/Jobs/StatusPipeline/StatusRemoteUpdatePipeline.php +++ b/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;