single-item: fix post-processing (fix #470)
Signed-off-by: Varun Patil <varunpatil@ucla.edu>pull/563/head
parent
81708a4de7
commit
dae5785462
|
@ -215,10 +215,8 @@ class PublicController extends AuthPublicShareController
|
|||
}
|
||||
|
||||
/** Get initial state of single item */
|
||||
private function getSingleItemInitialState(\OCP\Files\File $file): string
|
||||
private function getSingleItemInitialState(\OCP\Files\File $file): array
|
||||
{
|
||||
$photo = $this->timelineQuery->getSingleItem($file->getId());
|
||||
|
||||
return json_encode($photo);
|
||||
return $this->timelineQuery->getSingleItem($file->getId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,11 +168,15 @@ trait TimelineQueryDays
|
|||
// Apply all transformations
|
||||
$this->applyAllTransforms($queryTransforms, $query, false);
|
||||
|
||||
$cursor = $this->executeQueryWithCTEs($query);
|
||||
$rows = $cursor->fetchAll();
|
||||
$cursor->closeCursor();
|
||||
// FETCH all photos in this day
|
||||
$day = $this->executeQueryWithCTEs($query)->fetchAll();
|
||||
|
||||
return $this->processDay($rows);
|
||||
// Post process the day in-place
|
||||
foreach ($day as &$photo) {
|
||||
$this->processDayPhoto($photo);
|
||||
}
|
||||
|
||||
return $day;
|
||||
}
|
||||
|
||||
public function executeQueryWithCTEs(IQueryBuilder $query, string $psql = '')
|
||||
|
@ -253,35 +257,31 @@ trait TimelineQueryDays
|
|||
/**
|
||||
* Process the single day response.
|
||||
*/
|
||||
private function processDay(array $day)
|
||||
private function processDayPhoto(array &$row)
|
||||
{
|
||||
foreach ($day as &$row) {
|
||||
// Convert field types
|
||||
$row['fileid'] = (int) $row['fileid'];
|
||||
$row['isvideo'] = (int) $row['isvideo'];
|
||||
$row['video_duration'] = (int) $row['video_duration'];
|
||||
$row['dayid'] = (int) $row['dayid'];
|
||||
$row['w'] = (int) $row['w'];
|
||||
$row['h'] = (int) $row['h'];
|
||||
if (!$row['isvideo']) {
|
||||
unset($row['isvideo'], $row['video_duration']);
|
||||
}
|
||||
if ($row['categoryid']) {
|
||||
$row['isfavorite'] = 1;
|
||||
}
|
||||
unset($row['categoryid']);
|
||||
if (!$row['liveid']) {
|
||||
unset($row['liveid']);
|
||||
}
|
||||
|
||||
// All cluster transformations
|
||||
ClustersBackend\Manager::applyDayPostTransforms($this->request, $row);
|
||||
|
||||
// We don't need these fields
|
||||
unset($row['datetaken']);
|
||||
// Convert field types
|
||||
$row['fileid'] = (int) $row['fileid'];
|
||||
$row['isvideo'] = (int) $row['isvideo'];
|
||||
$row['video_duration'] = (int) $row['video_duration'];
|
||||
$row['dayid'] = (int) $row['dayid'];
|
||||
$row['w'] = (int) $row['w'];
|
||||
$row['h'] = (int) $row['h'];
|
||||
if (!$row['isvideo']) {
|
||||
unset($row['isvideo'], $row['video_duration']);
|
||||
}
|
||||
if ($row['categoryid']) {
|
||||
$row['isfavorite'] = 1;
|
||||
}
|
||||
unset($row['categoryid']);
|
||||
if (!$row['liveid']) {
|
||||
unset($row['liveid']);
|
||||
}
|
||||
|
||||
return $day;
|
||||
// All cluster transformations
|
||||
ClustersBackend\Manager::applyDayPostTransforms($this->request, $row);
|
||||
|
||||
// We don't need these fields
|
||||
unset($row['datetaken']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,13 @@ trait TimelineQuerySingleItem
|
|||
// JOIN with mimetypes to get the mimetype
|
||||
$query->join('f', 'mimetypes', 'mimetypes', $query->expr()->eq('f.mimetype', 'mimetypes.id'));
|
||||
|
||||
return $query->executeQuery()->fetch();
|
||||
// FETCH the photo
|
||||
$photo = $query->executeQuery()->fetch();
|
||||
|
||||
// Post process the record
|
||||
$this->processDayPhoto($photo);
|
||||
|
||||
return $photo;
|
||||
}
|
||||
|
||||
public function getInfoById(int $id, bool $basic): array
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
import { IDay } from "../../types";
|
||||
import { loadState } from "@nextcloud/initial-state";
|
||||
|
||||
const singleItem = JSON.parse(loadState("memories", "single_item", "{}"));
|
||||
let singleItem = null;
|
||||
try {
|
||||
singleItem = loadState("memories", "single_item", {});
|
||||
} catch (e) {
|
||||
console.error("Could not load single item", e);
|
||||
}
|
||||
|
||||
export function isSingleItem(): boolean {
|
||||
return Boolean(singleItem?.fileid);
|
||||
|
|
Loading…
Reference in New Issue