diff --git a/lib/Db/Util.php b/lib/Db/Util.php
index 2f006a4c..81ff394e 100644
--- a/lib/Db/Util.php
+++ b/lib/Db/Util.php
@@ -18,8 +18,21 @@ class Util {
$this->connection = $connection;
}
- private function getDateTaken($file) {
+ public static function getDateTaken($file) {
+ // Attempt to read exif data
+ $exif = exif_read_data($file->fopen('rb'));
+ $dt = $exif['DateTimeOriginal'];
+ if ($dt) {
+ $dt = \DateTime::createFromFormat('Y:m:d H:i:s', $dt);
+ if ($dt) {
+ return $dt->getTimestamp();
+ }
+ }
+
+ // Fall back to creation time
$dateTaken = $file->getCreationTime();
+
+ // Fall back to modification time
if ($dateTaken == 0) {
$dateTaken = $file->getMtime();
}
diff --git a/src/App.vue b/src/App.vue
index 0a5fa234..55c6c146 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -17,7 +17,7 @@
diff --git a/src/Timeline.vue b/src/Timeline.vue
index 96872c66..33b207fc 100644
--- a/src/Timeline.vue
+++ b/src/Timeline.vue
@@ -28,6 +28,9 @@ export default {
nrows: 0,
ncols: 5,
heads: {},
+
+ currentStart: 0,
+ currentEnd: 0,
}
},
@@ -37,6 +40,21 @@ export default {
methods: {
scrollChange(startIndex, endIndex) {
+ if (startIndex === this.currentStart && endIndex === this.currentEnd) {
+ return;
+ }
+
+ this.currentStart = startIndex;
+ this.currentEnd = endIndex;
+ setTimeout(() => {
+ if (this.currentStart === startIndex && this.currentEnd === endIndex) {
+ this.loadChanges(startIndex, endIndex);
+ }
+ }, 300);
+ },
+
+ loadChanges(startIndex, endIndex) {
+ console.log(startIndex, endIndex);
for (let i = startIndex; i <= endIndex; i++) {
let item = this.list[i];
if (!item) {
@@ -45,6 +63,7 @@ export default {
let head = this.heads[item.dayId];
if (head && !head.loaded) {
+ head.loaded = true;
this.fetchDay(item.dayId);
}
}
@@ -87,11 +106,16 @@ export default {
const head = this.heads[dayId];
head.loaded = true;
- const res = await fetch(`/apps/betterphotos/api/days/${dayId}`);
- const data = await res.json();
-
- const nrows = Math.ceil(data.length / this.ncols);
+ let data = [];
+ try {
+ const res = await fetch(`/apps/betterphotos/api/days/${dayId}`);
+ data = await res.json();
+ } catch (e) {
+ console.error(e);
+ head.loaded = false;
+ }
+ // Get index of header O(n)
const headIdx = this.list.findIndex(item => item.id === head.id);
let rowIdx = headIdx + 1;
@@ -133,7 +157,8 @@ export default {