50 lines
1.0 KiB
JavaScript
50 lines
1.0 KiB
JavaScript
"use strict";
|
|
|
|
const express = require("express"),
|
|
fs = require("fs"),
|
|
url = require("url"),
|
|
config = require("config"),
|
|
moment = require("moment");
|
|
|
|
let photoDB;
|
|
|
|
require("../db/photos").then(function(db) {
|
|
photoDB = db;
|
|
});
|
|
|
|
const router = express.Router();
|
|
|
|
/* Each photos has:
|
|
|
|
* locations
|
|
* people
|
|
* date
|
|
* tags
|
|
* photo info
|
|
|
|
*/
|
|
|
|
router.get("/", function(req, res/*, next*/) {
|
|
let start = moment(req.query.start || 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 DESC";
|
|
return photoDB.sequelize.query(query, {
|
|
replacements: {
|
|
path: req.url.replace(/\?.*$/, "") + "%"
|
|
},
|
|
type: photoDB.Sequelize.QueryTypes.SELECT
|
|
}).then(function(days) {
|
|
|
|
let results = {
|
|
items: days
|
|
};
|
|
return res.status(200).json(results);
|
|
}).catch(function(error) {
|
|
console.error("Query failed: " + query);
|
|
return Promise.reject(error);
|
|
});
|
|
});
|
|
|
|
module.exports = router;
|