diff --git a/scripts/thumbnails.php b/scripts/thumbnails.php new file mode 100644 index 00000000..849ac92a --- /dev/null +++ b/scripts/thumbnails.php @@ -0,0 +1,22 @@ +findAll() as $post) +{ + $thumbnailName = $postThumbnailService->generateIfNeeded($post, $size, $size); + echo '.'; +} +echo PHP_EOL; diff --git a/src/Controllers/PostContentController.php b/src/Controllers/PostContentController.php index f0574379..a5dbe523 100644 --- a/src/Controllers/PostContentController.php +++ b/src/Controllers/PostContentController.php @@ -6,7 +6,7 @@ use Szurubooru\Helpers\MimeHelper; use Szurubooru\Router; use Szurubooru\Services\NetworkingService; use Szurubooru\Services\PostService; -use Szurubooru\Services\ThumbnailService; +use Szurubooru\Services\PostThumbnailService; final class PostContentController extends AbstractController { @@ -14,20 +14,20 @@ final class PostContentController extends AbstractController private $fileDao; private $postService; private $networkingService; - private $thumbnailService; + private $postThumbnailService; public function __construct( Config $config, PublicFileDao $fileDao, PostService $postService, NetworkingService $networkingService, - ThumbnailService $thumbnailService) + PostThumbnailService $postThumbnailService) { $this->config = $config; $this->fileDao = $fileDao; $this->postService = $postService; $this->networkingService = $networkingService; - $this->thumbnailService = $thumbnailService; + $this->postThumbnailService = $postThumbnailService; } public function registerRoutes(Router $router) @@ -52,12 +52,7 @@ final class PostContentController extends AbstractController public function getPostThumbnail($postName, $size) { $post = $this->postService->getByName($postName); - - $sourceName = $post->getThumbnailSourceContentPath(); - if (!$this->fileDao->exists($sourceName)) - $sourceName = $post->getContentPath(); - - $thumbnailName = $this->thumbnailService->generateIfNeeded($sourceName, $size, $size); + $thumbnailName = $this->postThumbnailService->generateIfNeeded($post, $size, $size); $this->networkingService->serveFile($this->fileDao->getFullPath($thumbnailName)); } } diff --git a/src/Services/PostThumbnailService.php b/src/Services/PostThumbnailService.php new file mode 100644 index 00000000..a8174208 --- /dev/null +++ b/src/Services/PostThumbnailService.php @@ -0,0 +1,28 @@ +fileDao = $fileDao; + $this->thumbnailService = $thumbnailService; + } + + public function generateIfNeeded(Post $post, $width, $height) + { + $sourceName = $post->getThumbnailSourceContentPath(); + if (!$this->fileDao->exists($sourceName)) + $sourceName = $post->getContentPath(); + + return $this->thumbnailService->generateIfNeeded($sourceName, $width, $height); + } +}