Работа над opds

This commit is contained in:
Book Pauk
2022-11-23 20:57:41 +07:00
parent 6a3b919f5f
commit 6dfa551b97
3 changed files with 21 additions and 16 deletions

View File

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

View File

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

View File

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