<?php

namespace App\Http\Controllers;

use App\Models\Upload;
use Illuminate\Support\Facades\Storage;

class MediaController extends Controller
{
    public function artikelGambar(Upload $upload)
    {
        abort_unless($upload->isStoredIn('artikel/gambar') && $upload->existsOnPublicDisk(), 404);

        return Storage::disk('public')->response(
            $upload->normalizedStoragePath(),
            $upload->file_name,
            ['Content-Type' => $upload->mime_type ?: 'image/jpeg']
        );
    }

    public function artikelFile(Upload $upload)
    {
        abort_unless($upload->isStoredIn('artikel/file') && $upload->existsOnPublicDisk(), 404);

        return Storage::disk('public')->download(
            $upload->normalizedStoragePath(),
            $upload->file_name
        );
    }
}
