Работа над opds

This commit is contained in:
Book Pauk
2022-11-24 17:50:35 +07:00
parent fd9bc45fb1
commit 8de33fbd9a
3 changed files with 95 additions and 0 deletions

View File

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

View File

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

View File

@@ -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],
];