Работа над BookUpdateChecker

This commit is contained in:
Book Pauk
2022-07-27 14:08:59 +07:00
parent 35e46d0685
commit a1fcb7597b
4 changed files with 67 additions and 4 deletions

View File

@@ -573,14 +573,28 @@ class Reader {
//теперь по кусочкам запросим сервер //теперь по кусочкам запросим сервер
const arr = Array.from(updateUrls); const arr = Array.from(updateUrls);
const bucSize = {};
const chunkSize = 100; const chunkSize = 100;
for (let i = 0; i < arr.length; i += chunkSize) { for (let i = 0; i < arr.length; i += chunkSize) {
const chunk = arr.slice(i, i + chunkSize); const chunk = arr.slice(i, i + chunkSize);
const data = await readerApi.checkBuc(chunk); const data = await readerApi.checkBuc(chunk);
console.log(data);
for (const item of data) {
bucSize[item.id] = item.size;
}
await utils.sleep(1000);//чтобы не ддосить сервер await utils.sleep(1000);//чтобы не ддосить сервер
} }
//проставим новые размеры у книг
for (const book of sorted) {
//размер 0 считаем отсутствующим
if (book.url && bucSize[book.url] && bucSize[book.url] !== book.bucSize) {
book.bucSize = bucSize[book.url];
await bookManager.recentSetItem(book);
}
}
console.log('checkBuc finished', arr); console.log('checkBuc finished', arr);
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@@ -126,6 +126,9 @@
<div style="font-size: 75%"> <div style="font-size: 75%">
{{ item.desc.title }} {{ item.desc.title }}
</div> </div>
<div v-show="bothBucEnabled && item.needBookUpdate" style="font-size: 75%; color: blue">
Старый размер: {{ item.bucSize }}, новый: {{ item.downloadSize }}
</div>
</div> </div>
<div class="row" style="font-size: 10px"> <div class="row" style="font-size: 10px">
@@ -169,7 +172,7 @@
class="col column justify-center" class="col column justify-center"
style="font-size: 75%; padding-left: 6px; border: 1px solid #cccccc; border-left: 0;" style="font-size: 75%; padding-left: 6px; border: 1px solid #cccccc; border-left: 0;"
> >
<div :style="`margin-top: ${(archive ? 20 : 0)}px`"> <div style="margin: 20px 0 0 5px">
<a v-show="isUrl(item.url)" :href="item.url" target="_blank">Оригинал</a><br><br> <a v-show="isUrl(item.url)" :href="item.url" target="_blank">Оригинал</a><br><br>
<a :href="item.path" @click.prevent="downloadBook(item.path, item.fullTitle)">Скачать FB2</a> <a :href="item.path" @click.prevent="downloadBook(item.path, item.fullTitle)">Скачать FB2</a>
</div> </div>
@@ -195,6 +198,22 @@
Восстановить из архива Восстановить из архива
</q-tooltip> </q-tooltip>
</div> </div>
<div
v-show="bothBucEnabled && item.showCheckBuc"
class="buc-checkbox self-start"
>
<q-checkbox
v-model="item.checkBuc"
size="xs"
style="position: relative; top: -5px; left: -5px;"
@update:model-value="checkBucChange(item)"
>
<q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
Проверять обновления
</q-tooltip>
</q-checkbox>
</div>
</div> </div>
</div> </div>
</q-virtual-scroll> </q-virtual-scroll>
@@ -240,6 +259,10 @@ class RecentBooksPage {
tableData = []; tableData = [];
sortMethod = ''; sortMethod = '';
showSameBook = false; showSameBook = false;
bucEnabled = false;
bucSizeDiff = 0;
bucSetOnNew = false;
archive = false; archive = false;
covers = {}; covers = {};
@@ -277,12 +300,19 @@ class RecentBooksPage {
const settings = this.settings; const settings = this.settings;
this.showSameBook = settings.recentShowSameBook; this.showSameBook = settings.recentShowSameBook;
this.sortMethod = settings.recentSortMethod || 'loadTimeDesc'; this.sortMethod = settings.recentSortMethod || 'loadTimeDesc';
this.bucEnabled = settings.bucEnabled;
this.bucSizeDiff = settings.bucSizeDiff;
this.bucSetOnNew = settings.bucSetOnNew;
} }
get settings() { get settings() {
return this.$store.state.reader.settings; return this.$store.state.reader.settings;
} }
get bothBucEnabled() {
return this.$store.state.config.bucEnabled && this.bucEnabled;
}
async updateTableData() { async updateTableData() {
if (!this.inited) if (!this.inited)
return; return;
@@ -344,6 +374,12 @@ class RecentBooksPage {
inGroup: false, inGroup: false,
coverPageUrl: book.coverPageUrl, coverPageUrl: book.coverPageUrl,
showCheckBuc: !this.archive && utils.hasProp(book, 'downloadSize'),
checkBuc: !!book.checkBuc,
needBookUpdate: (!this.archive && book.checkBuc && book.bucSize && utils.hasProp(book, 'downloadSize') && (book.bucSize - book.downloadSize >= this.bucSizeDiff)),
bucSize: book.bucSize,
downloadSize: book.downloadSize,
//для сортировки //для сортировки
loadTimeRaw, loadTimeRaw,
touchTimeRaw: book.touchTime, touchTimeRaw: book.touchTime,
@@ -713,6 +749,14 @@ class RecentBooksPage {
else else
return ''; return '';
} }
async checkBucChange(item) {
const book = await bookManager.getRecentBook(item);
if (book) {
book.checkBuc = item.checkBuc;
await bookManager.recentSetItem(book);
}
}
} }
export default vueComponent(RecentBooksPage); export default vueComponent(RecentBooksPage);
@@ -855,4 +899,8 @@ export default vueComponent(RecentBooksPage);
.header-button-pressed:hover { .header-button-pressed:hover {
color: black; color: black;
} }
.buc-checkbox {
position: absolute;
}
</style> </style>

View File

@@ -78,7 +78,8 @@ class BUCClient {
const rows = await db.select({ const rows = await db.select({
table: 'buc', table: 'buc',
where: `@@id(${db.esc(bookUrls)})` map: `(r) => ({id: r.id, size: r.size})`,
where: `@@id(${db.esc(bookUrls)})`,
}); });
return rows; return rows;