Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify thumbs #2672

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Resources/Models/AlbumResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function __construct(Album $album)

// thumb
$this->cover_id = $album->cover_id;
$this->thumb = ThumbResource::make($album->thumb?->id, $album->thumb?->type, $album->thumb?->thumbUrl, $album->thumb?->thumb2xUrl, $album->thumb?->placeholderUrl);
$this->thumb = ThumbResource::fromModel($album->thumb);

// security
$this->policy = AlbumProtectionPolicy::ofBaseAlbum($album);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/Models/SmartAlbumResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(BaseSmartAlbum $smartAlbum)
$this->photos = $smartAlbum->relationLoaded('photos') ? PhotoResource::collect($smartAlbum->getPhotos()) : null;
$this->prepPhotosCollection();

$this->thumb = ThumbResource::make($smartAlbum->thumb?->id, $smartAlbum->thumb?->type, $smartAlbum->thumb?->thumbUrl, $smartAlbum->thumb?->thumb2xUrl, $smartAlbum->thumb?->placeholderUrl);
$this->thumb = ThumbResource::fromModel($smartAlbum->thumb);
$this->policy = AlbumProtectionPolicy::ofSmartAlbum($smartAlbum);
$this->rights = new AlbumRightsResource($smartAlbum);
$url = $this->getHeaderUrl($smartAlbum);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/Models/TagAlbumResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(TagAlbum $tagAlbum)
$this->prepPhotosCollection();

// thumb
$this->thumb = ThumbResource::make($tagAlbum->thumb?->id, $tagAlbum->thumb?->type, $tagAlbum->thumb?->thumbUrl, $tagAlbum->thumb?->thumb2xUrl, $tagAlbum->thumb?->placeholderUrl);
$this->thumb = ThumbResource::fromModel($tagAlbum->thumb);

// security
$this->policy = AlbumProtectionPolicy::ofBaseAlbum($tagAlbum);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/Models/ThumbAlbumResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(AbstractAlbum $data)
$date_format = Configs::getValueAsString('date_format_album_thumb');

$this->id = $data->id;
$this->thumb = $data->thumb === null ? null : new ThumbResource($data->thumb->id, $data->thumb->type, $data->thumb->thumbUrl, $data->thumb->thumb2xUrl, $data->thumb->placeholderUrl);
$this->thumb = ThumbResource::fromModel($data->thumb);
$this->title = $data->title;

if ($data instanceof BaseSmartAlbum) {
Expand Down
21 changes: 8 additions & 13 deletions app/Http/Resources/Models/ThumbResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Resources\Models;

use App\Models\Extensions\Thumb;
use Spatie\LaravelData\Data;
use Spatie\TypeScriptTransformer\Attributes\TypeScript;

Expand All @@ -24,24 +25,18 @@ public function __construct(string $id, string $type, string $thumbUrl, ?string
}

/**
* @param string|null $id
* @param string|null $type
* @param string|null $thumbUrl
* @param string|null $thumb2xUrl
* @param string|null $placeholderUrl
* Produce a thumb resource from a Thumb object if existing.
*
* @return ($id is null ? null : ThumbResource)
* @param Thumb|null $thumb
*
* @return ThumbResource|null
*/
public static function make(?string $id, ?string $type, ?string $thumbUrl, ?string $thumb2xUrl = null, ?string $placeholderUrl = null): ?self
public static function fromModel(?Thumb $thumb): ?self
{
if ($id === null) {
if ($thumb === null) {
return null;
}

/** @var string $id */
/** @var string $type */
/** @var string $thumbUrl */
/** @var string $placeholderUrl */
return new self($id, $type, $thumbUrl, $thumb2xUrl, $placeholderUrl);
return new self($thumb->id, $thumb->type, $thumb->thumbUrl, $thumb->thumb2xUrl, $thumb->placeholderUrl);
}
}