diff --git a/src/Controllers/PostContentController.php b/src/Routes/Posts/GetPostContent.php similarity index 52% rename from src/Controllers/PostContentController.php rename to src/Routes/Posts/GetPostContent.php index ae8c58d7..1c53007c 100644 --- a/src/Controllers/PostContentController.php +++ b/src/Routes/Posts/GetPostContent.php @@ -1,45 +1,45 @@ config = $config; $this->fileDao = $fileDao; $this->postService = $postService; $this->networkingService = $networkingService; - $this->postThumbnailService = $postThumbnailService; } - public function registerRoutes(Router $router) + public function getMethods() { - $router->get('/api/posts/:postName/content', [$this, 'getPostContent']); - $router->get('/api/posts/:postName/thumbnail/:size', [$this, 'getPostThumbnail']); + return ['GET']; } - public function getPostContent($postName) + public function getUrl() { - $post = $this->postService->getByName($postName); + return '/api/posts/:postName/content'; + } + + public function work() + { + $post = $this->postService->getByName($this->getArgument('postName')); $customFileName = sprintf('%s_%s.%s', $this->config->basic->serviceName, @@ -54,11 +54,4 @@ final class PostContentController extends AbstractController $this->networkingService->serveFile($this->fileDao->getFullPath($post->getContentPath()), $customFileName); } - - public function getPostThumbnail($postName, $size) - { - $post = $this->postService->getByName($postName); - $thumbnailName = $this->postThumbnailService->generateIfNeeded($post, $size, $size); - $this->networkingService->serveFile($this->fileDao->getFullPath($thumbnailName)); - } } diff --git a/src/Routes/Posts/GetPostThumbnail.php b/src/Routes/Posts/GetPostThumbnail.php new file mode 100644 index 00000000..253d662f --- /dev/null +++ b/src/Routes/Posts/GetPostThumbnail.php @@ -0,0 +1,50 @@ +config = $config; + $this->fileDao = $fileDao; + $this->postService = $postService; + $this->networkingService = $networkingService; + $this->postThumbnailService = $postThumbnailService; + } + + public function getMethods() + { + return ['GET']; + } + + public function getUrl() + { + return '/api/posts/:postName/thumbnail/:size'; + } + + public function work() + { + $size = $this->getArgument('size'); + $post = $this->postService->getByName($this->getArgument('postName')); + $thumbnailName = $this->postThumbnailService->generateIfNeeded($post, $size, $size); + $this->networkingService->serveFile($this->fileDao->getFullPath($thumbnailName)); + } +} diff --git a/src/di.php b/src/di.php index c71e2586..d2bb4c16 100644 --- a/src/di.php +++ b/src/di.php @@ -60,7 +60,6 @@ return [ $container->get(\Szurubooru\Controllers\UserController::class), $container->get(\Szurubooru\Controllers\UserAvatarController::class), $container->get(\Szurubooru\Controllers\PostController::class), - $container->get(\Szurubooru\Controllers\PostContentController::class), $container->get(\Szurubooru\Controllers\PostNotesController::class), $container->get(\Szurubooru\Controllers\ScoreController::class), $container->get(\Szurubooru\Controllers\TagController::class), @@ -80,6 +79,8 @@ return [ $container->get(\Szurubooru\Routes\Favorites\GetFavoriteUsers::class), $container->get(\Szurubooru\Routes\Favorites\AddToFavorites::class), $container->get(\Szurubooru\Routes\Favorites\RemoveFromFavorites::class), + $container->get(\Szurubooru\Routes\Posts\GetPostContent::class), + $container->get(\Szurubooru\Routes\Posts\GetPostThumbnail::class), ]; }), ];