Commit 7fdea63d authored by Yassine Doghri's avatar Yassine Doghri
Browse files

fix(persons): set person picture as optional for better ux

- use default avatar image if person image is not set
- add thumbnail and medium default avatar
images
- set default avatar images directly in public/media folder
- remove public/media's root
folder from .gitignore
- remove unnecessary copy:images script and cpy-cli package

closes #125
parent 0dd3b7e0
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -144,8 +144,6 @@ public/*
!public/robots.txt

# public media folder
public/media/*
!public/media/index.html
!public/media/podcasts
!public/media/persons

+2 −2
Original line number Diff line number Diff line
@@ -21,11 +21,11 @@ class ActivityPub extends ActivityPubBase
     * Default avatar and cover images
     * --------------------------------------------------------------------
     */
    public string $defaultAvatarImagePath = 'assets/images/castopod-avatar-default.jpg';
    public string $defaultAvatarImagePath = 'media/castopod-avatar-default_thumbnail.jpg';

    public string $defaultAvatarImageMimetype = 'image/jpeg';

    public string $defaultCoverImagePath = 'assets/images/castopod-cover-default.jpg';
    public string $defaultCoverImagePath = 'media/castopod-cover-default.jpg';

    public string $defaultCoverImageMimetype = 'image/jpeg';
}
+6 −1
Original line number Diff line number Diff line
@@ -81,11 +81,15 @@ class PersonController extends BaseController
            'full_name' => $this->request->getPost('full_name'),
            'unique_name' => $this->request->getPost('unique_name'),
            'information_url' => $this->request->getPost('information_url'),
            'image' => new Image($this->request->getFile('image')),
            'created_by' => user_id(),
            'updated_by' => user_id(),
        ]);

        $imageFile = $this->request->getFile('image');
        if ($imageFile !== null && $imageFile->isValid()) {
            $person->image = new Image($imageFile);
        }

        $personModel = new PersonModel();

        if (! $personModel->insert($person)) {
@@ -129,6 +133,7 @@ class PersonController extends BaseController
        $this->person->full_name = $this->request->getPost('full_name');
        $this->person->unique_name = $this->request->getPost('unique_name');
        $this->person->information_url = $this->request->getPost('information_url');

        $imageFile = $this->request->getFile('image');
        if ($imageFile !== null && $imageFile->isValid()) {
            $this->person->image = new Image($imageFile);
+2 −0
Original line number Diff line number Diff line
@@ -45,12 +45,14 @@ class AddPersons extends Migration
            'image_path' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
                'null' => true,
            ],
            // 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
            'image_mimetype' => [
                'type' => 'VARCHAR',
                'constraint' => 13,
                'null' => true,
            ],
            'created_by' => [
                'type' => 'INT',
+11 −3
Original line number Diff line number Diff line
@@ -47,8 +47,8 @@ class Person extends Entity
        'full_name' => 'string',
        'unique_name' => 'string',
        'information_url' => '?string',
        'image_path' => 'string',
        'image_mimetype' => 'string',
        'image_path' => '?string',
        'image_mimetype' => '?string',
        'podcast_id' => '?integer',
        'episode_id' => '?integer',
        'created_by' => 'integer',
@@ -58,8 +58,12 @@ class Person extends Entity
    /**
     * Saves a picture in `public/media/persons/`
     */
    public function setImage(Image $image): static
    public function setImage(?Image $image = null): static
    {
        if ($image === null) {
            return $this;
        }

        helper('media');

        // Save image
@@ -73,6 +77,10 @@ class Person extends Entity

    public function getImage(): Image
    {
        if ($this->attributes['image_path'] === null) {
            return new Image(null, '/castopod-avatar-default.jpg', 'image/jpeg');
        }

        return new Image(null, $this->attributes['image_path'], $this->attributes['image_mimetype']);
    }

Loading