]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/front/controller/admin/MetadataController.php
Add a setting to retrieve bookmark metadata asynchrounously
[github/shaarli/Shaarli.git] / application / front / controller / admin / MetadataController.php
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Shaarli\Front\Controller\Admin;
6
7 use Slim\Http\Request;
8 use Slim\Http\Response;
9
10 /**
11 * Controller used to retrieve/update bookmark's metadata.
12 */
13 class MetadataController extends ShaarliAdminController
14 {
15 /**
16 * GET /admin/metadata/{url} - Attempt to retrieve the bookmark title from provided URL.
17 */
18 public function ajaxRetrieveTitle(Request $request, Response $response): Response
19 {
20 $url = $request->getParam('url');
21
22 // Only try to extract metadata from URL with HTTP(s) scheme
23 if (!empty($url) && strpos(get_url_scheme($url) ?: '', 'http') !== false) {
24 return $response->withJson($this->container->metadataRetriever->retrieve($url));
25 }
26
27 return $response->withJson([]);
28 }
29 }