"use strict"; /* Memories: echo "select id,taken from photos where strftime('%m%d',taken)=strftime('%m%d',CURRENT_TIMESTAMP) order by taken desc;" | sqlite3 photos.db */ const express = require("express"), fs = require("fs"), url = require("url"), config = require("config"), moment = require("moment"); let photoDB; require("../db").then(function(db) { photoDB = db; }); const router = express.Router(); /* Each photos has: * locations * people * date * tags * photo info */ router.get("/memories", function(req, res/*, next*/) { let limit = parseInt(req.query.limit) || 50, id, cursor, index; if (req.query.next) { let parts = req.query.next.split("_"); cursor = parts[0]; id = parseInt(parts[1]); } else { cursor = ""; id = -1; } if (id == -1) { index = ""; } else { if (id != -1) { index = " AND ((taken=DATE(:cursor) AND id<"+id+ ") OR taken limit; /* We queried one extra item to see if there are more than LIMIT available */ if (more) { photos.splice(limit); } let results = { items: photos }; if (more) { results.more = true; } return res.status(200).json(results); }).catch(function(error) { console.error("Query failed: " + query); return Promise.reject(error); }); }); router.get("/*", function(req, res/*, next*/) { let limit = parseInt(req.query.limit) || 50, id, cursor, index; if (req.query.next) { let parts = req.query.next.split("_"); cursor = parts[0]; id = parseInt(parts[1]); } else { cursor = ""; id = -1; } if (id == -1) { index = ""; } else { if (id != -1) { index = " AND ((taken=DATE(:cursor) AND id<"+id+ ") OR taken limit; /* We queried one extra item to see if there are more than LIMIT available */ if (more) { photos.splice(limit); } let results = { items: photos }; if (more) { results.more = true; } return res.status(200).json(results); }).catch(function(error) { console.error("Query failed: " + query); return Promise.reject(error); }); }); module.exports = router;