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