|
@@ -252,15 +252,31 @@ function doCrawl(cat, force) {
|
|
|
|
|
|
var crawling = false;
|
|
|
|
|
|
-function doAllCrawl() {
|
|
|
+function doAllCrawl(force) {
|
|
|
if (crawling) return;
|
|
|
+ force = !!force
|
|
|
crawling = true;
|
|
|
|
|
|
let cats = _.values(defaults.category);
|
|
|
|
|
|
function getCat(idx) {
|
|
|
- console.log(`get cat ${cats[idx]}`);
|
|
|
- doCrawl(cats[idx]).then(function () {
|
|
|
+ let cat = cats[idx];
|
|
|
+ console.log(`get cat ${cat}`);
|
|
|
+
|
|
|
+ if(force){
|
|
|
+ var lastDates = settings().get('crawl').lastDates;
|
|
|
+ if (_.isUndefined(lastDates)) lastDates = {};
|
|
|
+ var lastDate = _.has(lastDates, cat) ? lastDates[cat] : '2024-09-01';
|
|
|
+ let date = moment(lastDate, 'YYYY-MM-DD').endOf('day');
|
|
|
+ if (date.isBefore(moment())) date.add(1, 'day');
|
|
|
+ if (date.isAfter(moment())) { //rollback only last day if force
|
|
|
+ date.subtract(2, 'day');
|
|
|
+ lastDates[cat] = moment(date).format('YYYY-MM-DD');
|
|
|
+ settings().set('crawl', {lastDates: lastDates});
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ doCrawl(cat, force).then(function () {
|
|
|
if (idx + 1 < cats.length)
|
|
|
getCat(idx + 1);
|
|
|
else {
|
|
@@ -292,4 +308,8 @@ ipc.on('global:refresh', function () {
|
|
|
if (!crawling) doAllCrawl();
|
|
|
});
|
|
|
|
|
|
+ipc.on('global:refresh:force', function () {
|
|
|
+ if (!crawling) doAllCrawl('force');
|
|
|
+});
|
|
|
+
|
|
|
module.exports = {};
|