Skip to content

Commit

Permalink
Add art by mca_chef
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdnbrk committed Dec 15, 2024
1 parent be64842 commit a29b489
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/Models/Inscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Traits\HasBtcLoongArt;
use App\Traits\HasJasmineArt;
use App\Traits\HasMcaChefArt;
use App\Traits\HasMoodzAnimations;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -15,7 +16,7 @@

class Inscription extends Model
{
use HasBtcLoongArt, HasFactory, HasJasmineArt, HasMoodzAnimations, HasSEO;
use HasBtcLoongArt, HasFactory, HasJasmineArt, HasMcaChefArt, HasMoodzAnimations, HasSEO;

protected $fillable = [
'inscription_id',
Expand Down
62 changes: 62 additions & 0 deletions app/Traits/HasMcaChefArt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace App\Traits;

use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;

trait HasMcaChefArt
{
private $cdn_base_url = 'https://cdn.pizza.ninja/';

private $mcaChefDirectory = 'images/mca_chef/';

private function getMcaChefCacheKey(): string
{
return 'mca_chef_art_'.$this->id;
}

private function getMcaChefDirectory(): string
{
return $this->mcaChefDirectory.'PN_'.$this->getInternalCollectionId().'/';
}

public function hasMcaChefImages(): bool
{
return $this->getMcaChefFileNames()->isNotEmpty();
}

public function getMcaChefFullUrls(): Collection
{
return $this->getMcaChefFileNames()->map(
fn ($path) => $this->cdn_base_url.urlencode($path)
);
}

public function getMcaChefFileNames(): Collection
{
if (Cache::has($this->getMcaChefCacheKey())) {
return Cache::get($this->getMcaChefCacheKey());
}

try {
$files = collect(Storage::disk('cloudflare')->files($this->getMcaChefDirectory()))
->filter(function ($file) {
return strtolower(
Storage::disk('cloudflare')->mimeType($file)
) === 'image/gif';
})
->values();

Cache::put($this->getMcaChefCacheKey(), $files, now()->addDay());
} catch (Exception $e) {
$files = collect([]);
Log::error('Error checking McaChef art for model: '.$this->id.': '.$e->getMessage());
}

return $files;
}
}
26 changes: 26 additions & 0 deletions resources/views/inscription.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,32 @@ class="underline"
</section>
@endif

@if($inscription->hasMcaChefImages())
<section class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8 my-6">
<div class="mx-auto max-w-2xl">
<div class="flex gap-x-2 justify-end">
@foreach($inscription->getMcaChefFullUrls() as $url)
<img
src="{{ $url }}"
class=" w-full md:w-64 border border-2 border-orange-400 rounded-lg"
alt="{{ $inscription->name }} art by mca_chef"
>
@endforeach
</div>
<div class="flex px-2 justify-end text-orange-200 text-sm">
<p class="mt-1">
art by
<a
class="underline"
href="https://x.com/mca_chef"
target="_blank"
>@mca_chef</a>
</p>
</div>
</div>
</section>
@endif

<section aria-labelledby="traits-heading" class="mt-32 bg-material-theme-ocean pt-16 pb-24 shadow-lg">
<h2 id="traits-heading" class="aria-hidden">
Traits
Expand Down

0 comments on commit a29b489

Please sign in to comment.