- Neue PM-Bilder/Anhänge liegen auf der privaten local-Disk; Auslieferung über kontrollierte Media-Routen mit gemeinsamer Zugriffslogik (AuthorizesPressReleaseMediaAccess). Öffentliche Medien werden aus den geladenen Modellen ermittelt (weniger Queries) und länger gecacht. - Anonyme Token-Vorschau lädt Bilder über temporär signierte URLs (Fix#5). - API-Resource baut Variant-URLs über die Media-Route statt /storage (Fix#4). Storage-Schicht prüft zusätzlich den serverseitigen MIME-Type (M5). - press-releases:privatize-media migriert Bestandsmedien. Deployment: einmalig `php artisan press-releases:privatize-media` ausführen. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
49 lines
1.7 KiB
PHP
49 lines
1.7 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Resources;
|
||
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Http\Resources\Json\JsonResource;
|
||
|
||
class PressReleaseImageResource extends JsonResource
|
||
{
|
||
/**
|
||
* Transform the resource into an array.
|
||
*
|
||
* @return array<string, mixed>
|
||
*/
|
||
public function toArray(Request $request): array
|
||
{
|
||
$variants = is_array($this->variants) ? $this->variants : [];
|
||
$variantUrls = [];
|
||
|
||
// Variant-URLs über das Model auflösen, damit sie – wie die Original-URL –
|
||
// je nach Disk entweder direkt (public) oder über die geschützte
|
||
// Media-Route (local) zeigen. Sonst 404 für private Medien.
|
||
foreach ($variants as $key => $relativePath) {
|
||
if (is_string($relativePath) && filled($relativePath) && filled($url = $this->variantUrl($key))) {
|
||
$variantUrls[$key] = $url;
|
||
}
|
||
}
|
||
|
||
return [
|
||
'id' => $this->id,
|
||
'press_release_id' => $this->press_release_id,
|
||
'url' => $this->url(),
|
||
'urls' => array_merge(['original' => $this->url()], $variantUrls),
|
||
'variants' => $variants,
|
||
'disk' => $this->disk,
|
||
'path' => $this->path,
|
||
'title' => $this->title,
|
||
'description' => $this->description,
|
||
'copyright' => $this->copyright,
|
||
'is_preview' => $this->is_preview,
|
||
'sort_order' => $this->sort_order,
|
||
'width' => $this->width,
|
||
'height' => $this->height,
|
||
'mime' => $this->mime,
|
||
'created_at' => $this->created_at?->toIso8601String(),
|
||
'updated_at' => $this->updated_at?->toIso8601String(),
|
||
];
|
||
}
|
||
}
|