Добавлена автоотмена проверки обновлений книг по истечении заданного количества дней

This commit is contained in:
Book Pauk
2022-08-03 14:57:01 +07:00
parent 084401b9c3
commit 76673295bf
4 changed files with 80 additions and 12 deletions

View File

@@ -476,7 +476,10 @@ class Reader {
this.dualPageMode = settings.dualPageMode;
this.userWallpapers = settings.userWallpapers;
this.bucEnabled = settings.bucEnabled;
this.bucSizeDiff = settings.bucSizeDiff;
this.bucSetOnNew = settings.bucSetOnNew;
this.bucCancelEnabled = settings.bucCancelEnabled;
this.bucCancelDays = settings.bucCancelDays;
this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys);
this.$root.readerActionByKeyEvent = (event) => {
@@ -604,6 +607,7 @@ class Reader {
await utils.sleep(1000);//чтобы не ддосить сервер
}
const checkSetTime = {};
//проставим новые размеры у книг
for (const book of sorted) {
//размер 0 считаем отсутствующим
@@ -611,6 +615,40 @@ class Reader {
book.bucSize = bucSize[book.url];
await bookManager.recentSetItem(book);
}
//подготовка к следующему шагу
if (updateUrls.has(book.url)) {
let time = checkSetTime[book.key] || 0;
if (book.checkBucTime && book.checkBucTime > time) {
time = book.checkBucTime;
} else if (book.loadTime && book.loadTime > time) {
time = book.loadTime;
}
checkSetTime[book.key] = time;
}
}
//bucCancelEnabled и bucCancelDays
//снимем флаг checkBuc у необновлявшихся bucCancelDays
if (this.bucCancelEnabled) {
for (const [key, time] of Object.entries(checkSetTime)) {
if (time && Date.now() - time > this.bucCancelDays*24*3600*1000) {
const book = await bookManager.getRecentBook({key});
const needBookUpdate =
book.checkBuc
&& book.bucSize
&& utils.hasProp(book, 'downloadSize')
&& book.bucSize !== book.downloadSize
&& (book.bucSize - book.downloadSize >= this.bucSizeDiff)
;
if (book && !needBookUpdate) {
book.checkBuc = undefined;//!!!
await bookManager.recentSetItem(book);
}
}
}
}
await this.$refs.recentBooksPage.updateTableData();