WIP
This commit is contained in:
@@ -39,7 +39,7 @@ class ImageController extends Controller
|
||||
*/
|
||||
public function show(Image $image) : BinaryFileResponse
|
||||
{
|
||||
return response()->file(Storage::disk('images')->path($image->album->id . '/original/' . $image->id));
|
||||
return response()->file(Storage::disk('images')->path($image->album->id . '/thumbnail/' . $image->id . '.avif'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,15 @@
|
||||
|
||||
namespace App\Livewire\Drawer\Album;
|
||||
|
||||
use App\Models\BatchMutation;
|
||||
use App\Services\MediaImporter;
|
||||
use App\Models\Album;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use Livewire\Features\SupportFileUploads\WithFileUploads;
|
||||
|
||||
@@ -9,9 +18,37 @@ class AddImage extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
#[Locked]
|
||||
public Album $album;
|
||||
|
||||
#[Locked]
|
||||
public bool $processing = false;
|
||||
|
||||
#[Validate(['media.*' => 'image|max:8192'])] // max:8MB
|
||||
public $media = [];
|
||||
|
||||
public function render()
|
||||
public function save(MediaImporter $importer) : void {
|
||||
$this->validate();
|
||||
|
||||
$jobs = array_map(fn($file) => $importer->import($file, $this->album), $this->media);
|
||||
$batch = Bus::batch($jobs)
|
||||
->name('Media import in ' . $this->album->name)
|
||||
->allowFailures()
|
||||
->dispatch();
|
||||
|
||||
BatchMutation::create([
|
||||
'album_id' => $this->album->id,
|
||||
'batch_id' => $batch->id,
|
||||
]);
|
||||
|
||||
$this->redirect(route('album.show', $this->album), navigate: true);
|
||||
}
|
||||
|
||||
public function mount(Album $album) : void {
|
||||
$this->album = $album;
|
||||
}
|
||||
|
||||
public function render() : View|Factory
|
||||
{
|
||||
return view('livewire.drawer.album.add-image');
|
||||
}
|
||||
|
||||
@@ -20,6 +20,10 @@ class Album extends Model
|
||||
return $this->hasMany(Image::class);
|
||||
}
|
||||
|
||||
public function mutations() : HasMany {
|
||||
return $this->hasMany(BatchMutation::class);
|
||||
}
|
||||
|
||||
public function media() : Collection {
|
||||
return $this->images;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,22 @@ class Image extends Model implements HasThumbnail
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The model's default values for attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'isCover' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['album_id'];
|
||||
|
||||
public function album(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Album::class);
|
||||
|
||||
@@ -11,7 +11,10 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
if ($this->app->environment('local')) {
|
||||
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
|
||||
$this->app->register(TelescopeServiceProvider::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user