OPDS: добавлен раздел "Жанры", в поиск добавлен раздел "Поиск книг в жанре" (#9)

This commit is contained in:
Book Pauk
2023-01-28 18:14:35 +07:00
parent 4d6da6a9b7
commit 5519e23e02
7 changed files with 31 additions and 12 deletions

View File

@@ -66,7 +66,7 @@ class AuthorPage extends BasePage {
author: req.query.author || '',
series: req.query.series || '',
genre: req.query.genre || '',
del: 0,
del: '0',
all: req.query.all || '',
depth: 0,
@@ -86,7 +86,7 @@ class AuthorPage extends BasePage {
if (bookList.books) {
let books = bookList.books;
const booksAll = this.filterBooks(books, {del: 0});
const booksAll = this.filterBooks(books);
const filtered = (query.all ? booksAll : this.filterBooks(books, query));
const sorted = this.sortSeriesBooks(filtered);

View File

@@ -20,6 +20,8 @@ class BasePage {
this.webWorker = new WebWorker(config);
this.rootTag = 'feed';
this.opdsRoot = config.opdsRoot;
this.showDeleted = false;
}
makeEntry(entry = {}) {
@@ -213,7 +215,7 @@ class BasePage {
}
//скопировано из BaseList.js, часть функционала не используется
filterBooks(books, query) {
filterBooks(books, query = {}) {
const s = query;
const splitAuthor = (author) => {

View File

@@ -13,13 +13,17 @@ class GenrePage extends BasePage {
const result = {};
const query = {
from: req.query.from || '',
from: req.query.from || 'search',
term: req.query.term || '*',
section: req.query.section || '',
};
let searchQuery = '';
if (query.from == 'search')
searchQuery = `&type=title&term=${encodeURIComponent(query.term)}`;
const entry = [];
if (query.from) {
if (query.section) {
//выбираем подразделы
const {genreSection} = await this.getGenres();
@@ -34,7 +38,7 @@ class GenrePage extends BasePage {
this.makeEntry({
id: ++id,
title: g.name,
link: this.navLink({href: `/${encodeURIComponent(query.from)}?genre=${encodeURIComponent(g.value)}`}),
link: this.navLink({href: `/${encodeURIComponent(query.from)}?genre=${encodeURIComponent(g.value)}${searchQuery}`}),
})
);
}
@@ -43,7 +47,7 @@ class GenrePage extends BasePage {
this.makeEntry({
id: 'whole_section',
title: '[Весь раздел]',
link: this.navLink({href: `/${encodeURIComponent(query.from)}?genre=${encodeURIComponent(all.join(','))}`}),
link: this.navLink({href: `/${encodeURIComponent(query.from)}?genre=${encodeURIComponent(all.join(','))}${searchQuery}`}),
})
);
}
@@ -56,7 +60,7 @@ class GenrePage extends BasePage {
this.makeEntry({
id: ++id,
title: section.name,
link: this.navLink({href: `/genre?from=${encodeURIComponent(query.from)}&section=${encodeURIComponent(section.name)}`}),
link: this.navLink({href: `/genre?from=${encodeURIComponent(query.from)}&section=${encodeURIComponent(section.name)}${searchQuery}`}),
})
);
}

View File

@@ -2,6 +2,7 @@ const BasePage = require('./BasePage');
const AuthorPage = require('./AuthorPage');
const SeriesPage = require('./SeriesPage');
const TitlePage = require('./TitlePage');
const GenrePage = require('./GenrePage');
class RootPage extends BasePage {
constructor(config) {
@@ -13,6 +14,7 @@ class RootPage extends BasePage {
this.authorPage = new AuthorPage(config);
this.seriesPage = new SeriesPage(config);
this.titlePage = new TitlePage(config);
this.genrePage = new GenrePage(config);
}
async body(req) {
@@ -30,6 +32,7 @@ class RootPage extends BasePage {
this.authorPage.myEntry(),
this.seriesPage.myEntry(),
this.titlePage.myEntry(),
this.genrePage.myEntry(),
];
return this.makeBody(result, req);

View File

@@ -15,6 +15,7 @@ class SearchPage extends BasePage {
const query = {
type: req.query.type || '',
term: req.query.term || '',
genre: req.query.genre || '',
page: parseInt(req.query.page, 10) || 1,
};
@@ -27,7 +28,7 @@ class SearchPage extends BasePage {
const limit = 100;
const offset = (page - 1)*limit;
const queryRes = await this.webWorker.search(from, {[from]: query.term, del: 0, offset, limit});
const queryRes = await this.webWorker.search(from, {[from]: query.term, genre: query.genre, del: '0', offset, limit});
const found = queryRes.found;
@@ -98,6 +99,15 @@ class SearchPage extends BasePage {
'*TEXT': `Искать по названиям книг`,
},
}),
this.makeEntry({
id: 'search_genre',
title: 'Поиск книг в жанре',
link: this.navLink({href: `/genre?from=search&term=${encodeURIComponent(query.term)}`}),
content: {
'*ATTRS': {type: 'text'},
'*TEXT': `Искать по названиям книг в выбранном жанре`,
},
}),
this.makeEntry({
id: 'search_help',
title: '[Памятка по поиску]',

View File

@@ -26,7 +26,7 @@ class SeriesPage extends BasePage {
const query = {
series: req.query.series || '',
genre: req.query.genre || '',
del: 0,
del: '0',
all: req.query.all || '',
depth: 0,
@@ -46,7 +46,7 @@ class SeriesPage extends BasePage {
if (bookList.books) {
let books = bookList.books;
const booksAll = this.filterBooks(books, {del: 0});
const booksAll = this.filterBooks(books);
const filtered = (query.all ? booksAll : this.filterBooks(books, query));
const sorted = this.sortSeriesBooks(filtered);

View File

@@ -15,7 +15,7 @@ class TitlePage extends BasePage {
const query = {
title: req.query.title || '',
genre: req.query.genre || '',
del: 0,
del: '0',
depth: 0,
};