use Wallabag\CoreBundle\Entity\Tag;
use Wallabag\CoreBundle\Event\EntryDeletedEvent;
use Wallabag\CoreBundle\Event\EntrySavedEvent;
+use Wallabag\CoreBundle\Helper\UrlHasher;
class EntryRestController extends WallabagRestController
{
}
$urlHashMap = [];
- foreach($urls as $urlToHash) {
- $urlHash = hash('sha1', $urlToHash); // XXX: the hash logic would better be in a separate util to avoid duplication with GenerateUrlHashesCommand::generateHashedUrls
+ foreach ($urls as $urlToHash) {
+ $urlHash = UrlHasher::hashUrl($urlToHash);
$hashedUrls[] = $urlHash;
$urlHashMap[$urlHash] = $urlToHash;
}
if (!empty($url) || !empty($hashedUrl)) {
$hu = array_keys($results)[0];
+
return $this->sendResponse(['exists' => $results[$hu]]);
}
- return $this->sendResponse($results);
- }
- /**
- * Replace the hashedUrl keys in $results with the unhashed URL from the
- * request, as recorded in $urlHashMap.
- */
- private function replaceUrlHashes(array $results, array $urlHashMap) {
- $newResults = [];
- foreach($results as $hash => $res) {
- if (isset($urlHashMap[$hash])) {
- $newResults[$urlHashMap[$hash]] = $res;
- } else {
- $newResults[$hash] = $res;
- }
- }
- return $newResults;
+ return $this->sendResponse($results);
}
/**
'language' => !empty($data['language']) ? $data['language'] : $entry->getLanguage(),
'date' => !empty($data['publishedAt']) ? $data['publishedAt'] : $entry->getPublishedAt(),
// faking the open graph preview picture
- 'open_graph' => [
- 'og_image' => !empty($data['picture']) ? $data['picture'] : $entry->getPreviewPicture(),
- ],
+ 'image' => !empty($data['picture']) ? $data['picture'] : $entry->getPreviewPicture(),
'authors' => \is_string($data['authors']) ? explode(',', $data['authors']) : $entry->getPublishedBy(),
]
);
return $this->sendResponse($results);
}
+ /**
+ * Replace the hashedUrl keys in $results with the unhashed URL from the
+ * request, as recorded in $urlHashMap.
+ */
+ private function replaceUrlHashes(array $results, array $urlHashMap)
+ {
+ $newResults = [];
+ foreach ($results as $hash => $res) {
+ if (isset($urlHashMap[$hash])) {
+ $newResults[$urlHashMap[$hash]] = $res;
+ } else {
+ $newResults[$hash] = $res;
+ }
+ }
+
+ return $newResults;
+ }
+
/**
* Retrieve value from the request.
* Used for POST & PATCH on a an entry.
/**
* Return information about the entry if it exist and depending on the id or not.
*
- * @param Entry|null $entry
- * @param bool $returnId
+ * @param Entry|bool|null $entry
+ * @param bool $returnId
*
* @return bool|int
*/