Commit 06c4f154 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

fix(fediverse): check that actor's images mimetype is present or guess it otherwise

fixes #348
parent 233ece4b
Loading
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ declare(strict_types=1);

use CodeIgniter\HTTP\Exceptions\HTTPException;
use CodeIgniter\HTTP\URI;
use Config\Mimes;
use Embera\Embera;
use Modules\Fediverse\Activities\AcceptActivity;
use Modules\Fediverse\ActivityRequest;
@@ -273,12 +274,26 @@ if (! function_exists('create_actor_from_uri')) {
        $newActor->summary = property_exists($actorPayload, 'summary') ? $actorPayload->summary : null;
        if (property_exists($actorPayload, 'icon')) {
            $newActor->avatar_image_url = $actorPayload->icon->url;

            if (property_exists($actorPayload->icon, 'mediaType')) {
                $newActor->avatar_image_mimetype = $actorPayload->icon->mediaType;
            } else {
                $iconExtension = pathinfo((string) $actorPayload->icon->url, PATHINFO_EXTENSION);

                $newActor->avatar_image_mimetype = (string) Mimes::guessTypeFromExtension($iconExtension);
            }
        }

        if (property_exists($actorPayload, 'image')) {
            $newActor->cover_image_url = $actorPayload->image->url;

            if (property_exists($actorPayload->image, 'mediaType')) {
                $newActor->cover_image_mimetype = $actorPayload->image->mediaType;
            } else {
                $coverExtension = pathinfo((string) $actorPayload->image->url, PATHINFO_EXTENSION);

                $newActor->cover_image_mimetype = (string) Mimes::guessTypeFromExtension($coverExtension);
            }
        }

        $newActor->inbox_url = $actorPayload->inbox;