mirror of
https://github.com/koel/koel
synced 2024-12-20 17:43:36 +00:00
37 lines
840 B
PHP
37 lines
840 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests\API;
|
|
|
|
use App\Rules\ImageData;
|
|
|
|
abstract class AbstractMediaImageUpdateRequest extends Request
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return auth()->user()->is_admin;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
$this->getImageFieldName() => ['string', 'required', new ImageData()]
|
|
];
|
|
}
|
|
|
|
public function getFileContentAsBinaryString(): string
|
|
{
|
|
[$_, $data] = explode(',', $this->{$this->getImageFieldName()});
|
|
|
|
return base64_decode($data);
|
|
}
|
|
|
|
public function getFileExtension(): string
|
|
{
|
|
[$type, $data] = explode(';', $this->{$this->getImageFieldName()});
|
|
[$_, $extension] = explode('/', $type);
|
|
|
|
return $extension;
|
|
}
|
|
|
|
abstract protected function getImageFieldName(): string;
|
|
}
|