forked from mirror/pixelfed
Fix remote profile avatar urls when storing locally
This commit is contained in:
parent
1de7a136f6
commit
b0422d4f26
2 changed files with 42 additions and 1 deletions
|
@ -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();
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue