diff --git a/.gitignore b/.gitignore index 39c8249..13cd3c8 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,4 @@ jspm_packages # Upload File uploads -/public/images/shot/ \ No newline at end of file +/public/images/snap/ \ No newline at end of file diff --git a/app.js b/app.js index fe91d77..120becc 100644 --- a/app.js +++ b/app.js @@ -76,5 +76,6 @@ app.use(function(err, req, res, next) { }); }); +api.getSnapByTimer(); module.exports = app; diff --git a/database/db.js b/database/db.js index 365a4e0..7ff4e48 100644 --- a/database/db.js +++ b/database/db.js @@ -52,15 +52,15 @@ Date.prototype.format = function(fmt) { //author: meizz // update delete 返回影响的行数 var db = { -} -// var sql = "SELECT * FROM `users` WHERE `username` = 'luchenqun'"; -// client.query(sql, (err, result) => { -// if (err) { -// console.log(err); -// } else { -// console.log(result); -// } -// }); + } + // var sql = "SELECT * FROM `users` WHERE `username` = 'luchenqun1'"; + // client.query(sql, (err, result) => { + // if (err) { + // console.log(err); + // } else { + // console.log(result); + // } + // }); db.addBookmark = function(user_id, bookmark) { var insertSql = "INSERT INTO `bookmarks` (`user_id`, `title`, `description`, `url`, `public`, `click_count`) VALUES ('" + user_id + "', '" + bookmark.title + "', '" + bookmark.description + "', '" + bookmark.url + "', '" + bookmark.public + "', '1')"; @@ -561,4 +561,32 @@ db.getTagsBookmarks = function(bookmark_ids) { }); } +db.getBookmarkWaitSnap = function(today) { + var todayNotSnap = today + 31; + var sql = "SELECT id, url, snap_state FROM `bookmarks` WHERE `snap_state`>=0 AND `snap_state` <= 64 AND snap_state != " + todayNotSnap + " ORDER BY last_click DESC LIMIT 0, 1"; + return new Promise(function(resolve, reject) { + client.query(sql, (err, result) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); +} + +db.updateBookmarkSnapState = function(id, snapState) { + console.log("updateBookmarkSnapState id = " + id + ", snapState = " + snapState); + var sql = "UPDATE `bookmarks` SET `snap_state`='"+ snapState +"' WHERE (`id`='"+ id +"')"; + return new Promise(function(resolve, reject) { + client.query(sql, (err, result) => { + if (err) { + reject(err); + } else { + resolve(result.affectedRows); + } + }); + }); +} + module.exports = db; diff --git a/public/views/bookmarks.html b/public/views/bookmarks.html index 3104b47..d19e62a 100644 --- a/public/views/bookmarks.html +++ b/public/views/bookmarks.html @@ -95,7 +95,7 @@