diff --git a/app/Http/Requests/API/UploadRequest.php b/app/Http/Requests/API/UploadRequest.php index 9bc0ede0..a8e356da 100644 --- a/app/Http/Requests/API/UploadRequest.php +++ b/app/Http/Requests/API/UploadRequest.php @@ -3,6 +3,7 @@ namespace App\Http\Requests\API; use App\Http\Requests\Request; +use App\Rules\SupportedAudioFile; use Illuminate\Http\UploadedFile; /** @property UploadedFile $file */ @@ -12,11 +13,7 @@ class UploadRequest extends Request public function rules(): array { return [ - 'file' => [ - 'required', - 'file', - 'mimes:mp3,mpga,aac,flac,ogg,oga,opus', - ], + 'file' => ['required', 'file', new SupportedAudioFile()], ]; } } diff --git a/app/Rules/SupportedAudioFile.php b/app/Rules/SupportedAudioFile.php new file mode 100644 index 00000000..9b63e2d3 --- /dev/null +++ b/app/Rules/SupportedAudioFile.php @@ -0,0 +1,35 @@ +analyze($value->getRealPath()), 'fileformat'), + self::SUPPORTED_FORMATS + ); + + return true; + } catch (Throwable) { + return false; + } + } + + public function message(): string + { + return 'Unsupported audio file'; + } +} diff --git a/app/Services/MediaSyncService.php b/app/Services/MediaSyncService.php index 9753a61c..9c5cf6b0 100644 --- a/app/Services/MediaSyncService.php +++ b/app/Services/MediaSyncService.php @@ -79,7 +79,7 @@ class MediaSyncService ->ignoreDotFiles((bool) config('koel.ignore_dot_files')) // https://github.com/koel/koel/issues/450 ->files() ->followLinks() - ->name('/\.(mp3|ogg|m4a|flac)$/i') + ->name('/\.(mp3|wav|ogg|m4a|flac)$/i') ->in($path) ); }