Switched to DESC order for date, and to SQLite
Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
parent
e8adf6b820
commit
050ce39186
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db": {
|
"db": {
|
||||||
"host": "mysql://photos:p4$$w0rd@localhost:3306/photos",
|
"host": "sqlite:photos.db",
|
||||||
"options": {
|
"options": {
|
||||||
"logging" : false,
|
"logging" : false,
|
||||||
"timezone": "+00:00"
|
"timezone": "+00:00"
|
||||||
|
@ -261,12 +261,12 @@
|
|||||||
|
|
||||||
loadNextPhotos: function() {
|
loadNextPhotos: function() {
|
||||||
var cursor = this.photos[this.photos.length - 1];
|
var cursor = this.photos[this.photos.length - 1];
|
||||||
this._loadPhotos(cursor.taken.toString().replace(/T.*/, "") + "_" + cursor.id, +1, true);
|
this._loadPhotos(cursor.taken.toString().replace(/T.*/, "") + "_" + cursor.id, -1, true);
|
||||||
},
|
},
|
||||||
|
|
||||||
loadPrevPhotos: function() {
|
loadPrevPhotos: function() {
|
||||||
var cursor = this.photos[0];
|
var cursor = this.photos[0];
|
||||||
this._loadPhotos(cursor.taken.toString().replace(/T.*/, "") + "_" + cursor.id, -1);
|
this._loadPhotos(cursor.taken.toString().replace(/T.*/, "") + "_" + cursor.id, +1);
|
||||||
},
|
},
|
||||||
|
|
||||||
_loadPhotos: function(start, dir, append) {
|
_loadPhotos: function(start, dir, append) {
|
||||||
@ -275,7 +275,7 @@
|
|||||||
}
|
}
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
dir = dir || +1;
|
dir = dir || -1;
|
||||||
var params = {
|
var params = {
|
||||||
limit: Math.ceil(this.clientWidth / 200) * Math.ceil(this.clientHeight / 200),
|
limit: Math.ceil(this.clientWidth / 200) * Math.ceil(this.clientHeight / 200),
|
||||||
dir: dir
|
dir: dir
|
||||||
|
@ -39,6 +39,7 @@ function init() {
|
|||||||
allowNull: true
|
allowNull: true
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
timestamps: false,
|
||||||
classMethods: {
|
classMethods: {
|
||||||
associate: function() {
|
associate: function() {
|
||||||
Album.hasOne(Album, {as:'Album', foreignKey: 'parentId'});
|
Album.hasOne(Album, {as:'Album', foreignKey: 'parentId'});
|
||||||
@ -67,6 +68,8 @@ function init() {
|
|||||||
key: 'id',
|
key: 'id',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
timestamps: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ router.get("/", function(req, res/*, next*/) {
|
|||||||
let start = moment(req.query.start || null) || null,
|
let start = moment(req.query.start || null) || null,
|
||||||
end = moment(req.query.end || null) || null;
|
end = moment(req.query.end || null) || null;
|
||||||
|
|
||||||
let query = "SELECT DATE(taken) AS date,COUNT(*) AS count FROM photos WHERE path LIKE :path GROUP BY DATE(taken) ORDER BY date";
|
let query = "SELECT DATE(taken) AS date,COUNT(*) AS count FROM photos WHERE path LIKE :path GROUP BY DATE(taken) ORDER BY date DESC";
|
||||||
return photoDB.sequelize.query(query, {
|
return photoDB.sequelize.query(query, {
|
||||||
replacements: {
|
replacements: {
|
||||||
path: req.url.replace(/\?.*$/, "") + "%"
|
path: req.url.replace(/\?.*$/, "") + "%"
|
||||||
|
@ -74,6 +74,7 @@ router.get("/", function(req, res/*, next*/) {
|
|||||||
|
|
||||||
if (order == "DESC") {
|
if (order == "DESC") {
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
|
cursor = moment(cursor);
|
||||||
photos = photos.filter(function(photo) {
|
photos = photos.filter(function(photo) {
|
||||||
if (!cursor.isSame(photo.taken, "day")) {
|
if (!cursor.isSame(photo.taken, "day")) {
|
||||||
return true;
|
return true;
|
||||||
@ -81,7 +82,6 @@ router.get("/", function(req, res/*, next*/) {
|
|||||||
return photo.id < id;
|
return photo.id < id;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
photos.reverse();
|
|
||||||
} else {
|
} else {
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
cursor = moment(cursor);
|
cursor = moment(cursor);
|
||||||
|
@ -34,13 +34,13 @@ function scanDir(parent, path) {
|
|||||||
}).then(function(results) {
|
}).then(function(results) {
|
||||||
if (results.length == 0) {
|
if (results.length == 0) {
|
||||||
// console.log("Adding " + path + " under " + parent, replacements);
|
// console.log("Adding " + path + " under " + parent, replacements);
|
||||||
return photoDB.sequelize.query("INSERT INTO albums SET path=:path,parentId=:parent", {
|
return photoDB.sequelize.query("INSERT INTO albums (path,parentId) VALUES(:path,:parent)", {
|
||||||
replacements: {
|
replacements: {
|
||||||
path: path,
|
path: path,
|
||||||
parent: parent || null
|
parent: parent || null
|
||||||
},
|
},
|
||||||
}).then(function(results) {
|
}).then(function(results) {
|
||||||
return results[0];
|
return results[1].lastID;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return results[0].id;
|
return results[0].id;
|
||||||
@ -78,7 +78,6 @@ function scanDir(parent, path) {
|
|||||||
/* If this file has an original NEF on the system, don't add the JPG to the
|
/* If this file has an original NEF on the system, don't add the JPG to the
|
||||||
* DB */
|
* DB */
|
||||||
if (/\.nef$/i.exec(files[i]) && file == files[i].replace(/\.nef$/i, ".jpg")) {
|
if (/\.nef$/i.exec(files[i]) && file == files[i].replace(/\.nef$/i, ".jpg")) {
|
||||||
console.log("Skipping DB duplicate for " + files[i]);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,6 +171,20 @@ function mkdirPromise(path) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function existsPromise(path) {
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
fs.stat(path, function(err, stats) {
|
||||||
|
if (!err) {
|
||||||
|
return resolve(true);
|
||||||
|
}
|
||||||
|
if (err.code == 'ENOENT') {
|
||||||
|
return resolve(false);
|
||||||
|
}
|
||||||
|
return reject(err);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function convertNefToJpg(path, file) {
|
function convertNefToJpg(path, file) {
|
||||||
console.log("Converting " + path + "/" + file);
|
console.log("Converting " + path + "/" + file);
|
||||||
|
|
||||||
@ -246,11 +259,17 @@ function triggerWatcher() {
|
|||||||
let tmp = Promise.resolve(file);
|
let tmp = Promise.resolve(file);
|
||||||
/* If this is a Nikon RAW file, convert it to JPG and move to /raw dir */
|
/* If this is a Nikon RAW file, convert it to JPG and move to /raw dir */
|
||||||
if (/\.nef$/i.exec(file)) {
|
if (/\.nef$/i.exec(file)) {
|
||||||
tmp = mkdirPromise(picturesPath + path + "/raw").then(function() {
|
tmp = existsPromise(picturesPath + path + "/" + file.replace(/\.nef$/i, ".jpg")).then(function(exists) {
|
||||||
|
if (exists) {
|
||||||
|
return file.replace(/\.nef$/i, ".jpg"); /* We converted from NEF => JPG */
|
||||||
|
}
|
||||||
|
|
||||||
|
return mkdirPromise(picturesPath + path + "/raw").then(function() {
|
||||||
return convertNefToJpg(path, file);
|
return convertNefToJpg(path, file);
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
return file.replace(/\.nef$/i, ".jpg"); /* We converted from NEF => JPG */
|
return file.replace(/\.nef$/i, ".jpg"); /* We converted from NEF => JPG */
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return tmp.then(function(file) {
|
return tmp.then(function(file) {
|
||||||
@ -276,16 +295,14 @@ function triggerWatcher() {
|
|||||||
filename: file,
|
filename: file,
|
||||||
width: metadata.width,
|
width: metadata.width,
|
||||||
height: metadata.height,
|
height: metadata.height,
|
||||||
added: moment().format().replace(/T.*/, "")
|
added: moment().format()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (metadata.exif && metadata.exif.exif && metadata.exif.exif.DateTimeOriginal && !isNaN(metadata.exif.exif.DateTimeOriginal.valueOf())) {
|
if (metadata.exif && metadata.exif.exif && metadata.exif.exif.DateTimeOriginal && !isNaN(metadata.exif.exif.DateTimeOriginal.valueOf())) {
|
||||||
metadata.exif.exif.DateTimeOriginal.setHours(0, 0, 0, 0);
|
replacements.taken = moment(metadata.exif.exif.DateTimeOriginal).format();
|
||||||
metadata.exif.exif.DateTimeOriginal = metadata.exif.exif.DateTimeOriginal.toISOString().replace(/T.*/, "");
|
replacements.modified = moment(metadata.exif.exif.DateTimeOriginal).format();
|
||||||
replacements.taken = moment(metadata.exif.exif.DateTimeOriginal, "YYYY-MM-DD").format().replace(/T.*/, "");
|
|
||||||
replacements.modified = moment(metadata.exif.exif.DateTimeOriginal).format().replace(/T.*/, "");
|
|
||||||
|
|
||||||
if (replacements.taken == "Invalid date" || replacements.taken == "1899-11-30") {
|
if (replacements.taken == "Invalid date" || replacements.taken.replace(/T.*/, "") == "1899-11-30") {
|
||||||
console.log("Invalid EXIF date information: ", JSON.stringify(metadata.exif.exif));
|
console.log("Invalid EXIF date information: ", JSON.stringify(metadata.exif.exif));
|
||||||
replacements.taken = replacements.modified = moment(created).format();
|
replacements.taken = replacements.modified = moment(created).format();
|
||||||
}
|
}
|
||||||
@ -303,10 +320,24 @@ function triggerWatcher() {
|
|||||||
replacements.taken = replacements.modified = date;
|
replacements.taken = replacements.modified = date;
|
||||||
}
|
}
|
||||||
|
|
||||||
return image.resize(256, 256).toFile(dst).then(function() {
|
return existsPromise(dst).then(function(exists) {
|
||||||
|
let resize;
|
||||||
|
if (!exists) {
|
||||||
|
resize = image.resize(256, 256).toFile(dst);
|
||||||
|
} else {
|
||||||
|
resize = Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return resize.then(function() {
|
||||||
return photoDB.sequelize.query("INSERT INTO photos " +
|
return photoDB.sequelize.query("INSERT INTO photos " +
|
||||||
"SET albumId=:albumId,path=:path,filename=:filename,added=DATE(:added),modified=DATE(:modified),taken=DATE(:taken),width=:width,height=:height", {
|
"(albumId,path,filename,added,modified,taken,width,height)" +
|
||||||
|
"VALUES(:albumId,:path,:filename,DATE(:added),DATE(:modified),DATE(:taken),:width,:height)", {
|
||||||
replacements: replacements
|
replacements: replacements
|
||||||
|
});
|
||||||
|
}).catch(function(error) {
|
||||||
|
console.error("Error resizing image, writing to disc, or updating DB: " + src, error);
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
toProcess--;
|
toProcess--;
|
||||||
if (moment().add(-5, 'seconds') > lastMessage) {
|
if (moment().add(-5, 'seconds') > lastMessage) {
|
||||||
@ -314,10 +345,6 @@ function triggerWatcher() {
|
|||||||
lastMessage = moment();
|
lastMessage = moment();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).catch(function(error) {
|
|
||||||
console.error("Error resizing image, writing to disc, or updating DB: " + src, error);
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
console.error("Error reading image " + src + ": ", error);
|
console.error("Error reading image " + src + ": ", error);
|
||||||
return moveCorrupt(path, file).then(function() {
|
return moveCorrupt(path, file).then(function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user