Partial implementation of Thuanksgiving days
Signed-off-by: James Ketrenos <james.p.ketrenos@intel.com>
This commit is contained in:
parent
8cd10222c0
commit
c787cd186c
6
query.sh
6
query.sh
@ -1,6 +1,2 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
P=${P:=$(sed -ne 's#^.*mysql://[^:]*:\([^@]*\).*$#\1#p' config/default.json)}
|
sqlite3 photos.db
|
||||||
U=${U:=$(sed -ne 's#^.*mysql://\([^:]*\).*$#\1#p' config/default.json)}
|
|
||||||
DB=${DB:=$(sed -ne 's#^.*mysql://[^@]*@[^/]*/\([^/"]*\).*$#\1#p' config/default.json)}
|
|
||||||
mysql -u ${U} --password=${P} ${DB}
|
|
||||||
|
|
||||||
|
@ -538,6 +538,95 @@ router.delete("/:id?", function(req, res/*, next*/) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get("/thanksgiving", function(req, res/*, next*/) {
|
||||||
|
let thanksgiving = [
|
||||||
|
"1995-11-23",
|
||||||
|
"1996-11-28",
|
||||||
|
"1997-11-27",
|
||||||
|
"1998-11-26",
|
||||||
|
"1999-11-25",
|
||||||
|
"2000-11-23",
|
||||||
|
"2001-11-22",
|
||||||
|
"2002-11-28",
|
||||||
|
"2003-11-27",
|
||||||
|
"2004-11-25",
|
||||||
|
"2005-11-24",
|
||||||
|
"2006-11-23",
|
||||||
|
"2007-11-22",
|
||||||
|
"2008-11-27",
|
||||||
|
"2009-11-26",
|
||||||
|
"2010-11-25",
|
||||||
|
"2011-11-24",
|
||||||
|
"2012-11-22",
|
||||||
|
"2013-11-28",
|
||||||
|
"2014-11-27",
|
||||||
|
"2015-11-26",
|
||||||
|
"2016-11-24",
|
||||||
|
"2017-11-23",
|
||||||
|
"2018-11-22",
|
||||||
|
"2019-11-28",
|
||||||
|
"2020-11-26",
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
index = "strftime('%m-%d',taken)=strftime('%m-%d',:date)";
|
||||||
|
} else {
|
||||||
|
index = "((strftime('%Y-%m-%d',taken)=strftime('%Y-%m-%d',:cursor) AND photos.id<"+id+ ") OR " +
|
||||||
|
"(strftime('%m-%d',taken)=strftime('%m-%d',:cursor) AND strftime('%Y',taken)<strftime('%Y',:cursor)))";
|
||||||
|
}
|
||||||
|
|
||||||
|
let date = new Date("2016-" + req.params.date);
|
||||||
|
let query = "SELECT photos.*,albums.path AS path FROM photos " +
|
||||||
|
"INNER JOIN albums ON (albums.id=photos.albumId) " +
|
||||||
|
"WHERE (photos.duplicate=0 AND photos.deleted=0 AND photos.scanned NOT NULL AND " + index + ") " +
|
||||||
|
"ORDER BY strftime('%Y-%m-%d',taken) DESC,id DESC LIMIT " + (limit + 1);
|
||||||
|
|
||||||
|
// console.log("Memories for " + date.toISOString().replace(/^2016-(.*)T.*$/, "$1"));
|
||||||
|
// if (cursor) {
|
||||||
|
// console.log("Cursor" + cursor.toISOString().replace(/T.*/, ""));
|
||||||
|
// }
|
||||||
|
|
||||||
|
return photoDB.sequelize.query(query, {
|
||||||
|
replacements: {
|
||||||
|
cursor: cursor,
|
||||||
|
date: date
|
||||||
|
},
|
||||||
|
type: photoDB.Sequelize.QueryTypes.SELECT
|
||||||
|
}).then(function(photos) {
|
||||||
|
photos.forEach(function(photo) {
|
||||||
|
for (var key in photo) {
|
||||||
|
if (photo[key] instanceof Date) {
|
||||||
|
photo[key] = moment(photo[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let more = photos.length > limit; /* We queried one extra item to see if there are more than LIMIT available */
|
||||||
|
|
||||||
|
let last;
|
||||||
|
if (more) {
|
||||||
|
photos.splice(limit);
|
||||||
|
last = photos[photos.length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
let results = {
|
||||||
|
items: photos.sort(function(a, b) {
|
||||||
|
return new Date(b.taken) - new Date(a.taken);
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
if (more) {
|
||||||
|
results.cursor = new Date(last.taken).toISOString().replace(/T.*/, "") + "_" + last.id;
|
||||||
|
results.more = true;
|
||||||
|
}
|
||||||
|
return res.status(200).json(results);
|
||||||
|
}).catch(function(error) {
|
||||||
|
console.error("Query failed: " + query);
|
||||||
|
return Promise.reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/* Each photos has:
|
/* Each photos has:
|
||||||
|
|
||||||
* locations
|
* locations
|
||||||
|
2
util/check.js
Normal file → Executable file
2
util/check.js
Normal file → Executable file
@ -75,7 +75,7 @@ function getAssetInfoFromDisk(asset, filepath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
asset.name = asset.filename.replace(/\.[^.]*$/, "");
|
asset.name = asset.filename.replace(/\.[^.]*$/, "");
|
||||||
|
console.log(asset);
|
||||||
return photoDB.sequelize.query("SELECT photos.*,(albums.path || photos.filename) AS filepath " +
|
return photoDB.sequelize.query("SELECT photos.*,(albums.path || photos.filename) AS filepath " +
|
||||||
"FROM photos LEFT JOIN albums ON albums.id=photos.albumId " +
|
"FROM photos LEFT JOIN albums ON albums.id=photos.albumId " +
|
||||||
"WHERE albums.path=:path AND photos.filename=:filename", {
|
"WHERE albums.path=:path AND photos.filename=:filename", {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user