启动的时候检查截图与数据库的状态是否保持一致
This commit is contained in:
parent
72a3150a58
commit
e8becc4fa4
2
app.js
2
app.js
|
|
@ -75,7 +75,7 @@ app.use(function(err, req, res, next) {
|
||||||
error: {}
|
error: {}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
api.checkSnapState();
|
||||||
api.getSnapByTimer();
|
api.getSnapByTimer();
|
||||||
|
|
||||||
module.exports = app;
|
module.exports = app;
|
||||||
|
|
|
||||||
|
|
@ -561,6 +561,21 @@ db.getTagsBookmarks = function(bookmark_ids) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db.getBookmarks = function() {
|
||||||
|
var sql = "SELECT id, snap_state FROM `bookmarks`"; // 如果是空的,那查一个不存在的就行了。
|
||||||
|
console.log('getBookmarks', sql);
|
||||||
|
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
client.query(sql, (err, result) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve(result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
db.getBookmarkWaitSnap = function(today) {
|
db.getBookmarkWaitSnap = function(today) {
|
||||||
var todayNotSnap = today + 31;
|
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 created_at DESC LIMIT 0, 1";
|
var sql = "SELECT id, url, snap_state FROM `bookmarks` WHERE `snap_state`>=0 AND `snap_state` <= 64 AND snap_state != " + todayNotSnap + " ORDER BY created_at DESC LIMIT 0, 1";
|
||||||
|
|
|
||||||
|
|
@ -617,6 +617,23 @@ api.post('/getTitle', function(req, response) {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
api.checkSnapState = function() {
|
||||||
|
db.getBookmarks()
|
||||||
|
.then((bookmarks) => {
|
||||||
|
bookmarks.forEach(bookmark => {
|
||||||
|
var id = bookmark.id;
|
||||||
|
var snap_state = bookmark.snap_state;
|
||||||
|
var finePath = './public/images/snap/' + id + '.png'
|
||||||
|
fs.exists(finePath, function(exists) {
|
||||||
|
if (!exists && snap_state == -1) {
|
||||||
|
db.updateBookmarkSnapState(id, 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch((err) => console.log('getBookmarks err', err));
|
||||||
|
}
|
||||||
|
|
||||||
api.getSnapByTimer = function() {
|
api.getSnapByTimer = function() {
|
||||||
console.log('getSnapByTimer...........');
|
console.log('getSnapByTimer...........');
|
||||||
var timeout = 5000
|
var timeout = 5000
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue