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

Use API thumbnail over DIM service #22

Merged
merged 2 commits into from
May 2, 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
27 changes: 0 additions & 27 deletions app/Console/Commands/CacheImageInfo.php

This file was deleted.

4 changes: 0 additions & 4 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ protected function schedule(Schedule $schedule): void
->command('app:cache-json')
->everyFiveMinutes()
->withoutOverlapping();

$schedule
->command('app:cache-image-info')
->daily();
}

/**
Expand Down
16 changes: 7 additions & 9 deletions app/Http/Controllers/Twill/ArtworkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
use A17\Twill\Services\Listings\Filters\TableFilters;
use A17\Twill\Services\Listings\TableColumns;
use App\Libraries\Api\Builders\ApiQueryBuilder;
use App\Models\Artwork;
use App\Models\Theme;
use App\Support\Forms\Fields\QueryArtwork;
use Exception;
use Facades\App\Libraries\DamsImageService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -77,7 +77,7 @@ public function getForm(TwillModelContract $model): Form
BladePartial::make()
->view('forms.image')
->withAdditionalParams([
'src' => DamsImageService::getUrl($model->image_id, $model->mediasParams['iiif']['default'][0]),
'src' => $model->getDimImageUrl($model->mediasParams['iiif']['default'][0]),
]),
Medias::make()
->name('override')
Expand Down Expand Up @@ -183,13 +183,11 @@ public function queryArtwork(Request $request, ApiQueryBuilder $api): JsonRespon
$artwork->artist = Str::of($artwork->artist_title ?: $artwork->artist_display)
->before("\n")->trim()->__toString();

$artwork->thumbnail = $artwork->image_id
? DamsImageService::getUrl($artwork->image_id, [
'name' => 'thumbnail',
'height' => 112,
'width' => 112,
])
: null;
$artwork->thumbnail = Artwork::make((array) $artwork)->getDimImageUrl([
'name' => 'thumbnail',
'height' => 112,
'width' => 112,
]);

return $artwork;
});
Expand Down
23 changes: 13 additions & 10 deletions app/Http/Resources/ThemePromptArtworkResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Http\Resources;

use Facades\App\Libraries\DamsImageService;
use App\Models\Artwork;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

Expand All @@ -21,7 +21,7 @@ public function toArray(Request $request): array

$images = $override
? $this->getOverrideImages($override)
: $this->getApiImages($this->artwork->image_id);
: $this->getApiImages($this->artwork);

return [
'id' => $this->id,
Expand Down Expand Up @@ -80,24 +80,27 @@ private function getOverrideImages(array $image): array
];
}

private function getApiImages(?string $id): array
private function getApiImages(Artwork $artwork): array
{
if (! $id) {
return [];
if (! $artwork->thumbnail) {
return [
'img' => null,
'artwork_thumbnail' => null,
'img_medium' => null,
'img_large' => null,
];
}

$dimensions = DamsImageService::getDimensions($id);

return collect([
'img' => static::IMAGE_SIZES['img'],
'artwork_thumbnail' => static::IMAGE_SIZES['small'],
'img_medium' => static::IMAGE_SIZES['medium'],
'img_large' => static::IMAGE_SIZES['large'],
])->map(fn ($size) => [
'url' => $this->getApiImageUrl($id, $size),
'url' => $this->getApiImageUrl($artwork->id, $size),
...$this->getDimensions(
$dimensions['width'],
$dimensions['height'],
$artwork->thumbnail->width,
$artwork->thumbnail->height,
$size
),
])->toArray();
Expand Down
202 changes: 0 additions & 202 deletions app/Libraries/DamsImageService.php

This file was deleted.

27 changes: 24 additions & 3 deletions app/Models/Artwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use A17\Twill\Services\MediaLibrary\ImageService;
use App\Libraries\Api\Builders\ApiQueryBuilder;
use Exception;
use Facades\App\Libraries\DamsImageService;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
Expand All @@ -28,6 +27,7 @@ class Artwork extends Model
public const ARTWORK_API_FIELDS = [
'id',
'main_reference_number',
'thumbnail',
'artist_title',
'artist_display',
'medium_display',
Expand Down Expand Up @@ -172,15 +172,36 @@ public function image(
}

if ($this->image_id) {
return DamsImageService::getUrl(
$this->image_id,
return $this->getDimImageUrl(
$this->getMediasParams()['iiif'][$crop][0] + $params
);
}

return ImageService::getTransparentFallbackUrl();
}

public function getDimImageUrl(array $params = []): ?string
{
if (! $this->image_id) {
return null;
}

$width = $params['width'] ?? '';
$height = $params['height'] ?? '';
$size = $params['size'] ?? 'full';

$dimensions = '!3000,3000';

if ($width != '' || $height != '') {
$dimensions = '!'.$width.','.$height;
}

$baseUrl = config('dams.cdn_enabled') ? config('dams.base_url_cdn') : config('dams.base_url');
$version = config('dams.version');

return $baseUrl.$version.'/'.$this->image_id.'/'.$size.'/'.$dimensions.'/0/default.jpg';
}

public function getArtworkApiData(): stdClass
{
$nullArtwork = (object) array_combine(
Expand Down