Refresh list status over Reverb with polling fallback, clarify queued vs processing, streamline upload empty states, and seed an admin login.
90 lines
2.5 KiB
PHP
90 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Actions\StoreUploadedRecordings;
|
|
use App\Http\Requests\StoreRecordingRequest;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Validation\Rules\File;
|
|
use Livewire\Component;
|
|
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
|
use Livewire\WithFileUploads;
|
|
|
|
class UploadRecordings extends Component
|
|
{
|
|
use WithFileUploads;
|
|
|
|
/**
|
|
* @var list<TemporaryUploadedFile>
|
|
*/
|
|
public array $audio = [];
|
|
|
|
public bool $saving = false;
|
|
|
|
public bool $showCancel = true;
|
|
|
|
public function updatedAudio(): void
|
|
{
|
|
if ($this->saving || $this->audio === []) {
|
|
return;
|
|
}
|
|
|
|
$this->save();
|
|
}
|
|
|
|
public function save(?StoreUploadedRecordings $store = null): mixed
|
|
{
|
|
if ($this->saving) {
|
|
return null;
|
|
}
|
|
|
|
$this->saving = true;
|
|
|
|
try {
|
|
$store ??= app(StoreUploadedRecordings::class);
|
|
|
|
$this->validate([
|
|
'audio' => ['required', 'array', 'min:1', 'max:50'],
|
|
'audio.*' => [
|
|
'required',
|
|
File::types(StoreRecordingRequest::AUDIO_EXTENSIONS)->max('2gb'),
|
|
],
|
|
], [
|
|
'audio.required' => 'Please choose at least one audio file to upload.',
|
|
'audio.min' => 'Please choose at least one audio file to upload.',
|
|
'audio.max' => 'You can upload at most 50 files at once.',
|
|
'audio.*' => 'Unsupported audio type. Use MP3, WAV, OGG, FLAC, M4A, AAC, WebM, WMA, or AIFF.',
|
|
'audio.*.max' => 'Each audio file may not be larger than 2 GB.',
|
|
]);
|
|
|
|
$result = $store->handle(Auth::user(), $this->audio);
|
|
|
|
$this->audio = [];
|
|
|
|
if ($result['recordings'] === []) {
|
|
session()->flash('error', $result['message']);
|
|
|
|
return $this->redirect(route('recordings.create'), navigate: true);
|
|
}
|
|
|
|
session()->flash('success', $result['message']);
|
|
|
|
if (count($result['recordings']) === 1) {
|
|
return $this->redirect(
|
|
route('recordings.show', $result['recordings'][0]),
|
|
navigate: true,
|
|
);
|
|
}
|
|
|
|
return $this->redirect(route('recordings.index'), navigate: true);
|
|
} finally {
|
|
$this->saving = false;
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.upload-recordings');
|
|
}
|
|
}
|