aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ApiBundle/Controller/EntryRestController.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-05-11 08:14:29 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-05-31 13:59:45 +0200
commite668a8124c46d47add4248963d77f3b29b37b3ce (patch)
treeb9b56d19b06fe268d025c3591119470162efc99a /src/Wallabag/ApiBundle/Controller/EntryRestController.php
parent4423b88c5b2c2d530b0a83a822f521a61ca4d4b8 (diff)
downloadwallabag-e668a8124c46d47add4248963d77f3b29b37b3ce.tar.gz
wallabag-e668a8124c46d47add4248963d77f3b29b37b3ce.tar.zst
wallabag-e668a8124c46d47add4248963d77f3b29b37b3ce.zip
Allow other fields to be send using API
Entry API can now have these new fields: - content - language - preview_picture - published_at Re-use the ContentProxy to be able to do the same using the web UI (in the future). htmLawed is used to clean stuff from content, I hope it’ll be enough to avoid security breach. Lower content validation when we want to update an entry with content already defined. Before, language & content_type were required. If there weren’t provided, we re-fetched the content using graby. I think these fields aren’t required for an entry to be created. So I removed them. Which means some import from the v1 export won’t be re-fetched since they provide content, url & title. Also, remove liberation link from Readability import to avoid overlaping import (from wallabag v1, which had the same link)
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller/EntryRestController.php')
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php46
1 files changed, 31 insertions, 15 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index 31bb67fd..dfd04fb4 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -280,6 +280,10 @@ class EntryRestController extends WallabagRestController
280 * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, 280 * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
281 * {"name"="starred", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="entry already starred"}, 281 * {"name"="starred", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="entry already starred"},
282 * {"name"="archive", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="entry already archived"}, 282 * {"name"="archive", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="entry already archived"},
283 * {"name"="content", "dataType"="string", "required"=false, "description"="Content of the entry"},
284 * {"name"="language", "dataType"="string", "required"=false, "description"="Language of the entry"},
285 * {"name"="preview_picture", "dataType"="string", "required"=false, "description"="Preview picture of the entry"},
286 * {"name"="published_at", "dataType"="datetime", "format"="YYYY-MM-DDTHH:II:SS+TZ", "required"=false, "description"="Published date of the entry"},
283 * } 287 * }
284 * ) 288 * )
285 * 289 *
@@ -293,30 +297,42 @@ class EntryRestController extends WallabagRestController
293 $title = $request->request->get('title'); 297 $title = $request->request->get('title');
294 $isArchived = $request->request->get('archive'); 298 $isArchived = $request->request->get('archive');
295 $isStarred = $request->request->get('starred'); 299 $isStarred = $request->request->get('starred');
300 $content = $request->request->get('content');
301 $language = $request->request->get('language');
302 $picture = $request->request->get('preview_picture');
303 $publishedAt = $request->request->get('published_at');
296 304
297 $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($url, $this->getUser()->getId()); 305 $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($url, $this->getUser()->getId());
298 306
299 if (false === $entry) { 307 if (false === $entry) {
300 $entry = new Entry($this->getUser()); 308 $entry = new Entry($this->getUser());
301 try {
302 $entry = $this->get('wallabag_core.content_proxy')->updateEntry(
303 $entry,
304 $url
305 );
306 } catch (\Exception $e) {
307 $this->get('logger')->error('Error while saving an entry', [
308 'exception' => $e,
309 'entry' => $entry,
310 ]);
311 $entry->setUrl($url);
312 }
313 } 309 }
314 310
315 if (!is_null($title)) { 311 try {
316 $entry->setTitle($title); 312 $entry = $this->get('wallabag_core.content_proxy')->updateEntry(
313 $entry,
314 $url,
315 [
316 'title' => $title,
317 'html' => $content,
318 'url' => $url,
319 'language' => $language,
320 'date' => $publishedAt,
321 // faking the preview picture
322 'open_graph' => [
323 'og_image' => $picture,
324 ],
325 ]
326 );
327 } catch (\Exception $e) {
328 $this->get('logger')->error('Error while saving an entry', [
329 'exception' => $e,
330 'entry' => $entry,
331 ]);
332 $entry->setUrl($url);
317 } 333 }
318 334
319 $tags = $request->request->get('tags', ''); 335 $tags = $request->request->get('tags', []);
320 if (!empty($tags)) { 336 if (!empty($tags)) {
321 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags); 337 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags);
322 } 338 }