From c787cd186cbd543ad720546abe267f4845845b99 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Sat, 24 Nov 2018 16:09:30 -0800 Subject: [PATCH] Partial implementation of Thuanksgiving days Signed-off-by: James Ketrenos --- query.sh | 6 +-- server/routes/photos.js | 89 +++++++++++++++++++++++++++++++++++++++++ util/check.js | 2 +- 3 files changed, 91 insertions(+), 6 deletions(-) mode change 100644 => 100755 util/check.js diff --git a/query.sh b/query.sh index 2040733..7ad9448 100755 --- a/query.sh +++ b/query.sh @@ -1,6 +1,2 @@ #!/bin/bash -P=${P:=$(sed -ne 's#^.*mysql://[^:]*:\([^@]*\).*$#\1#p' config/default.json)} -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} - +sqlite3 photos.db diff --git a/server/routes/photos.js b/server/routes/photos.js index 163fbeb..be68040 100755 --- a/server/routes/photos.js +++ b/server/routes/photos.js @@ -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) 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: * locations diff --git a/util/check.js b/util/check.js old mode 100644 new mode 100755 index d983b07..16467bf --- a/util/check.js +++ b/util/check.js @@ -75,7 +75,7 @@ function getAssetInfoFromDisk(asset, filepath) { } asset.name = asset.filename.replace(/\.[^.]*$/, ""); - +console.log(asset); return photoDB.sequelize.query("SELECT photos.*,(albums.path || photos.filename) AS filepath " + "FROM photos LEFT JOIN albums ON albums.id=photos.albumId " + "WHERE albums.path=:path AND photos.filename=:filename", {