forked from leftypol/leftypol
FallbackMediaHandler.php: add closeHandle and implement installMediaAndGenerateThumb
This commit is contained in:
parent
4eee6cb58f
commit
70bd777493
1 changed files with 39 additions and 2 deletions
|
@ -2,6 +2,8 @@
|
|||
namespace Vichan\Service\Media;
|
||||
|
||||
use Vichan\Data\ThumbGenerationResult;
|
||||
use Vichan\Functions\Fs;
|
||||
use Mimey\MimeTypes;
|
||||
|
||||
|
||||
class FallbackMediaHandler implements MediaHandler {
|
||||
|
@ -9,14 +11,16 @@ class FallbackMediaHandler implements MediaHandler {
|
|||
private int $width;
|
||||
private int $height;
|
||||
private string $mime;
|
||||
private MimeTypes $mime_types;
|
||||
|
||||
|
||||
public function __construct(ImageMetadataReader $image_metadate_reader, string $default_thumb_path) {
|
||||
public function __construct(ImageMetadataReader $image_metadate_reader, string $default_thumb_path, MimeTypes $mime_types) {
|
||||
$res = $image_metadate_reader->getMetadata($default_thumb_path);
|
||||
$this->path = $default_thumb_path;
|
||||
$this->width = $res->width;
|
||||
$this->height = $res->height;
|
||||
$this->mime = $res->mime;
|
||||
$this->mime_types = $mime_types;
|
||||
}
|
||||
|
||||
public function supportsMime(string $mime): bool {
|
||||
|
@ -24,7 +28,40 @@ class FallbackMediaHandler implements MediaHandler {
|
|||
}
|
||||
|
||||
public function openHandle(string $file_path, string $file_mime, int $file_kind): mixed {
|
||||
return null;
|
||||
return [ $file_path, $file_kind ];
|
||||
}
|
||||
|
||||
public function closeHandle(mixed $handle) {
|
||||
// No-op
|
||||
}
|
||||
|
||||
public function installMediaAndGenerateThumb(
|
||||
mixed $handle,
|
||||
string $media_preferred_out_file_path,
|
||||
string $thumb_preferred_out_file_path,
|
||||
string $thumb_preferred_out_mime,
|
||||
int $thumb_max_width,
|
||||
int $thumb_max_height
|
||||
) {
|
||||
list($source_file_path, $source_file_kind) = $handle;
|
||||
|
||||
if ($source_file_kind === self::FILE_KIND_UPLOADED) {
|
||||
if (!Fs\move_or_copy_uploaded($source_file_path, $media_preferred_out_file_path)) {
|
||||
throw new \RuntimeException("Could not move or copy uploaded file '$source_file_path' to '$media_preferred_out_file_path'");
|
||||
}
|
||||
} else {
|
||||
if (!Fs\link_or_copy($source_file_path, $media_preferred_out_file_path)) {
|
||||
throw new \RuntimeException("Could not link or copy '$source_file_path' to '$media_preferred_out_file_path'");
|
||||
}
|
||||
}
|
||||
|
||||
return $this->generateThumb(
|
||||
$handle,
|
||||
$thumb_preferred_out_file_path,
|
||||
$thumb_preferred_out_mime,
|
||||
$thumb_max_width,
|
||||
$thumb_max_height
|
||||
);
|
||||
}
|
||||
|
||||
public function generateThumb(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue