3 declare(strict_types
=1);
5 namespace Shaarli\Front\Controller\Admin
;
7 use Shaarli\Bookmark\Exception\BookmarkNotFoundException
;
8 use Shaarli\Render\TemplatePage
;
10 use Slim\Http\Response
;
13 * Class ToolsController
15 * Slim controller used to handle thumbnails update.
17 class ThumbnailsController
extends ShaarliAdminController
20 * GET /admin/thumbnails - Display thumbnails update page
22 public function index(Request
$request, Response
$response): Response
25 foreach ($this->container
->bookmarkService
->search() as $bookmark) {
26 // A note or not HTTP(S)
27 if ($bookmark->isNote() || !startsWith(strtolower($bookmark->getUrl()), 'http')) {
31 $ids[] = $bookmark->getId();
34 $this->assignView('ids', $ids);
37 t('Thumbnails update') .' - '. $this->container
->conf
->get('general.title', 'Shaarli')
40 return $response->write($this->render(TemplatePage
::THUMBNAILS
));
44 * PATCH /admin/shaare/{id}/thumbnail-update - Route for AJAX calls
46 public function ajaxUpdate(Request
$request, Response
$response, array $args): Response
48 $id = $args['id'] ?? null;
50 if (false === ctype_digit($id)) {
51 return $response->withStatus(400);
55 $bookmark = $this->container
->bookmarkService
->get($id);
56 } catch (BookmarkNotFoundException
$e) {
57 return $response->withStatus(404);
60 $bookmark->setThumbnail($this->container
->thumbnailer
->get($bookmark->getUrl()));
61 $this->container
->bookmarkService
->set($bookmark);
63 return $response->withJson($this->container
->formatterFactory
->getFormatter('raw')->format($bookmark));