Created
October 5, 2016 05:56
-
-
Save pmartin/42e788c043ffb383d9802f201749e98d to your computer and use it in GitHub Desktop.
Adding EPUB export to wallabag API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |
index af24e49..f64b4aa 100644 | |
--- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |
+++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |
@@ -79,11 +79,18 @@ class WallabagRestController extends FOSRestController | |
* | |
* @return Response | |
*/ | |
- public function getEntryAction(Entry $entry) | |
+ public function getEntryAction(Entry $entry, $_format) | |
{ | |
$this->validateAuthentication(); | |
$this->validateUserAccess($entry->getUser()->getId()); | |
+ if ($_format === 'epub') { | |
+ return $this->get('wallabag_core.helper.entries_export') | |
+ ->setEntries($entry) | |
+ ->updateTitle('entry') | |
+ ->exportAs($_format); | |
+ } | |
+ | |
$json = $this->get('serializer')->serialize($entry, 'json'); | |
return $this->renderJsonResponse($json); | |
diff --git a/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml | |
index 5f43f97..9aef7e8 100644 | |
--- a/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml | |
+++ b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml | |
@@ -2,3 +2,5 @@ entries: | |
type: rest | |
resource: "WallabagApiBundle:WallabagRest" | |
name_prefix: api_ | |
+ requirements: | |
+ _format: xml|json|html|epub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With this patch, the
/api/entries/X.format
API endpoint can be called withepub
as format (and not only JSON) to export the EPUB version of an entry.For instance:
https://WALLABAG_INSTANCE_URL/api/entries/2343.epub?access_token=YOUR_TOKEN