diff --git a/frontend/src/ketr-photos/ketr-photos.html b/frontend/src/ketr-photos/ketr-photos.html index 93bac98..89928d7 100755 --- a/frontend/src/ketr-photos/ketr-photos.html +++ b/frontend/src/ketr-photos/ketr-photos.html @@ -655,11 +655,11 @@ }, breadcrumb: function(path) { - var crumbs = path.split("/"), parts = []; + var crumbs = path.replace(/(.*)\/$/, "/$1").split("/"), parts = []; path = ""; crumbs.forEach(function(crumb, index) { - if (crumb) { - path += "/" + crumb; + if (index > 0) { + path += crumb + "/"; } parts.push({ name: crumb ? crumb : "Top", @@ -736,7 +736,7 @@ if (top) { var photo = top.item; 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.*/, ""); this.$.pager.textContent = date; this.$.pager.style.top = headerHeight + @@ -966,11 +966,9 @@ return; } - var i = 0; photos.forEach(function(photo) { - var datetime = new Date((photo.taken || photo.modified || photo.added) + " GMT"), - year = datetime.getFullYear(); - for (; i < this.years.length; i++) { + var year = (photo.taken || photo.modified || photo.added).replace(/^(....).*$/, "$1"); + for (var i = 0; i < this.years.length; i++) { if (this.years[i] == year) { return; } @@ -1008,7 +1006,7 @@ thumbnail.addEventListener("load-image", this._imageTap.bind(this)); thumbnail.addEventListener("load-album", this.loadAlbum.bind(this)); 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) { console.log(JSON.stringify(photo, null, 2)); throw error; @@ -1112,18 +1110,18 @@ query += key + "=" + encodeURIComponent(params[key]); } - var path = this.path || "/", mode = this.mode; + var path = this.path || "", mode = this.mode; if (mode != "albums") { - path = "/" + mode; + path = mode; if (mode == "time") { path = ""; } else { - path = "/memories/" + (this.date || ""); + path = "memories/" + (this.date || ""); } } var username = this.user ? this.user.username : ""; 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; if (!this.user) { @@ -1132,8 +1130,8 @@ if ((username != (this.user ? this.user.username : "")) || (mode != this.mode) || - ((mode == "albums") && (path != (this.path || "/"))) || - ((mode == "memories") && (path != ("/memories/" + (this.date || ""))))) { + ((mode == "albums") && (path != (this.path || ""))) || + ((mode == "memories") && (path != ("memories/" + (this.date || ""))))) { console.log("Skipping results for old query. Triggering re-fetch of photos for new path or mode."); this._loadPhotos(); return; @@ -1181,22 +1179,22 @@ } this.loadingAlbums = true; - var path = this.path || "/"; - window.fetch("api/v1/albums" + path, function(path, error, xhr) { + var path = this.path || ""; + window.fetch("api/v1/albums/" + path, function(path, error, xhr) { this.loadingAlbums = false; if (!this.user) { return; } - if (path != (this.path || "/")) { + if (path != (this.path || "")) { console.log("Skipping results for old query. Triggering re-fetch of albums for new path."); this._loadAlbums(); return; } if (error) { - console.log("Error loading album: " + (this.path || "/")); + console.log("Error loading album: " + (this.path || "")); console.error(JSON.stringify(error, null, 2)); return; } diff --git a/server/app.js b/server/app.js index 2233a73..5788a2f 100755 --- a/server/app.js +++ b/server/app.js @@ -41,8 +41,6 @@ app.set("trust proxy", true); /* Handle static files first so excessive logging doesn't occur */ app.use(basePath, express.static("frontend", { index: false })); -app.use(morgan("common")); - app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false @@ -109,6 +107,9 @@ app.use(basePath, function(req, res, next) { }); 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/days", require("./routes/days")); app.use(basePath + "api/v1/albums", require("./routes/albums")); diff --git a/server/db/photos.js b/server/db/photos.js index 77ca84b..ef0c409 100755 --- a/server/db/photos.js +++ b/server/db/photos.js @@ -60,6 +60,10 @@ function init() { taken: Sequelize.DATE, width: Sequelize.INTEGER, height: Sequelize.INTEGER, + duplicate: { + type: Sequelize.BOOLEAN, + defaultValue: 0 + }, albumId: { type: Sequelize.INTEGER, allowNull: true, diff --git a/server/routes/albums.js b/server/routes/albums.js index 86891bc..8d59fc9 100644 --- a/server/routes/albums.js +++ b/server/routes/albums.js @@ -17,7 +17,7 @@ const router = express.Router(); router.get("/*", function(req, res/*, next*/) { let url = decodeURI(req.url).replace(/\?.*$/, "").replace(/^\//, ""), query = "SELECT * FROM albums WHERE path=:path"; - console.log("Looking up album: " + url); +// console.log("Looking up album: " + url); return photoDB.sequelize.query(query, { replacements: { path: url diff --git a/server/routes/photos.js b/server/routes/photos.js index b07d510..d758de0 100755 --- a/server/routes/photos.js +++ b/server/routes/photos.js @@ -38,13 +38,15 @@ router.get("/memories/*", function(req, res/*, next*/) { } if (id == -1) { - index = ""; + index = "strftime('%m%d',taken)=strftime('%m%d',:date)"; } else { - index = " AND ((taken=DATE(:cursor) AND photos.id<"+id+ ") OR taken