Scanning and everything now works
Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
parent
698cd6a202
commit
383b5fae61
@ -655,11 +655,11 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
breadcrumb: function(path) {
|
breadcrumb: function(path) {
|
||||||
var crumbs = path.split("/"), parts = [];
|
var crumbs = path.replace(/(.*)\/$/, "/$1").split("/"), parts = [];
|
||||||
path = "";
|
path = "";
|
||||||
crumbs.forEach(function(crumb, index) {
|
crumbs.forEach(function(crumb, index) {
|
||||||
if (crumb) {
|
if (index > 0) {
|
||||||
path += "/" + crumb;
|
path += crumb + "/";
|
||||||
}
|
}
|
||||||
parts.push({
|
parts.push({
|
||||||
name: crumb ? crumb : "Top",
|
name: crumb ? crumb : "Top",
|
||||||
@ -736,7 +736,7 @@
|
|||||||
if (top) {
|
if (top) {
|
||||||
var photo = top.item;
|
var photo = top.item;
|
||||||
this.$.pager.style.opacity = 1;
|
this.$.pager.style.opacity = 1;
|
||||||
var date = window.moment(new Date((photo.taken || photo.modified || photo.added) + " GMT"));
|
var date = window.moment(new Date((photo.taken || photo.modified || photo.added).replace(/T.*/, " GMT")));
|
||||||
date = date.calendar(null, { sameElse: "MMM DD, YYYY" }).replace(/ at.*/, "");
|
date = date.calendar(null, { sameElse: "MMM DD, YYYY" }).replace(/ at.*/, "");
|
||||||
this.$.pager.textContent = date;
|
this.$.pager.textContent = date;
|
||||||
this.$.pager.style.top = headerHeight +
|
this.$.pager.style.top = headerHeight +
|
||||||
@ -966,11 +966,9 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var i = 0;
|
|
||||||
photos.forEach(function(photo) {
|
photos.forEach(function(photo) {
|
||||||
var datetime = new Date((photo.taken || photo.modified || photo.added) + " GMT"),
|
var year = (photo.taken || photo.modified || photo.added).replace(/^(....).*$/, "$1");
|
||||||
year = datetime.getFullYear();
|
for (var i = 0; i < this.years.length; i++) {
|
||||||
for (; i < this.years.length; i++) {
|
|
||||||
if (this.years[i] == year) {
|
if (this.years[i] == year) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1008,7 +1006,7 @@
|
|||||||
thumbnail.addEventListener("load-image", this._imageTap.bind(this));
|
thumbnail.addEventListener("load-image", this._imageTap.bind(this));
|
||||||
thumbnail.addEventListener("load-album", this.loadAlbum.bind(this));
|
thumbnail.addEventListener("load-album", this.loadAlbum.bind(this));
|
||||||
try {
|
try {
|
||||||
datetime = new Date((photo.taken || photo.modified || photo.added).replace(/T.*/, "") + " GMT").toISOString().replace(/T.*$/, "");
|
datetime = (photo.taken || photo.modified || photo.added).replace(/T.*/, "");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(JSON.stringify(photo, null, 2));
|
console.log(JSON.stringify(photo, null, 2));
|
||||||
throw error;
|
throw error;
|
||||||
@ -1112,18 +1110,18 @@
|
|||||||
query += key + "=" + encodeURIComponent(params[key]);
|
query += key + "=" + encodeURIComponent(params[key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
var path = this.path || "/", mode = this.mode;
|
var path = this.path || "", mode = this.mode;
|
||||||
if (mode != "albums") {
|
if (mode != "albums") {
|
||||||
path = "/" + mode;
|
path = mode;
|
||||||
if (mode == "time") {
|
if (mode == "time") {
|
||||||
path = "";
|
path = "";
|
||||||
} else {
|
} else {
|
||||||
path = "/memories/" + (this.date || "");
|
path = "memories/" + (this.date || "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var username = this.user ? this.user.username : "";
|
var username = this.user ? this.user.username : "";
|
||||||
console.log("Requesting " + this.limit + " photos from " + path);
|
console.log("Requesting " + this.limit + " photos from " + path);
|
||||||
window.fetch("api/v1/photos" + path + query, function(path, error, xhr) {
|
window.fetch("api/v1/photos/" + path + query, function(path, error, xhr) {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
|
||||||
if (!this.user) {
|
if (!this.user) {
|
||||||
@ -1132,8 +1130,8 @@
|
|||||||
|
|
||||||
if ((username != (this.user ? this.user.username : "")) ||
|
if ((username != (this.user ? this.user.username : "")) ||
|
||||||
(mode != this.mode) ||
|
(mode != this.mode) ||
|
||||||
((mode == "albums") && (path != (this.path || "/"))) ||
|
((mode == "albums") && (path != (this.path || ""))) ||
|
||||||
((mode == "memories") && (path != ("/memories/" + (this.date || ""))))) {
|
((mode == "memories") && (path != ("memories/" + (this.date || ""))))) {
|
||||||
console.log("Skipping results for old query. Triggering re-fetch of photos for new path or mode.");
|
console.log("Skipping results for old query. Triggering re-fetch of photos for new path or mode.");
|
||||||
this._loadPhotos();
|
this._loadPhotos();
|
||||||
return;
|
return;
|
||||||
@ -1181,22 +1179,22 @@
|
|||||||
}
|
}
|
||||||
this.loadingAlbums = true;
|
this.loadingAlbums = true;
|
||||||
|
|
||||||
var path = this.path || "/";
|
var path = this.path || "";
|
||||||
window.fetch("api/v1/albums" + path, function(path, error, xhr) {
|
window.fetch("api/v1/albums/" + path, function(path, error, xhr) {
|
||||||
this.loadingAlbums = false;
|
this.loadingAlbums = false;
|
||||||
|
|
||||||
if (!this.user) {
|
if (!this.user) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path != (this.path || "/")) {
|
if (path != (this.path || "")) {
|
||||||
console.log("Skipping results for old query. Triggering re-fetch of albums for new path.");
|
console.log("Skipping results for old query. Triggering re-fetch of albums for new path.");
|
||||||
this._loadAlbums();
|
this._loadAlbums();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log("Error loading album: " + (this.path || "/"));
|
console.log("Error loading album: " + (this.path || ""));
|
||||||
console.error(JSON.stringify(error, null, 2));
|
console.error(JSON.stringify(error, null, 2));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,6 @@ app.set("trust proxy", true);
|
|||||||
/* Handle static files first so excessive logging doesn't occur */
|
/* Handle static files first so excessive logging doesn't occur */
|
||||||
app.use(basePath, express.static("frontend", { index: false }));
|
app.use(basePath, express.static("frontend", { index: false }));
|
||||||
|
|
||||||
app.use(morgan("common"));
|
|
||||||
|
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use(bodyParser.urlencoded({
|
app.use(bodyParser.urlencoded({
|
||||||
extended: false
|
extended: false
|
||||||
@ -109,6 +107,9 @@ app.use(basePath, function(req, res, next) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.use(basePath, express.static(picturesPath, { index: false }));
|
app.use(basePath, express.static(picturesPath, { index: false }));
|
||||||
|
|
||||||
|
app.use(morgan("common"));
|
||||||
|
|
||||||
app.use(basePath + "api/v1/photos", require("./routes/photos"));
|
app.use(basePath + "api/v1/photos", require("./routes/photos"));
|
||||||
app.use(basePath + "api/v1/days", require("./routes/days"));
|
app.use(basePath + "api/v1/days", require("./routes/days"));
|
||||||
app.use(basePath + "api/v1/albums", require("./routes/albums"));
|
app.use(basePath + "api/v1/albums", require("./routes/albums"));
|
||||||
|
@ -60,6 +60,10 @@ function init() {
|
|||||||
taken: Sequelize.DATE,
|
taken: Sequelize.DATE,
|
||||||
width: Sequelize.INTEGER,
|
width: Sequelize.INTEGER,
|
||||||
height: Sequelize.INTEGER,
|
height: Sequelize.INTEGER,
|
||||||
|
duplicate: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: 0
|
||||||
|
},
|
||||||
albumId: {
|
albumId: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.INTEGER,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
|
@ -17,7 +17,7 @@ const router = express.Router();
|
|||||||
router.get("/*", function(req, res/*, next*/) {
|
router.get("/*", function(req, res/*, next*/) {
|
||||||
let url = decodeURI(req.url).replace(/\?.*$/, "").replace(/^\//, ""),
|
let url = decodeURI(req.url).replace(/\?.*$/, "").replace(/^\//, ""),
|
||||||
query = "SELECT * FROM albums WHERE path=:path";
|
query = "SELECT * FROM albums WHERE path=:path";
|
||||||
console.log("Looking up album: " + url);
|
// console.log("Looking up album: " + url);
|
||||||
return photoDB.sequelize.query(query, {
|
return photoDB.sequelize.query(query, {
|
||||||
replacements: {
|
replacements: {
|
||||||
path: url
|
path: url
|
||||||
|
@ -38,13 +38,15 @@ router.get("/memories/*", function(req, res/*, next*/) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (id == -1) {
|
if (id == -1) {
|
||||||
index = "";
|
index = "strftime('%m%d',taken)=strftime('%m%d',:date)";
|
||||||
} else {
|
} else {
|
||||||
index = " AND ((taken=DATE(:cursor) AND photos.id<"+id+ ") OR taken<DATE(:cursor))";
|
index = "(strftime('%m%d',taken)=strftime('%m%d',:date) AND photos.id<"+id+ ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
let date = new Date(decodeURI(req.url).replace(/\?.*$/, ""));
|
let date = new Date(decodeURI(req.url).replace(/\?.*$/, ""));
|
||||||
let query = "SELECT photos.*,albums.path AS path FROM photos INNER JOIN albums ON albums.id=photos.albumId WHERE strftime('%m%d',taken)=strftime('%m%d',:date) " + index + " ORDER BY taken DESC,id DESC LIMIT " + (limit * 2 + 1);
|
let query = "SELECT photos.*,albums.path AS path FROM photos " +
|
||||||
|
"INNER JOIN albums ON (albums.id=photos.albumId) " +
|
||||||
|
"WHERE (photos.duplicate=0 AND photos.scanned NOT NULL AND " + index + ") ORDER BY taken DESC,id DESC LIMIT " + (limit * 2 + 1);
|
||||||
|
|
||||||
// console.log("Memories for " + date.toISOString().replace(/T.*/, ""));
|
// console.log("Memories for " + date.toISOString().replace(/T.*/, ""));
|
||||||
// console.log(query);
|
// console.log(query);
|
||||||
@ -109,19 +111,22 @@ router.get("/*", function(req, res/*, next*/) {
|
|||||||
if (id == -1) {
|
if (id == -1) {
|
||||||
index = "";
|
index = "";
|
||||||
} else {
|
} else {
|
||||||
index = " AND ((taken=DATE(:cursor) AND photos.id<"+id+ ") OR taken<DATE(:cursor))";
|
index = "AND ((strftime('%m%d',taken)=strftime('%m%d',:cursor) AND photos.id<"+id+ ") OR DATE(taken)<DATE(:cursor))";
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = decodeURI(req.url).replace(/\?.*$/, ""),
|
let path = decodeURI(req.url).replace(/\?.*$/, "").replace(/^\//, ""),
|
||||||
query = "SELECT photos.*,albums.path AS path FROM photos INNER JOIN albums ON albums.id=photos.albumId AND albums.path LIKE :path " + index + " ORDER BY taken DESC,id DESC LIMIT " + (limit * 2 + 1);
|
query = "SELECT photos.*,albums.path AS path FROM photos " +
|
||||||
|
"INNER JOIN albums ON (albums.id=photos.albumId AND albums.path LIKE :path) " +
|
||||||
|
"WHERE (photos.duplicate=0 AND photos.scanned NOT NULL " + index + ") ORDER BY taken DESC,id DESC LIMIT " + (limit * 2 + 1),
|
||||||
|
replacements = {
|
||||||
|
cursor: cursor,
|
||||||
|
path: path + "%"
|
||||||
|
};
|
||||||
|
|
||||||
console.log("Fetching from: " + path);
|
// console.log("Fetching from: " + JSON.stringify(replacements, null, 2) + "\nwith:\n" + query);
|
||||||
|
|
||||||
return photoDB.sequelize.query(query, {
|
return photoDB.sequelize.query(query, {
|
||||||
replacements: {
|
replacements: replacements,
|
||||||
cursor: cursor,
|
|
||||||
path: path + "%"
|
|
||||||
},
|
|
||||||
type: photoDB.Sequelize.QueryTypes.SELECT
|
type: photoDB.Sequelize.QueryTypes.SELECT
|
||||||
}).then(function(photos) {
|
}).then(function(photos) {
|
||||||
photos.forEach(function(photo) {
|
photos.forEach(function(photo) {
|
||||||
|
@ -101,7 +101,8 @@ router.post("/login", function(req, res) {
|
|||||||
* found there, we look them up in the site-specific user database */
|
* found there, we look them up in the site-specific user database */
|
||||||
|
|
||||||
return ldapPromise(username, password).then(function(user) {
|
return ldapPromise(username, password).then(function(user) {
|
||||||
return user;
|
user.authenticated = 1;
|
||||||
|
return user;
|
||||||
}).catch(function() {
|
}).catch(function() {
|
||||||
console.log("User not found in LDAP. Looking up in DB.");
|
console.log("User not found in LDAP. Looking up in DB.");
|
||||||
let query = "SELECT * FROM users WHERE uid=:username AND password=:password";
|
let query = "SELECT * FROM users WHERE uid=:username AND password=:password";
|
||||||
|
@ -192,6 +192,7 @@ function processBlock(items) {
|
|||||||
setTimeout(processBlock, 1000);
|
setTimeout(processBlock, 1000);
|
||||||
|
|
||||||
if (items) {
|
if (items) {
|
||||||
|
console.log("Adding " + items.length + " on top of " + processQueue.length + " assets.");
|
||||||
processQueue = processQueue.concat(items);
|
processQueue = processQueue.concat(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +202,9 @@ function processBlock(items) {
|
|||||||
|
|
||||||
let lastMessage = moment(), toProcess = processQueue.length, processing = processQueue.splice(0),
|
let lastMessage = moment(), toProcess = processQueue.length, processing = processQueue.splice(0),
|
||||||
needsProcessing = [], duplicates = [];
|
needsProcessing = [], duplicates = [];
|
||||||
|
|
||||||
processRunning = true;
|
processRunning = true;
|
||||||
|
|
||||||
/* Sort to newest files to be processed first */
|
/* Sort to newest files to be processed first */
|
||||||
processing.sort(function(a, b) {
|
processing.sort(function(a, b) {
|
||||||
return a.stats.mtime - b.stats.mtime;
|
return a.stats.mtime - b.stats.mtime;
|
||||||
@ -227,19 +230,22 @@ function processBlock(items) {
|
|||||||
console.log("Duplicate asset: " + asset.id + " vs " + results[0].photoId + ". Skipping " + asset.album.path + asset.filename);
|
console.log("Duplicate asset: " + asset.id + " vs " + results[0].photoId + ". Skipping " + asset.album.path + asset.filename);
|
||||||
duplicates.push(asset);
|
duplicates.push(asset);
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
/* Even if the hash doesn't need to be updated, the entry needs to be scanned */
|
||||||
|
needsProcessing.push(asset);
|
||||||
|
|
||||||
|
if (!query) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return photoDB.sequelize.query(query, {
|
return photoDB.sequelize.query(query, {
|
||||||
replacements: asset
|
replacements: asset
|
||||||
}).then(function() {
|
|
||||||
/* HASH has been updated; add to the needsProcessing array */
|
|
||||||
needsProcessing.push(asset);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
|
console.log(needsProcessing.length + " assets need to have metadata extracted");
|
||||||
return Promise.map(needsProcessing, function(asset) {
|
return Promise.map(needsProcessing, function(asset) {
|
||||||
var path = asset.album.path,
|
var path = asset.album.path,
|
||||||
file = asset.filename,
|
file = asset.filename,
|
||||||
@ -343,7 +349,8 @@ function processBlock(items) {
|
|||||||
});
|
});
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
return photoDB.sequelize.query("UPDATE photos SET " +
|
return photoDB.sequelize.query("UPDATE photos SET " +
|
||||||
"added=:added,modified=:modified,taken=:taken,width=:width,height=:height,scanned=CURRENT_TIMESTAMP", {
|
"added=:added,modified=:modified,taken=:taken,width=:width,height=:height,scanned=CURRENT_TIMESTAMP " +
|
||||||
|
"WHERE id=:id", {
|
||||||
replacements: asset
|
replacements: asset
|
||||||
});
|
});
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
@ -385,7 +392,22 @@ function processBlock(items) {
|
|||||||
concurrency: 1
|
concurrency: 1
|
||||||
});
|
});
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
console.log("Completed processing queue. " + duplicates.length + " duplicates.");
|
console.log("Completed processing queue. Marking " + duplicates.length + " duplicates.");
|
||||||
|
let dups = [];
|
||||||
|
duplicates.forEach(function(asset) {
|
||||||
|
/* If not already marked as a duplicate, mark it. */
|
||||||
|
if (!asset.duplicate) {
|
||||||
|
dups.push(asset.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return photoDB.sequelize.query("UPDATE photos SET duplicate=1,scanned=CURRENT_TIME WHERE id IN (:dups)", {
|
||||||
|
replacements: {
|
||||||
|
dups: dups
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).then(function() {
|
||||||
|
processRunning = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user