From b4bda3744e4be97d6cfcab486b480906878f473c Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 16 Aug 2022 00:46:36 +0000 Subject: [PATCH] Add video icon --- lib/Db/Util.php | 33 ++++++++++++++----- .../Version000000Date20220812163631.php | 4 +++ src/components/Timeline.vue | 7 ++++ 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/lib/Db/Util.php b/lib/Db/Util.php index 1c3c2542..caecab62 100644 --- a/lib/Db/Util.php +++ b/lib/Db/Util.php @@ -44,7 +44,9 @@ class Util { public function processFile(string $user, File $file): void { $mime = $file->getMimeType(); - if (!in_array($mime, Application::IMAGE_MIMES) && !in_array($mime, Application::VIDEO_MIMES)) { + $is_image = in_array($mime, Application::IMAGE_MIMES); + $is_video = in_array($mime, Application::VIDEO_MIMES); + if (!$is_image && !$is_video) { return; } @@ -65,16 +67,20 @@ class Util { // Insert or update file if ($exists) { $sql = 'UPDATE oc_betterphotos SET - day_id = ?, date_taken = ? + day_id = ?, date_taken = ?, is_video = ? WHERE user_id = ? AND file_id = ?'; } else { $sql = 'INSERT - INTO oc_betterphotos (day_id, date_taken, user_id, file_id) - VALUES (?, ?, ?, ?)'; + INTO oc_betterphotos (day_id, date_taken, is_video, user_id, file_id) + VALUES (?, ?, ?, ?, ?)'; } $res = $this->connection->executeStatement($sql, [ - $dayId, $dateTaken, $user, $fileId, - ]); + $dayId, $dateTaken, $is_video, + $user, $fileId, + ], [ + \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_BOOL, + \PDO::PARAM_STR, \PDO::PARAM_INT, + ]); // Change of day $dayChange = ($exists && intval($erow['day_id']) != $dayId); @@ -140,7 +146,7 @@ class Util { string $user, int $dayId, ): array { - $sql = 'SELECT file_id, oc_filecache.etag + $sql = 'SELECT file_id, oc_filecache.etag, is_video FROM oc_betterphotos LEFT JOIN oc_filecache ON oc_filecache.fileid = oc_betterphotos.file_id @@ -148,7 +154,16 @@ class Util { ORDER BY date_taken DESC'; $rows = $this->connection->executeQuery($sql, [$user, $dayId], [ \PDO::PARAM_STR, \PDO::PARAM_INT, - ]); - return $rows->fetchAll(); + ])->fetchAll(); + + foreach($rows as &$row) { + $row["file_id"] = intval($row["file_id"]); + $row["is_video"] = intval($row["is_video"]); + if (!$row["is_video"]) { + unset($row["is_video"]); + } + } + + return $rows; } } \ No newline at end of file diff --git a/lib/Migration/Version000000Date20220812163631.php b/lib/Migration/Version000000Date20220812163631.php index 3e2af80e..4316a767 100644 --- a/lib/Migration/Version000000Date20220812163631.php +++ b/lib/Migration/Version000000Date20220812163631.php @@ -40,6 +40,10 @@ $table->addColumn('day_id', Types::INTEGER, [ 'notnull' => true, ]); + $table->addColumn('is_video', Types::BOOLEAN, [ + 'notnull' => false, + 'default' => false + ]); $table->setPrimaryKey(['id']); $table->addIndex(['user_id'], 'betterphotos_user_id_index'); diff --git a/src/components/Timeline.vue b/src/components/Timeline.vue index 24561bca..268aeb24 100644 --- a/src/components/Timeline.vue +++ b/src/components/Timeline.vue @@ -21,6 +21,7 @@ v-bind:style="{ height: rowHeight + 'px' }">
+