X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FApiBundle%2FController%2FEntryRestController.php;h=77eb489e61ea099e4326b4883dc1711760bd177e;hb=4a5516376bf4c8b0cdc1e81d24ce1cca68425785;hp=17b53a0189d6284e849332d373511fc520e5e391;hpb=d5744bf0dfdbee4dbbe380d8a076d07b89fc76e6;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 17b53a01..77eb489e 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php @@ -14,6 +14,7 @@ use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Event\EntryDeletedEvent; use Wallabag\CoreBundle\Event\EntrySavedEvent; +use Wallabag\CoreBundle\Helper\UrlHasher; class EntryRestController extends WallabagRestController { @@ -56,8 +57,8 @@ class EntryRestController extends WallabagRestController } $urlHashMap = []; - foreach($urls as $urlToHash) { - $urlHash = hash('sha1', $urlToHash); // XXX: the hash logic would better be in a separate util to avoid duplication with GenerateUrlHashesCommand::generateHashedUrls + foreach ($urls as $urlToHash) { + $urlHash = UrlHasher::hashUrl($urlToHash); $hashedUrls[] = $urlHash; $urlHashMap[$urlHash] = $urlToHash; } @@ -77,25 +78,11 @@ class EntryRestController extends WallabagRestController if (!empty($url) || !empty($hashedUrl)) { $hu = array_keys($results)[0]; + return $this->sendResponse(['exists' => $results[$hu]]); } - return $this->sendResponse($results); - } - /** - * Replace the hashedUrl keys in $results with the unhashed URL from the - * request, as recorded in $urlHashMap. - */ - private function replaceUrlHashes(array $results, array $urlHashMap) { - $newResults = []; - foreach($results as $hash => $res) { - if (isset($urlHashMap[$hash])) { - $newResults[$urlHashMap[$hash]] = $res; - } else { - $newResults[$hash] = $res; - } - } - return $newResults; + return $this->sendResponse($results); } /** @@ -815,6 +802,24 @@ class EntryRestController extends WallabagRestController return $this->sendResponse($results); } + /** + * Replace the hashedUrl keys in $results with the unhashed URL from the + * request, as recorded in $urlHashMap. + */ + private function replaceUrlHashes(array $results, array $urlHashMap) + { + $newResults = []; + foreach ($results as $hash => $res) { + if (isset($urlHashMap[$hash])) { + $newResults[$urlHashMap[$hash]] = $res; + } else { + $newResults[$hash] = $res; + } + } + + return $newResults; + } + /** * Retrieve value from the request. * Used for POST & PATCH on a an entry.