mirror of
https://github.com/wallabag/wallabag.git
synced 2025-07-22 17:18:37 +00:00
Ability to check multiple urls in API
This commit is contained in:
parent
233a1081ea
commit
f0abc22d09
2 changed files with 37 additions and 1 deletions
|
@ -27,7 +27,8 @@ class WallabagRestController extends FOSRestController
|
|||
*
|
||||
* @ApiDoc(
|
||||
* parameters={
|
||||
* {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"}
|
||||
* {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"},
|
||||
* {"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"}
|
||||
* }
|
||||
* )
|
||||
*
|
||||
|
@ -37,6 +38,25 @@ class WallabagRestController extends FOSRestController
|
|||
{
|
||||
$this->validateAuthentication();
|
||||
|
||||
$urls = $request->query->get('urls', []);
|
||||
|
||||
// handle multiple urls first
|
||||
if (!empty($urls)) {
|
||||
$results = [];
|
||||
foreach ($urls as $url) {
|
||||
$res = $this->getDoctrine()
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findByUrlAndUserId($url, $this->getUser()->getId());
|
||||
|
||||
$results[$url] = false === $res ? false : true;
|
||||
}
|
||||
|
||||
$json = $this->get('serializer')->serialize($results, 'json');
|
||||
|
||||
return (new JsonResponse())->setJson($json);
|
||||
}
|
||||
|
||||
// let's see if it is a simple url?
|
||||
$url = $request->query->get('url', '');
|
||||
|
||||
if (empty($url)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue