1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-25 01:05:36 +00:00

Update HandleUpdateActivity

This commit is contained in:
Daniel Supernault 2023-06-06 05:47:17 -06:00
parent 31afaba3d0
commit 1bf3ad7ed9
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 94 additions and 3 deletions

View file

@ -0,0 +1,91 @@
<?php
namespace App\Jobs\AvatarPipeline;
use App\Avatar;
use App\Profile;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Util\ActivityPub\Helpers;
use Illuminate\Support\Str;
use Zttp\Zttp;
use App\Http\Controllers\AvatarController;
use Storage;
use Log;
use Illuminate\Http\File;
use App\Services\MediaStorageService;
use App\Services\ActivityPubFetchService;
class RemoteAvatarFetchFromUrl implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $profile;
protected $url;
/**
* Delete the job if its models no longer exist.
*
* @var bool
*/
public $deleteWhenMissingModels = true;
/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries = 1;
public $timeout = 300;
public $maxExceptions = 1;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Profile $profile, $url)
{
$this->profile = $profile;
$this->url = $url;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$profile = $this->profile;
if(boolval(config_cache('pixelfed.cloud_storage')) == false && boolval(config_cache('federation.avatars.store_local')) == false) {
return 1;
}
if($profile->domain == null || $profile->private_key) {
return 1;
}
$avatar = Avatar::whereProfileId($profile->id)->first();
if(!$avatar) {
$avatar = new Avatar;
$avatar->profile_id = $profile->id;
$avatar->is_remote = true;
$avatar->remote_url = $this->url;
$avatar->save();
} else {
$avatar->remote_url = $this->url;
$avatar->is_remote = true;
$avatar->save();
}
MediaStorageService::avatar($avatar, boolval(config_cache('pixelfed.cloud_storage')) == false);
return 1;
}
}

View file

@ -13,7 +13,7 @@ use App\Profile;
use App\Util\ActivityPub\Helpers; use App\Util\ActivityPub\Helpers;
use Cache; use Cache;
use Purify; use Purify;
use App\Jobs\AvatarPipeline\RemoteAvatarFetch; use App\Jobs\AvatarPipeline\RemoteAvatarFetchFromUrl;
use App\Util\Lexer\Autolink; use App\Util\Lexer\Autolink;
class HandleUpdateActivity implements ShouldQueue class HandleUpdateActivity implements ShouldQueue
@ -82,8 +82,8 @@ class HandleUpdateActivity implements ShouldQueue
$profile->save(); $profile->save();
} }
if(isset($payload['object']['icon'])) { if(isset($payload['object']['icon']) && isset($payload['object']['icon']['url'])) {
RemoteAvatarFetch::dispatch($profile)->onQueue('low'); RemoteAvatarFetch::dispatch($profile, $payload['object']['icon']['url'])->onQueue('low');
} else { } else {
$profile->avatar->update(['remote_url' => null]); $profile->avatar->update(['remote_url' => null]);
Cache::forget('avatar:' . $profile->id); Cache::forget('avatar:' . $profile->id);