mirror of
https://code.castopod.org/adaures/castopod.git
synced 2024-09-30 05:31:22 +02:00
fix(avatar): use default avatar when no avatar url has been set
- get avatar and cover urls from entity: if no image exists, retrieve the default ones. - always set icon and image in actor object: set the default ones if podcast hasn't set them. fixes #111
This commit is contained in:
parent
e2b85a1d8f
commit
9d23c7e7e1
@ -11,4 +11,15 @@ class ActivityPub extends ActivityPubBase
|
|||||||
*/
|
*/
|
||||||
public $actorObject = 'App\Libraries\PodcastActor';
|
public $actorObject = 'App\Libraries\PodcastActor';
|
||||||
public $noteObject = 'App\Libraries\NoteObject';
|
public $noteObject = 'App\Libraries\NoteObject';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------
|
||||||
|
* Default avatar and cover images
|
||||||
|
* --------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
public $defaultAvatarImagePath = 'assets/images/castopod-avatar-default.jpg';
|
||||||
|
public $defaultAvatarImageMimetype = 'image/jpeg';
|
||||||
|
|
||||||
|
public $defaultCoverImagePath = 'assets/images/castopod-cover-default.jpg';
|
||||||
|
public $defaultCoverImageMimetype = 'image/jpeg';
|
||||||
}
|
}
|
||||||
|
@ -19,4 +19,15 @@ class ActivityPub extends BaseConfig
|
|||||||
*/
|
*/
|
||||||
public $actorObject = 'ActivityPub\Objects\ActorObject';
|
public $actorObject = 'ActivityPub\Objects\ActorObject';
|
||||||
public $noteObject = 'ActivityPub\Objects\NoteObject';
|
public $noteObject = 'ActivityPub\Objects\NoteObject';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* --------------------------------------------------------------------
|
||||||
|
* Default avatar and cover images
|
||||||
|
* --------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
public $defaultAvatarImagePath = 'assets/images/avatar-default.jpg';
|
||||||
|
public $defaultAvatarImageMimetype = 'image/jpeg';
|
||||||
|
|
||||||
|
public $defaultCoverImagePath = 'assets/images/cover-default.jpg';
|
||||||
|
public $defaultCoverImageMimetype = 'image/jpeg';
|
||||||
}
|
}
|
||||||
|
@ -54,12 +54,14 @@ class AddActors extends Migration
|
|||||||
'avatar_image_url' => [
|
'avatar_image_url' => [
|
||||||
'type' => 'VARCHAR',
|
'type' => 'VARCHAR',
|
||||||
'constraint' => 255,
|
'constraint' => 255,
|
||||||
|
'null' => true,
|
||||||
],
|
],
|
||||||
// constraint is 13 because the longest safe mimetype for images is image/svg+xml,
|
// constraint is 13 because the longest safe mimetype for images is image/svg+xml,
|
||||||
// see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#image_types
|
// see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#image_types
|
||||||
'avatar_image_mimetype' => [
|
'avatar_image_mimetype' => [
|
||||||
'type' => 'VARCHAR',
|
'type' => 'VARCHAR',
|
||||||
'constraint' => 13,
|
'constraint' => 13,
|
||||||
|
'null' => true,
|
||||||
],
|
],
|
||||||
'cover_image_url' => [
|
'cover_image_url' => [
|
||||||
'type' => 'VARCHAR',
|
'type' => 'VARCHAR',
|
||||||
|
@ -36,8 +36,8 @@ class Actor extends Entity
|
|||||||
'summary' => '?string',
|
'summary' => '?string',
|
||||||
'private_key' => '?string',
|
'private_key' => '?string',
|
||||||
'public_key' => '?string',
|
'public_key' => '?string',
|
||||||
'avatar_image_url' => 'string',
|
'avatar_image_url' => '?string',
|
||||||
'avatar_image_mimetype' => 'string',
|
'avatar_image_mimetype' => '?string',
|
||||||
'cover_image_url' => '?string',
|
'cover_image_url' => '?string',
|
||||||
'cover_image_mimetype' => '?string',
|
'cover_image_mimetype' => '?string',
|
||||||
'inbox_url' => 'string',
|
'inbox_url' => 'string',
|
||||||
@ -81,4 +81,40 @@ class Actor extends Entity
|
|||||||
|
|
||||||
return $this->followers;
|
return $this->followers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAvatarImageUrl()
|
||||||
|
{
|
||||||
|
if (empty($this->attributes['avatar_image_url'])) {
|
||||||
|
return base_url(config('ActivityPub')->defaultAvatarImagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->attributes['avatar_image_url'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAvatarImageMimetype()
|
||||||
|
{
|
||||||
|
if (empty($this->attributes['avatar_image_mimetype'])) {
|
||||||
|
return config('ActivityPub')->defaultAvatarImageMimetype;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->attributes['avatar_image_mimetype'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCoverImageUrl()
|
||||||
|
{
|
||||||
|
if (empty($this->attributes['cover_image_url'])) {
|
||||||
|
return base_url(config('ActivityPub')->defaultCoverImagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->attributes['cover_image_url'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCoverImageMimetype()
|
||||||
|
{
|
||||||
|
if (empty($this->attributes['cover_image_mimetype'])) {
|
||||||
|
return config('ActivityPub')->defaultCoverImageMimetype;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->attributes['cover_image_mimetype'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,13 +91,12 @@ class ActorObject extends ObjectType
|
|||||||
$this->outbox = $actor->outbox_url;
|
$this->outbox = $actor->outbox_url;
|
||||||
$this->followers = $actor->followers_url;
|
$this->followers = $actor->followers_url;
|
||||||
|
|
||||||
if ($actor->cover_image_url) {
|
$this->image = [
|
||||||
$this->image = [
|
'type' => 'Image',
|
||||||
'type' => 'Image',
|
'mediaType' => $actor->cover_image_mimetype,
|
||||||
'mediaType' => $actor->cover_image_mimetype,
|
'url' => $actor->cover_image_url,
|
||||||
'url' => $actor->cover_image_url,
|
];
|
||||||
];
|
|
||||||
}
|
|
||||||
$this->icon = [
|
$this->icon = [
|
||||||
'type' => 'Image',
|
'type' => 'Image',
|
||||||
'mediaType' => $actor->avatar_image_mimetype,
|
'mediaType' => $actor->avatar_image_mimetype,
|
||||||
|
@ -297,12 +297,6 @@ class PodcastModel extends Model
|
|||||||
'public_key' => $publickey,
|
'public_key' => $publickey,
|
||||||
'display_name' => $data['data']['title'],
|
'display_name' => $data['data']['title'],
|
||||||
'summary' => $data['data']['description_html'],
|
'summary' => $data['data']['description_html'],
|
||||||
'avatar_image_url' => '',
|
|
||||||
'avatar_image_mimetype' => '',
|
|
||||||
'cover_image_url' => base_url(
|
|
||||||
'assets/images/castopod-cover-default.jpg',
|
|
||||||
),
|
|
||||||
'cover_image_mimetype' => 'image/jpeg',
|
|
||||||
'inbox_url' => url_to('inbox', $username),
|
'inbox_url' => url_to('inbox', $username),
|
||||||
'outbox_url' => url_to('outbox', $username),
|
'outbox_url' => url_to('outbox', $username),
|
||||||
'followers_url' => url_to('followers', $username),
|
'followers_url' => url_to('followers', $username),
|
||||||
@ -342,6 +336,7 @@ class PodcastModel extends Model
|
|||||||
$actor->display_name = $podcast->title;
|
$actor->display_name = $podcast->title;
|
||||||
$actor->summary = $podcast->description_html;
|
$actor->summary = $podcast->description_html;
|
||||||
$actor->avatar_image_url = $podcast->image->thumbnail_url;
|
$actor->avatar_image_url = $podcast->image->thumbnail_url;
|
||||||
|
$actor->avatar_image_mimetype = $podcast->image_mimetype;
|
||||||
|
|
||||||
if ($actor->hasChanged()) {
|
if ($actor->hasChanged()) {
|
||||||
$actorModel->update($actor->id, $actor);
|
$actorModel->update($actor->id, $actor);
|
||||||
|
BIN
app/Views/_assets/images/castopod-avatar-default.jpg
Normal file
BIN
app/Views/_assets/images/castopod-avatar-default.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.3 KiB |
@ -1,10 +1,6 @@
|
|||||||
<header id="main-header" class="fixed top-0 left-0 flex-col flex-shrink-0 h-screen transform -translate-x-full sm:left-auto sm:-translate-x-0 sm:sticky w-80 sm:w-64 lg:w-80 xl:w-112 sm:flex">
|
<header id="main-header" class="fixed top-0 left-0 flex-col flex-shrink-0 h-screen transform -translate-x-full sm:left-auto sm:-translate-x-0 sm:sticky w-80 sm:w-64 lg:w-80 xl:w-112 sm:flex">
|
||||||
<?php if ($podcast->actor->cover_image_url): ?>
|
<img src="<?= $podcast->actor
|
||||||
<img src="<?= $podcast->actor
|
->cover_image_url ?>" alt="" class="object-cover w-full h-48 bg-pine-900"/>
|
||||||
->cover_image_url ?>" alt="" class="object-cover w-full h-48 bg-pine-900"/>
|
|
||||||
<?php else: ?>
|
|
||||||
<div class="w-full h-48 bg-pine-900"></div>
|
|
||||||
<?php endif; ?>
|
|
||||||
<div class="flex items-center justify-between px-4 py-2 mb-4 lg:px-6 -mt-14 lg:-mt-16 xl:-mt-20">
|
<div class="flex items-center justify-between px-4 py-2 mb-4 lg:px-6 -mt-14 lg:-mt-16 xl:-mt-20">
|
||||||
<img src="<?= $podcast->image
|
<img src="<?= $podcast->image
|
||||||
->thumbnail_url ?>" alt="<?= $podcast->title ?>" class="h-24 rounded-full shadow-xl xl:h-36 lg:h-28 ring-4 ring-pine-50" />
|
->thumbnail_url ?>" alt="<?= $podcast->title ?>" class="h-24 rounded-full shadow-xl xl:h-36 lg:h-28 ring-4 ring-pine-50" />
|
||||||
|
@ -31,11 +31,7 @@
|
|||||||
'ActivityPub.follow.subtitle',
|
'ActivityPub.follow.subtitle',
|
||||||
) ?></h1>
|
) ?></h1>
|
||||||
<div class="flex flex-col w-full max-w-xs -mt-24 overflow-hidden bg-white shadow rounded-xl">
|
<div class="flex flex-col w-full max-w-xs -mt-24 overflow-hidden bg-white shadow rounded-xl">
|
||||||
<?php if ($actor->cover_image_url): ?>
|
|
||||||
<img src="<?= $actor->cover_image_url ?>" alt="" class="object-cover w-full h-32 bg-pine-800" />
|
<img src="<?= $actor->cover_image_url ?>" alt="" class="object-cover w-full h-32 bg-pine-800" />
|
||||||
<?php else: ?>
|
|
||||||
<div class="w-full h-32 bg-pine-800"></div>
|
|
||||||
<?php endif; ?>
|
|
||||||
<div class="flex px-4 py-2">
|
<div class="flex px-4 py-2">
|
||||||
<img src="<?= $actor->avatar_image_url ?>" alt="<?= $actor->display_name ?>"
|
<img src="<?= $actor->avatar_image_url ?>" alt="<?= $actor->display_name ?>"
|
||||||
class="w-16 h-16 mr-4 -mt-8 rounded-full shadow-xl ring-2 ring-white" />
|
class="w-16 h-16 mr-4 -mt-8 rounded-full shadow-xl ring-2 ring-white" />
|
||||||
|
Loading…
Reference in New Issue
Block a user