浏览代码

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

Book Pauk 2 年之前
父节点
当前提交
5519e23e02

+ 2 - 2
server/core/opds/AuthorPage.js

@@ -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);
 

+ 3 - 1
server/core/opds/BasePage.js

@@ -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) => {

+ 9 - 5
server/core/opds/GenrePage.js

@@ -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}`}),
                         })
                     );
                 }

+ 3 - 0
server/core/opds/RootPage.js

@@ -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);

+ 11 - 1
server/core/opds/SearchPage.js

@@ -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: '[Памятка по поиску]',

+ 2 - 2
server/core/opds/SeriesPage.js

@@ -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);
 

+ 1 - 1
server/core/opds/TitlePage.js

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