From 8de33fbd9a30aa58c8151826ae678fe5c168470e Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Thu, 24 Nov 2022 17:50:35 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B4=20opds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/opds/RootPage.js | 3 ++ server/core/opds/TitlePage.js | 89 +++++++++++++++++++++++++++++++++++ server/core/opds/index.js | 3 ++ 3 files changed, 95 insertions(+) create mode 100644 server/core/opds/TitlePage.js diff --git a/server/core/opds/RootPage.js b/server/core/opds/RootPage.js index 481884e..4ee4fb6 100644 --- a/server/core/opds/RootPage.js +++ b/server/core/opds/RootPage.js @@ -1,6 +1,7 @@ const BasePage = require('./BasePage'); const AuthorPage = require('./AuthorPage'); const SeriesPage = require('./SeriesPage'); +const TitlePage = require('./TitlePage'); class RootPage extends BasePage { constructor(config) { @@ -11,6 +12,7 @@ class RootPage extends BasePage { this.authorPage = new AuthorPage(config); this.seriesPage = new SeriesPage(config); + this.titlePage = new TitlePage(config); } async body(req) { @@ -27,6 +29,7 @@ class RootPage extends BasePage { result.entry = [ this.authorPage.myEntry(), this.seriesPage.myEntry(), + this.titlePage.myEntry(), ]; return this.makeBody(result, req); diff --git a/server/core/opds/TitlePage.js b/server/core/opds/TitlePage.js new file mode 100644 index 0000000..beb92f3 --- /dev/null +++ b/server/core/opds/TitlePage.js @@ -0,0 +1,89 @@ +const BasePage = require('./BasePage'); + +class TitlePage extends BasePage { + constructor(config) { + super(config); + + this.id = 'title'; + this.title = 'Книги'; + } + + async body(req) { + const result = {}; + + const query = { + title: req.query.title || '', + genre: req.query.genre || '', + del: 0, + + depth: 0, + }; + query.depth = query.title.length + 1; + + if (query.title == '___others') { + query.title = ''; + query.depth = 1; + query.others = true; + } + + const entry = []; + if (query.title && query.title[0] == '=') { + //книги по названию + const res = await this.webWorker.search('title', query); + + if (res.found.length) { + const books = res.found[0].books || []; + const filtered = this.filterBooks(books, query); + + for (const book of filtered) { + const title = `${book.serno ? `${book.serno}. `: ''}${book.title || 'Без названия'} (${book.ext})`; + + const e = { + id: book._uid, + title, + link: this.acqLink({href: `/book?uid=${encodeURIComponent(book._uid)}`}), + }; + + if (query.all) { + e.content = { + '*ATTRS': {type: 'text'}, + '*TEXT': this.bookAuthor(book.author), + } + } + + entry.push( + this.makeEntry(e) + ); + } + } + } else { + if (query.depth == 1 && !query.genre && !query.others) { + entry.push( + this.makeEntry({ + id: 'select_genre', + title: '[Выбрать жанр]', + link: this.navLink({href: `/genre?from=${this.id}`}), + }) + ); + } + + //навигация по каталогу + const queryRes = await this.opdsQuery('title', query, '[Остальные названия]'); + + for (const rec of queryRes) { + entry.push( + this.makeEntry({ + id: rec.id, + title: rec.title, + link: this.navLink({href: `/${this.id}?title=${rec.q}&genre=${encodeURIComponent(query.genre)}`}), + }) + ); + } + } + + result.entry = entry; + return this.makeBody(result, req); + } +} + +module.exports = TitlePage; \ No newline at end of file diff --git a/server/core/opds/index.js b/server/core/opds/index.js index 60501b2..f9f28f4 100644 --- a/server/core/opds/index.js +++ b/server/core/opds/index.js @@ -1,6 +1,7 @@ const RootPage = require('./RootPage'); const AuthorPage = require('./AuthorPage'); const SeriesPage = require('./SeriesPage'); +const TitlePage = require('./TitlePage'); const GenrePage = require('./GenrePage'); const BookPage = require('./BookPage'); @@ -11,6 +12,7 @@ module.exports = function(app, config) { const root = new RootPage(config); const author = new AuthorPage(config); const series = new SeriesPage(config); + const title = new TitlePage(config); const genre = new GenrePage(config); const book = new BookPage(config); @@ -19,6 +21,7 @@ module.exports = function(app, config) { ['/root', root], ['/author', author], ['/series', series], + ['/title', title], ['/genre', genre], ['/book', book], ];