aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ApiBundle
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ApiBundle')
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php41
1 files changed, 23 insertions, 18 deletions
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;
14use Wallabag\CoreBundle\Entity\Tag; 14use Wallabag\CoreBundle\Entity\Tag;
15use Wallabag\CoreBundle\Event\EntryDeletedEvent; 15use Wallabag\CoreBundle\Event\EntryDeletedEvent;
16use Wallabag\CoreBundle\Event\EntrySavedEvent; 16use Wallabag\CoreBundle\Event\EntrySavedEvent;
17use Wallabag\CoreBundle\Helper\UrlHasher;
17 18
18class EntryRestController extends WallabagRestController 19class EntryRestController extends WallabagRestController
19{ 20{
@@ -56,8 +57,8 @@ class EntryRestController extends WallabagRestController
56 } 57 }
57 58
58 $urlHashMap = []; 59 $urlHashMap = [];
59 foreach($urls as $urlToHash) { 60 foreach ($urls as $urlToHash) {
60 $urlHash = hash('sha1', $urlToHash); // XXX: the hash logic would better be in a separate util to avoid duplication with GenerateUrlHashesCommand::generateHashedUrls 61 $urlHash = UrlHasher::hashUrl($urlToHash);
61 $hashedUrls[] = $urlHash; 62 $hashedUrls[] = $urlHash;
62 $urlHashMap[$urlHash] = $urlToHash; 63 $urlHashMap[$urlHash] = $urlToHash;
63 } 64 }
@@ -77,25 +78,11 @@ class EntryRestController extends WallabagRestController
77 78
78 if (!empty($url) || !empty($hashedUrl)) { 79 if (!empty($url) || !empty($hashedUrl)) {
79 $hu = array_keys($results)[0]; 80 $hu = array_keys($results)[0];
81
80 return $this->sendResponse(['exists' => $results[$hu]]); 82 return $this->sendResponse(['exists' => $results[$hu]]);
81 } 83 }
82 return $this->sendResponse($results);
83 }
84 84
85 /** 85 return $this->sendResponse($results);
86 * Replace the hashedUrl keys in $results with the unhashed URL from the
87 * request, as recorded in $urlHashMap.
88 */
89 private function replaceUrlHashes(array $results, array $urlHashMap) {
90 $newResults = [];
91 foreach($results as $hash => $res) {
92 if (isset($urlHashMap[$hash])) {
93 $newResults[$urlHashMap[$hash]] = $res;
94 } else {
95 $newResults[$hash] = $res;
96 }
97 }
98 return $newResults;
99 } 86 }
100 87
101 /** 88 /**
@@ -816,6 +803,24 @@ class EntryRestController extends WallabagRestController
816 } 803 }
817 804
818 /** 805 /**
806 * Replace the hashedUrl keys in $results with the unhashed URL from the
807 * request, as recorded in $urlHashMap.
808 */
809 private function replaceUrlHashes(array $results, array $urlHashMap)
810 {
811 $newResults = [];
812 foreach ($results as $hash => $res) {
813 if (isset($urlHashMap[$hash])) {
814 $newResults[$urlHashMap[$hash]] = $res;
815 } else {
816 $newResults[$hash] = $res;
817 }
818 }
819
820 return $newResults;
821 }
822
823 /**
819 * Retrieve value from the request. 824 * Retrieve value from the request.
820 * Used for POST & PATCH on a an entry. 825 * Used for POST & PATCH on a an entry.
821 * 826 *