Update AP Helpers, add blurhash and RemoteAvatarFetch

This commit is contained in:
Daniel Supernault 2021-01-25 22:24:24 -07:00
parent cc2d4bf8d8
commit de8828e88a
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
1 changed files with 7 additions and 4 deletions

View File

@ -28,6 +28,7 @@ use App\Services\ActivityPubDeliveryService;
use App\Services\MediaPathService; use App\Services\MediaPathService;
use App\Services\MediaStorageService; use App\Services\MediaStorageService;
use App\Jobs\MediaPipeline\MediaStoragePipeline; use App\Jobs\MediaPipeline\MediaStoragePipeline;
use App\Jobs\AvatarPipeline\RemoteAvatarFetch;
class Helpers { class Helpers {
@ -387,12 +388,14 @@ class Helpers {
foreach($attachments as $media) { foreach($attachments as $media) {
$type = $media['mediaType']; $type = $media['mediaType'];
$url = $media['url']; $url = $media['url'];
$blurhash = isset($media['blurhash']) ? $media['blurhash'] : null;
$valid = self::validateUrl($url); $valid = self::validateUrl($url);
if(in_array($type, $allowed) == false || $valid == false) { if(in_array($type, $allowed) == false || $valid == false) {
continue; continue;
} }
$media = new Media(); $media = new Media();
$media->blurhash = $blurhash;
$media->remote_media = true; $media->remote_media = true;
$media->status_id = $status->id; $media->status_id = $status->id;
$media->profile_id = $status->profile_id; $media->profile_id = $status->profile_id;
@ -400,6 +403,7 @@ class Helpers {
$media->media_path = $url; $media->media_path = $url;
$media->remote_url = $url; $media->remote_url = $url;
$media->mime = $type; $media->mime = $type;
$media->version = 3;
$media->save(); $media->save();
if(config('pixelfed.cloud_storage') == true) { if(config('pixelfed.cloud_storage') == true) {
@ -431,6 +435,7 @@ class Helpers {
->whereUsername($id) ->whereUsername($id)
->firstOrFail(); ->firstOrFail();
} }
$res = self::fetchProfileFromUrl($url); $res = self::fetchProfileFromUrl($url);
if(isset($res['id']) == false) { if(isset($res['id']) == false) {
return; return;
@ -466,10 +471,7 @@ class Helpers {
$profile->webfinger = strtolower(Purify::clean($webfinger)); $profile->webfinger = strtolower(Purify::clean($webfinger));
$profile->last_fetched_at = now(); $profile->last_fetched_at = now();
$profile->save(); $profile->save();
if($runJobs == true) { RemoteAvatarFetch::dispatch($profile);
// RemoteFollowImportRecent::dispatch($res, $profile);
CreateAvatar::dispatch($profile);
}
return $profile; return $profile;
}); });
} else { } else {
@ -483,6 +485,7 @@ class Helpers {
$profile->sharedInbox = isset($res['endpoints']) && isset($res['endpoints']['sharedInbox']) && Helpers::validateUrl($res['endpoints']['sharedInbox']) ? $res['endpoints']['sharedInbox'] : null; $profile->sharedInbox = isset($res['endpoints']) && isset($res['endpoints']['sharedInbox']) && Helpers::validateUrl($res['endpoints']['sharedInbox']) ? $res['endpoints']['sharedInbox'] : null;
$profile->save(); $profile->save();
} }
RemoteAvatarFetch::dispatch($profile);
} }
return $profile; return $profile;
}); });