aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ApiBundle/Controller/EntryRestController.php
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2017-05-28 14:53:04 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2019-04-01 13:24:40 +0200
commitbfe02a0b481055bb4e799200c8daa9a0ad987c71 (patch)
treeb82431b5ca4b24de1ddab6f0407e1ae7cda54083 /src/Wallabag/ApiBundle/Controller/EntryRestController.php
parent3620dae1e6b3fab5a4ba4001b4581ce7ed795996 (diff)
downloadwallabag-bfe02a0b481055bb4e799200c8daa9a0ad987c71.tar.gz
wallabag-bfe02a0b481055bb4e799200c8daa9a0ad987c71.tar.zst
wallabag-bfe02a0b481055bb4e799200c8daa9a0ad987c71.zip
Hash the urls to check if they exist
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller/EntryRestController.php')
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index 5c850091..26746f7d 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -29,6 +29,8 @@ class EntryRestController extends WallabagRestController
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"="Url to check if it exists"},
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"="Urls (as an array) to check if it exists"}
32 * {"name"="hashedurl", "dataType"="string", "required"=true, "format"="An url", "description"="Md5 url to check if it exists"},
33 * {"name"="hashedurls", "dataType"="string", "required"=false, "format"="An array of urls (?urls[]=http...&urls[]=http...)", "description"="Md5 urls (as an array) to check if it exists"}
32 * } 34 * }
33 * ) 35 * )
34 * 36 *
@@ -41,34 +43,46 @@ class EntryRestController extends WallabagRestController
41 $returnId = (null === $request->query->get('return_id')) ? false : (bool) $request->query->get('return_id'); 43 $returnId = (null === $request->query->get('return_id')) ? false : (bool) $request->query->get('return_id');
42 $urls = $request->query->get('urls', []); 44 $urls = $request->query->get('urls', []);
43 45
46 $hashedUrls = $request->query->get('hashedurls', []);
47
44 // handle multiple urls first 48 // handle multiple urls first
45 if (!empty($urls)) { 49 if (!empty($hashedUrls)) {
46 $results = []; 50 $results = [];
47 foreach ($urls as $url) { 51 foreach ($hashedUrls as $hashedUrl) {
48 $res = $this->getDoctrine() 52 $res = $this->getDoctrine()
49 ->getRepository('WallabagCoreBundle:Entry') 53 ->getRepository('WallabagCoreBundle:Entry')
50 ->findByUrlAndUserId($url, $this->getUser()->getId()); 54 ->findOneBy([
55 'hashedUrl' => $hashedUrl,
56 'user' => $this->getUser()->getId(),
57 ]);
51 58
52 $results[$url] = $this->returnExistInformation($res, $returnId); 59 // $results[$url] = $this->returnExistInformation($res, $returnId);
60 $results[$hashedUrl] = $this->returnExistInformation($res, $returnId);
53 } 61 }
54 62
55 return $this->sendResponse($results); 63 return $this->sendResponse($results);
56 } 64 }
57 65
58 // let's see if it is a simple url? 66 // let's see if it is a simple url?
59 $url = $request->query->get('url', ''); 67 $hashedUrl = $request->query->get('hashedurl', '');
68
69 // if (empty($url)) {
70 // throw $this->createAccessDeniedException('URL is empty?, logged user id: ' . $this->getUser()->getId());
71 // }
60 72
61 if (empty($url)) { 73 if (empty($hashedUrl)) {
62 throw $this->createAccessDeniedException('URL is empty?, logged user id: ' . $this->getUser()->getId()); 74 throw $this->createAccessDeniedException('URL is empty?, logged user id: '.$this->getUser()->getId());
63 } 75 }
64 76
65 $res = $this->getDoctrine() 77 $res = $this->getDoctrine()
66 ->getRepository('WallabagCoreBundle:Entry') 78 ->getRepository('WallabagCoreBundle:Entry')
67 ->findByUrlAndUserId($url, $this->getUser()->getId()); 79 // ->findByUrlAndUserId($url, $this->getUser()->getId());
68 80 ->findOneBy([
69 $exists = $this->returnExistInformation($res, $returnId); 81 'hashedUrl' => $hashedUrl,
82 'user' => $this->getUser()->getId(),
83 ]);
70 84
71 return $this->sendResponse(['exists' => $exists]); 85 return $this->sendResponse(['exists' => $this->returnExistInformation($res, $returnId)]);
72 } 86 }
73 87
74 /** 88 /**