소스 검색

Работа над BookUpdateChecker

Book Pauk 2 년 전
부모
커밋
a1fcb7597b

+ 15 - 1
client/components/Reader/Reader.vue

@@ -573,14 +573,28 @@ class Reader {
 
             //теперь по кусочкам запросим сервер
             const arr = Array.from(updateUrls);
+            const bucSize = {};
             const chunkSize = 100;
             for (let i = 0; i < arr.length; i += chunkSize) {
                 const chunk = arr.slice(i, i + chunkSize);
 
                 const data = await readerApi.checkBuc(chunk);
-console.log(data);
+
+                for (const item of data) {
+                    bucSize[item.id] = item.size;
+                }
+
                 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);            
         } catch (e) {
             console.error(e);

+ 49 - 1
client/components/Reader/RecentBooksPage/RecentBooksPage.vue

@@ -126,6 +126,9 @@
                             <div style="font-size: 75%">
                                 {{ item.desc.title }}
                             </div>
+                            <div v-show="bothBucEnabled && item.needBookUpdate" style="font-size: 75%; color: blue">
+                                Старый размер: {{ item.bucSize }}, новый: {{ item.downloadSize }}
+                            </div>
                         </div>
 
                         <div class="row" style="font-size: 10px">
@@ -169,7 +172,7 @@
                             class="col column justify-center" 
                             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 :href="item.path" @click.prevent="downloadBook(item.path, item.fullTitle)">Скачать FB2</a>
                             </div>
@@ -195,6 +198,22 @@
                                 Восстановить из архива
                             </q-tooltip>
                         </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>
             </q-virtual-scroll>
@@ -240,6 +259,10 @@ class RecentBooksPage {
     tableData = [];
     sortMethod = '';
     showSameBook = false;
+    bucEnabled = false;
+    bucSizeDiff = 0;
+    bucSetOnNew = false;
+
     archive = false;
 
     covers = {};
@@ -277,12 +300,19 @@ class RecentBooksPage {
         const settings = this.settings;
         this.showSameBook = settings.recentShowSameBook;
         this.sortMethod = settings.recentSortMethod || 'loadTimeDesc';
+        this.bucEnabled = settings.bucEnabled;
+        this.bucSizeDiff = settings.bucSizeDiff;
+        this.bucSetOnNew = settings.bucSetOnNew;
     }
 
     get settings() {
         return this.$store.state.reader.settings;
     }
 
+    get bothBucEnabled() {
+        return this.$store.state.config.bucEnabled && this.bucEnabled;
+    }
+
     async updateTableData() {
         if (!this.inited)
             return;
@@ -344,6 +374,12 @@ class RecentBooksPage {
                     inGroup: false,
                     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,
                     touchTimeRaw: book.touchTime,
@@ -713,6 +749,14 @@ class RecentBooksPage {
         else
             return '';
     }
+
+    async checkBucChange(item) {
+        const book = await bookManager.getRecentBook(item);
+        if (book) {
+            book.checkBuc = item.checkBuc;
+            await bookManager.recentSetItem(book);
+        }
+    }
 }
 
 export default vueComponent(RecentBooksPage);
@@ -855,4 +899,8 @@ export default vueComponent(RecentBooksPage);
 .header-button-pressed:hover {
     color: black;
 }
+
+.buc-checkbox {
+    position: absolute;
+}
 </style>

+ 1 - 1
client/components/Reader/share/bookManager.js

@@ -237,7 +237,7 @@ class BookManager {
 
         if (newBook.downloadSize !== undefined && newBook.downloadSize >= 0)
             meta.downloadSize = newBook.downloadSize;
-        
+
         meta.key = this.keyFromPath(meta.path);
         meta.addTime = Date.now();//время добавления в кеш
 

+ 2 - 1
server/core/BookUpdateChecker/BUCClient.js

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