Procházet zdrojové kódy

Работа над opds

Book Pauk před 2 roky
rodič
revize
6dfa551b97

+ 2 - 2
server/core/DbSearcher.js

@@ -546,15 +546,15 @@ class DbSearcher {
         try {
             const db = this.db;
 
+            const depth = query.depth || 1;
             const queryKey = this.queryKey(query);
-            const opdsKey = `${from}-opds-${queryKey}`;
+            const opdsKey = `${from}-opds-d${depth}-${queryKey}`;
             let result = await this.getCached(opdsKey);
 
             if (result === null) {
                 const ids = await this.selectTableIds(from, query);
 
                 const totalFound = ids.length;
-                const depth = query.depth || 1;
 
                 //группировка по name длиной depth
                 const found = await db.select({

+ 0 - 1
server/core/opds/AuthorPage.js

@@ -70,7 +70,6 @@ class AuthorPage extends BasePage {
             series: req.query.series || '',
             genre: req.query.genre || '',
             del: 0,
-            limit: 100,
             
             all: req.query.all || '',
             depth: 0,

+ 19 - 13
server/core/opds/BasePage.js

@@ -138,7 +138,7 @@ class BasePage {
         return result;
     }
 
-    async opdsQuery(from, query, otherTitle = '[Другие]') {
+    async opdsQuery(from, query, otherTitle = '[Другие]', prevLen = 0) {
         const queryRes = await this.webWorker.opdsQuery(from, query);
         let count = 0;
         for (const row of queryRes.found)
@@ -146,21 +146,30 @@ class BasePage {
 
         const others = [];
         let result = [];
-        if (count <= query.limit) {
-            result = await this.search(from, query);
+        if (count <= 50) {
+            //конец навигации
+            return await this.search(from, query);
         } else {
             const names = new Set();
+            let len = 0;
             for (const row of queryRes.found) {
                 const name = row.name.toUpperCase();
+                const lowName = row.name.toLowerCase();
+                len += name.length;
+
+                if (lowName == query[from]) {
+                    //конец навигации, результат содержит запрос
+                    return await this.search(from, query);
+                }
 
                 if (!names.has(name)) {
                     const rec = {
                         id: row.id,
                         title: name.replace(/ /g, spaceChar),
-                        q: encodeURIComponent(row.name.toLowerCase()),
+                        q: encodeURIComponent(lowName),
                         count: row.count,
                     };
-                    if (query.depth > 1 || enru.has(row.name[0].toLowerCase())) {
+                    if (query.depth > 1 || enru.has(lowName[0])) {
                         result.push(rec);
                     } else {
                         others.push(rec);
@@ -168,15 +177,12 @@ class BasePage {
                     names.add(name);
                 }
             }
-        }
-
-        if (query.depth > 1 && result.length == 1 && query[from]) {
-            const newQuery = _.cloneDeep(query);
-            newQuery[from] = decodeURIComponent(result[0].q);
 
-            if (newQuery[from].length >= query.depth) {
-                newQuery.depth = newQuery[from].length + 1;
-                return await this.opdsQuery(from, newQuery);
+            if (query[from] && query.depth > 1 && result.length < 20 && len > prevLen) {
+                //рекурсия, с увеличением глубины, для облегчения навигации
+                const newQuery = _.cloneDeep(query);
+                newQuery.depth++;
+                return await this.opdsQuery(from, newQuery, otherTitle, len);
             }
         }