Fix remote profile avatar urls when storing locally

This commit is contained in:
Daniel Supernault 2022-10-08 22:59:33 -06:00
parent 1de7a136f6
commit b0422d4f26
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 42 additions and 1 deletions

View file

@ -248,7 +248,7 @@ class MediaStorageService {
$avatar->media_path = $base . $path;
$avatar->is_remote = true;
$avatar->cdn_url = $permalink;
$avatar->cdn_url = $local ? config('app.url') . $permalink : $permalink;
$avatar->size = $head['length'];
$avatar->change_count = $avatar->change_count + 1;
$avatar->last_fetched_at = now();

View file

@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Cache;
use App\Services\AccountService;
use App\Avatar;
class FixCdnUrlInAvatarsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$baseUrl = 'https://' . config('pixelfed.domain.app');
Avatar::whereNotNull('cdn_url')
->chunk(50, function($avatars) use($baseUrl) {
foreach($avatars as $avatar) {
if(substr($avatar->cdn_url, 0, 23) === '/storage/cache/avatars/') {
$avatar->cdn_url = $baseUrl . $avatar->cdn_url;
$avatar->save();
}
Cache::forget('avatar:' . $avatar->profile_id);
AccountService::del($avatar->profile_id);
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}