mirror of
https://github.com/koel/koel
synced 2024-12-27 21:13:06 +00:00
29 lines
715 B
PHP
29 lines
715 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests\API;
|
|
|
|
use App\Rules\ImageData;
|
|
use Illuminate\Support\Str;
|
|
|
|
abstract class MediaImageUpdateRequest extends Request
|
|
{
|
|
/** @return array<mixed> */
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
$this->getImageFieldName() => ['string', 'required', new ImageData()],
|
|
];
|
|
}
|
|
|
|
public function getFileContentAsBinaryString(): string
|
|
{
|
|
return base64_decode(Str::after($this->{$this->getImageFieldName()}, ','), true);
|
|
}
|
|
|
|
public function getFileExtension(): string
|
|
{
|
|
return Str::after(Str::before($this->{$this->getImageFieldName()}, ';'), '/');
|
|
}
|
|
|
|
abstract protected function getImageFieldName(): string;
|
|
}
|