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.php40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index 5c850091..06520af9 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -27,8 +27,10 @@ class EntryRestController extends WallabagRestController
27 * @ApiDoc( 27 * @ApiDoc(
28 * parameters={ 28 * parameters={
29 * {"name"="return_id", "dataType"="string", "required"=false, "format"="1 or 0", "description"="Set 1 if you want to retrieve ID in case entry(ies) exists, 0 by default"}, 29 * {"name"="return_id", "dataType"="string", "required"=false, "format"="1 or 0", "description"="Set 1 if you want to retrieve ID in case entry(ies) exists, 0 by default"},
30 * {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"}, 30 * {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="DEPRECATED, use hashed_url instead"},
31 * {"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"} 31 * {"name"="urls", "dataType"="string", "required"=false, "format"="An array of urls (?urls[]=http...&urls[]=http...)", "description"="DEPRECATED, use hashed_urls instead"},
32 * {"name"="hashed_url", "dataType"="string", "required"=false, "format"="A hashed url", "description"="Hashed url using SHA1 to check if it exists"},
33 * {"name"="hashed_urls", "dataType"="string", "required"=false, "format"="An array of hashed urls (?hashed_urls[]=xxx...&hashed_urls[]=xxx...)", "description"="An array of hashed urls using SHA1 to check if they exist"}
32 * } 34 * }
33 * ) 35 * )
34 * 36 *
@@ -37,17 +39,30 @@ class EntryRestController extends WallabagRestController
37 public function getEntriesExistsAction(Request $request) 39 public function getEntriesExistsAction(Request $request)
38 { 40 {
39 $this->validateAuthentication(); 41 $this->validateAuthentication();
42 $repo = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
40 43
41 $returnId = (null === $request->query->get('return_id')) ? false : (bool) $request->query->get('return_id'); 44 $returnId = (null === $request->query->get('return_id')) ? false : (bool) $request->query->get('return_id');
45
42 $urls = $request->query->get('urls', []); 46 $urls = $request->query->get('urls', []);
47 $hashedUrls = $request->query->get('hashed_urls', []);
43 48
44 // handle multiple urls first 49 // handle multiple urls first
50 if (!empty($hashedUrls)) {
51 $results = [];
52 foreach ($hashedUrls as $hashedUrl) {
53 $res = $repo->findByHashedUrlAndUserId($hashedUrl, $this->getUser()->getId());
54
55 $results[$hashedUrl] = $this->returnExistInformation($res, $returnId);
56 }
57
58 return $this->sendResponse($results);
59 }
60
61 // @deprecated, to be remove in 3.0
45 if (!empty($urls)) { 62 if (!empty($urls)) {
46 $results = []; 63 $results = [];
47 foreach ($urls as $url) { 64 foreach ($urls as $url) {
48 $res = $this->getDoctrine() 65 $res = $repo->findByUrlAndUserId($url, $this->getUser()->getId());
49 ->getRepository('WallabagCoreBundle:Entry')
50 ->findByUrlAndUserId($url, $this->getUser()->getId());
51 66
52 $results[$url] = $this->returnExistInformation($res, $returnId); 67 $results[$url] = $this->returnExistInformation($res, $returnId);
53 } 68 }
@@ -57,18 +72,21 @@ class EntryRestController extends WallabagRestController
57 72
58 // let's see if it is a simple url? 73 // let's see if it is a simple url?
59 $url = $request->query->get('url', ''); 74 $url = $request->query->get('url', '');
75 $hashedUrl = $request->query->get('hashed_url', '');
60 76
61 if (empty($url)) { 77 if (empty($url) && empty($hashedUrl)) {
62 throw $this->createAccessDeniedException('URL is empty?, logged user id: ' . $this->getUser()->getId()); 78 throw $this->createAccessDeniedException('URL is empty?, logged user id: ' . $this->getUser()->getId());
63 } 79 }
64 80
65 $res = $this->getDoctrine() 81 $method = 'findByUrlAndUserId';
66 ->getRepository('WallabagCoreBundle:Entry') 82 if (!empty($hashedUrl)) {
67 ->findByUrlAndUserId($url, $this->getUser()->getId()); 83 $method = 'findByHashedUrlAndUserId';
84 $url = $hashedUrl;
85 }
68 86
69 $exists = $this->returnExistInformation($res, $returnId); 87 $res = $repo->$method($url, $this->getUser()->getId());
70 88
71 return $this->sendResponse(['exists' => $exists]); 89 return $this->sendResponse(['exists' => $this->returnExistInformation($res, $returnId)]);
72 } 90 }
73 91
74 /** 92 /**