From 4c148055cfd1a054183320c5debb04f3775949b5 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 25 Jan 2021 22:03:27 -0700 Subject: [PATCH] Update AvatarPipeline, add remote avatar fetch --- app/Jobs/AvatarPipeline/RemoteAvatarFetch.php | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 app/Jobs/AvatarPipeline/RemoteAvatarFetch.php diff --git a/app/Jobs/AvatarPipeline/RemoteAvatarFetch.php b/app/Jobs/AvatarPipeline/RemoteAvatarFetch.php new file mode 100644 index 000000000..6a05949e5 --- /dev/null +++ b/app/Jobs/AvatarPipeline/RemoteAvatarFetch.php @@ -0,0 +1,98 @@ +profile = $profile; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + $profile = $this->profile; + + if($profile->domain == null || $profile->private_key) { + return 1; + } + + $avatar = Avatar::firstOrCreate([ + 'profile_id' => $profile->id + ]); + + if($avatar->media_path == null && $avatar->remote_url == null) { + $avatar->media_path = 'public/avatars/default.jpg'; + $avatar->is_remote = true; + $avatar->save(); + } + + $person = Helpers::fetchFromUrl($profile->remote_url); + + if(!$person || !isset($person['@context'])) { + return 1; + } + + if( !isset($person['icon']) || + !isset($person['icon']['type']) || + !isset($person['icon']['url']) + ) { + return 1; + } + + if($person['icon']['type'] !== 'Image') { + return 1; + } + + if(!Helpers::validateUrl($person['icon']['url'])) { + return 1; + } + + $icon = $person['icon']; + + $avatar->remote_url = $icon['url']; + $avatar->save(); + + MediaStorageService::avatar($avatar); + + return 1; + } +} \ No newline at end of file