aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ApiBundle/Controller/EntryRestController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller/EntryRestController.php')
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index 4801811d..2b07cb59 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -21,8 +21,8 @@ class EntryRestController extends WallabagRestController
21 * 21 *
22 * @ApiDoc( 22 * @ApiDoc(
23 * parameters={ 23 * parameters={
24 * {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"}, 24 * {"name"="hashedurl", "dataType"="string", "required"=true, "format"="An url", "description"="SHA512 Url to check if it exists"},
25 * {"name"="urls", "dataType"="string", "required"=false, "format"="An array of urls (?urls[]=http...&urls[]=http...)", "description"="Urls (as an array) to check if it exists"} 25 * {"name"="hashedurls", "dataType"="string", "required"=false, "format"="An array of urls (?urls[]=http...&urls[]=http...)", "description"="SHA512 Urls (as an array) to check if it exists"}
26 * } 26 * }
27 * ) 27 * )
28 * 28 *
@@ -32,33 +32,38 @@ class EntryRestController extends WallabagRestController
32 { 32 {
33 $this->validateAuthentication(); 33 $this->validateAuthentication();
34 34
35 $urls = $request->query->get('urls', []); 35 $hashedUrls = $request->query->get('hashedurls', []);
36 36
37 // handle multiple urls first 37 // handle multiple urls first
38 if (!empty($urls)) { 38 if (!empty($hashedUrls)) {
39 $results = []; 39 $results = [];
40 foreach ($urls as $url) { 40 foreach ($hashedUrls as $hashedUrl) {
41 $res = $this->getDoctrine() 41 $res = $this->getDoctrine()
42 ->getRepository('WallabagCoreBundle:Entry') 42 ->getRepository('WallabagCoreBundle:Entry')
43 ->findByUrlAndUserId($url, $this->getUser()->getId()); 43 ->findOneBy([
44 'hashedUrl' => $hashedUrl,
45 'user' => $this->getUser()->getId(),
46 ]);
44 47
45 $results[$url] = $res instanceof Entry ? $res->getId() : false; 48 $results[$hashedUrl] = $res instanceof Entry ? $res->getId() : false;
46 } 49 }
47 50
48 return $this->sendResponse($results); 51 return $this->sendResponse($results);
49 } 52 }
50 53
51 // let's see if it is a simple url? 54 // let's see if it is a simple url?
52 $url = $request->query->get('url', ''); 55 $hashedUrl = $request->query->get('hashedurl', '');
53 56
54 if (empty($url)) { 57 if (empty($hashedUrl)) {
55 throw $this->createAccessDeniedException('URL is empty?, logged user id: '.$this->getUser()->getId()); 58 throw $this->createAccessDeniedException('URL is empty?, logged user id: '.$this->getUser()->getId());
56 } 59 }
57 60
58 $res = $this->getDoctrine() 61 $res = $this->getDoctrine()
59 ->getRepository('WallabagCoreBundle:Entry') 62 ->getRepository('WallabagCoreBundle:Entry')
60 ->findByUrlAndUserId($url, $this->getUser()->getId()); 63 ->findOneBy([
61 64 'hashedUrl' => $hashedUrl,
65 'user' => $this->getUser()->getId(),
66 ]);
62 $exists = $res instanceof Entry ? $res->getId() : false; 67 $exists = $res instanceof Entry ? $res->getId() : false;
63 68
64 return $this->sendResponse(['exists' => $exists]); 69 return $this->sendResponse(['exists' => $exists]);