Admin Menü neu geordnet.
Introduced a two-tier media pipeline with dynamic disks, asset tracking, admin controls, and alerting around
upload/archival workflows.
- Added storage metadata + asset tables and models so every photo/variant knows where it lives
(database/migrations/2025_10_20_090000_create_media_storage_targets_table.php, database/ migrations/2025_10_20_090200_create_event_media_assets_table.php, app/Models/MediaStorageTarget.php:1, app/
Models/EventMediaAsset.php:1, app/Models/EventStorageAssignment.php:1, app/Models/Event.php:27).
- Rewired guest and tenant uploads to pick the event’s hot disk, persist EventMediaAsset records, compute
checksums, and clean up on delete (app/Http/Controllers/Api/EventPublicController.php:243, app/Http/
Controllers/Api/Tenant/PhotoController.php:25, app/Models/Photo.php:25).
- Implemented storage services, archival job scaffolding, monitoring config, and queue-failure notifications for upload issues (app/Services/Storage/EventStorageManager.php:16, app/Services/Storage/
StorageHealthService.php:9, app/Jobs/ArchiveEventMediaAssets.php:16, app/Providers/AppServiceProvider.php:39, app/Notifications/UploadPipelineFailed.php:8, config/storage-monitor.php:1).
- Seeded default hot/cold targets and exposed super-admin tooling via a Filament resource and capacity widget (database/seeders/MediaStorageTargetSeeder.php:13, database/seeders/DatabaseSeeder.php:17, app/Filament/Resources/MediaStorageTargetResource.php:1, app/Filament/Widgets/StorageCapacityWidget.php:12, app/Providers/Filament/SuperAdminPanelProvider.php:47).
- Dropped cron skeletons and artisan placeholders to schedule storage monitoring, archival dispatch, and upload queue health checks (cron/storage_monitor.sh, cron/archive_dispatcher.sh, cron/upload_queue_health.sh, routes/console.php:9).
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Http\Resources\Tenant\PhotoResource;
|
||||
use App\Models\Event;
|
||||
use App\Models\Photo;
|
||||
use App\Support\ImageHelper;
|
||||
use App\Services\Storage\EventStorageManager;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
@@ -16,9 +17,14 @@ use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Models\EventMediaAsset;
|
||||
|
||||
class PhotoController extends Controller
|
||||
{
|
||||
public function __construct(private readonly EventStorageManager $eventStorageManager)
|
||||
{
|
||||
}
|
||||
/**
|
||||
* Display a listing of the event's photos.
|
||||
*/
|
||||
@@ -81,17 +87,21 @@ class PhotoController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
// Determine storage target
|
||||
$event->load('storageAssignments.storageTarget');
|
||||
$disk = $this->eventStorageManager->getHotDiskForEvent($event);
|
||||
|
||||
// Generate unique filename
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
$filename = Str::uuid() . '.' . $extension;
|
||||
$path = "events/{$eventSlug}/photos/{$filename}";
|
||||
|
||||
// Store original file
|
||||
Storage::disk('public')->put($path, file_get_contents($file->getRealPath()));
|
||||
Storage::disk($disk)->put($path, file_get_contents($file->getRealPath()));
|
||||
|
||||
// Generate thumbnail
|
||||
$thumbnailPath = "events/{$eventSlug}/thumbnails/{$filename}";
|
||||
$thumbnailRelative = ImageHelper::makeThumbnailOnDisk('public', $path, $thumbnailPath, 400);
|
||||
$thumbnailRelative = ImageHelper::makeThumbnailOnDisk($disk, $path, $thumbnailPath, 400);
|
||||
if ($thumbnailRelative) {
|
||||
$thumbnailPath = $thumbnailRelative;
|
||||
}
|
||||
@@ -105,7 +115,7 @@ class PhotoController extends Controller
|
||||
'size' => $file->getSize(),
|
||||
'path' => $path,
|
||||
'thumbnail_path' => $thumbnailPath,
|
||||
'width' => null, // To be filled by image processing
|
||||
'width' => null, // Filled below
|
||||
'height' => null,
|
||||
'status' => 'pending', // Requires moderation
|
||||
'uploader_id' => null,
|
||||
@@ -113,8 +123,38 @@ class PhotoController extends Controller
|
||||
'user_agent' => $request->userAgent(),
|
||||
]);
|
||||
|
||||
// Record primary asset metadata
|
||||
$checksum = hash_file('sha256', $file->getRealPath());
|
||||
$asset = $this->eventStorageManager->recordAsset($event, $disk, $path, [
|
||||
'variant' => 'original',
|
||||
'mime_type' => $file->getMimeType(),
|
||||
'size_bytes' => $file->getSize(),
|
||||
'checksum' => $checksum,
|
||||
'status' => 'hot',
|
||||
'processed_at' => now(),
|
||||
'photo_id' => $photo->id,
|
||||
]);
|
||||
|
||||
if ($thumbnailRelative) {
|
||||
$this->eventStorageManager->recordAsset($event, $disk, $thumbnailRelative, [
|
||||
'variant' => 'thumbnail',
|
||||
'mime_type' => 'image/jpeg',
|
||||
'status' => 'hot',
|
||||
'processed_at' => now(),
|
||||
'photo_id' => $photo->id,
|
||||
'size_bytes' => Storage::disk($disk)->exists($thumbnailRelative)
|
||||
? Storage::disk($disk)->size($thumbnailRelative)
|
||||
: null,
|
||||
'meta' => [
|
||||
'source_variant_id' => $asset->id,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
$photo->update(['media_asset_id' => $asset->id]);
|
||||
|
||||
// Get image dimensions
|
||||
list($width, $height) = getimagesize($file->getRealPath());
|
||||
[$width, $height] = getimagesize($file->getRealPath());
|
||||
$photo->update(['width' => $width, 'height' => $height]);
|
||||
|
||||
$photo->load('event')->loadCount('likes');
|
||||
@@ -202,15 +242,33 @@ class PhotoController extends Controller
|
||||
return response()->json(['error' => 'Photo not found'], 404);
|
||||
}
|
||||
|
||||
// Delete from storage
|
||||
Storage::disk('public')->delete([
|
||||
$photo->path,
|
||||
$photo->thumbnail_path,
|
||||
]);
|
||||
$assets = EventMediaAsset::where('photo_id', $photo->id)->get();
|
||||
|
||||
foreach ($assets as $asset) {
|
||||
try {
|
||||
Storage::disk($asset->disk)->delete($asset->path);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('Failed to delete asset from storage', [
|
||||
'asset_id' => $asset->id,
|
||||
'disk' => $asset->disk,
|
||||
'path' => $asset->path,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure legacy paths are removed if assets missing
|
||||
if ($assets->isEmpty()) {
|
||||
$fallbackDisk = $this->eventStorageManager->getHotDiskForEvent($event);
|
||||
Storage::disk($fallbackDisk)->delete([$photo->path, $photo->thumbnail_path]);
|
||||
}
|
||||
|
||||
// Delete record and likes
|
||||
DB::transaction(function () use ($photo) {
|
||||
DB::transaction(function () use ($photo, $assets) {
|
||||
$photo->likes()->delete();
|
||||
if ($assets->isNotEmpty()) {
|
||||
EventMediaAsset::whereIn('id', $assets->pluck('id'))->delete();
|
||||
}
|
||||
$photo->delete();
|
||||
});
|
||||
|
||||
@@ -474,16 +532,19 @@ class PhotoController extends Controller
|
||||
return response()->json(['error' => 'Invalid event ID'], 400);
|
||||
}
|
||||
|
||||
$event->load('storageAssignments.storageTarget');
|
||||
$disk = $this->eventStorageManager->getHotDiskForEvent($event);
|
||||
|
||||
$file = $request->file('photo');
|
||||
$filename = $request->filename;
|
||||
$path = "events/{$eventSlug}/photos/{$filename}";
|
||||
|
||||
// Store file
|
||||
Storage::disk('public')->put($path, file_get_contents($file->getRealPath()));
|
||||
Storage::disk($disk)->put($path, file_get_contents($file->getRealPath()));
|
||||
|
||||
// Generate thumbnail
|
||||
$thumbnailPath = "events/{$eventSlug}/thumbnails/{$filename}";
|
||||
$thumbnailRelative = ImageHelper::makeThumbnailOnDisk('public', $path, $thumbnailPath, 400);
|
||||
$thumbnailRelative = ImageHelper::makeThumbnailOnDisk($disk, $path, $thumbnailPath, 400);
|
||||
if ($thumbnailRelative) {
|
||||
$thumbnailPath = $thumbnailRelative;
|
||||
}
|
||||
@@ -502,10 +563,38 @@ class PhotoController extends Controller
|
||||
'user_agent' => $request->userAgent(),
|
||||
]);
|
||||
|
||||
// Get dimensions
|
||||
list($width, $height) = getimagesize($file->getRealPath());
|
||||
[$width, $height] = getimagesize($file->getRealPath());
|
||||
$photo->update(['width' => $width, 'height' => $height]);
|
||||
|
||||
$checksum = hash_file('sha256', $file->getRealPath());
|
||||
$asset = $this->eventStorageManager->recordAsset($event, $disk, $path, [
|
||||
'variant' => 'original',
|
||||
'mime_type' => $file->getMimeType(),
|
||||
'size_bytes' => $file->getSize(),
|
||||
'checksum' => $checksum,
|
||||
'status' => 'hot',
|
||||
'processed_at' => now(),
|
||||
'photo_id' => $photo->id,
|
||||
]);
|
||||
|
||||
if ($thumbnailRelative) {
|
||||
$this->eventStorageManager->recordAsset($event, $disk, $thumbnailRelative, [
|
||||
'variant' => 'thumbnail',
|
||||
'mime_type' => 'image/jpeg',
|
||||
'status' => 'hot',
|
||||
'processed_at' => now(),
|
||||
'photo_id' => $photo->id,
|
||||
'size_bytes' => Storage::disk($disk)->exists($thumbnailRelative)
|
||||
? Storage::disk($disk)->size($thumbnailRelative)
|
||||
: null,
|
||||
'meta' => [
|
||||
'source_variant_id' => $asset->id,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
$photo->update(['media_asset_id' => $asset->id]);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Upload successful. Awaiting moderation.',
|
||||
'photo_id' => $photo->id,
|
||||
|
||||
Reference in New Issue
Block a user