Работа над opds

This commit is contained in:
Book Pauk
2022-11-24 19:08:34 +07:00
parent 72ab94291c
commit 870f95a51f
4 changed files with 65 additions and 7 deletions

View File

@@ -89,11 +89,21 @@ class BasePage {
});
}
baseLinks(req) {
return [
baseLinks(req, selfAcq = false) {
const result = [
this.makeLink({href: `${this.opdsRoot}/opensearch`, rel: 'search', type: 'application/opensearchdescription+xml'}),
this.makeLink({href: `${this.opdsRoot}/search?term={searchTerms}`, rel: 'search', type: 'application/atom+xml'}),
this.navLink({rel: 'start'}),
this.navLink({rel: 'self', href: req.originalUrl, hrefAsIs: true}),
];
if (selfAcq) {
result.push(this.acqLink({rel: 'self', href: req.originalUrl, hrefAsIs: true}));
} else {
result.push(this.navLink({rel: 'self', href: req.originalUrl, hrefAsIs: true}));
}
return result;
}
makeBody(content, req) {

View File

@@ -119,10 +119,7 @@ class BookPage extends BasePage {
async body(req) {
const result = {};
result.link = [
this.navLink({rel: 'start'}),
this.acqLink({rel: 'self', href: req.originalUrl, hrefAsIs: true}),
];
result.link = this.baseLinks(req, true);
const bookUid = req.query.uid;
const entry = [];

View File

@@ -0,0 +1,45 @@
const BasePage = require('./BasePage');
const XmlParser = require('../xml/XmlParser');
class OpensearchPage extends BasePage {
constructor(config) {
super(config);
this.id = 'opensearch';
this.title = 'opensearch';
}
async body() {
const xml = new XmlParser();
const xmlObject = {};
/*
<?xml version="1.0" encoding="utf-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>inpx-web</ShortName>
<Description>Поиск по каталогу</Description>
<InputEncoding>UTF-8</InputEncoding>
<OutputEncoding>UTF-8</OutputEncoding>
<Url type="application/atom+xml;profile=opds-catalog;kind=navigation" template="/opds/search?term={searchTerms}"/>
</OpenSearchDescription>
*/
xmlObject['OpenSearchDescription'] = {
'*ATTRS': {xmlns: 'http://a9.com/-/spec/opensearch/1.1/'},
ShortName: 'inpx-web',
Description: 'Поиск по каталогу',
InputEncoding: 'UTF-8',
OutputEncoding: 'UTF-8',
Url: {
'*ATTRS': {
type: 'application/atom+xml;profile=opds-catalog;kind=navigation',
template: `${this.opdsRoot}/search?term={searchTerms}`,
},
},
}
xml.fromObject(xmlObject);
return xml.toString({format: true});
}
}
module.exports = OpensearchPage;

View File

@@ -5,6 +5,8 @@ const TitlePage = require('./TitlePage');
const GenrePage = require('./GenrePage');
const BookPage = require('./BookPage');
const OpensearchPage = require('./OpensearchPage');
module.exports = function(app, config) {
const opdsRoot = '/opds';
config.opdsRoot = opdsRoot;
@@ -16,6 +18,8 @@ module.exports = function(app, config) {
const genre = new GenrePage(config);
const book = new BookPage(config);
const opensearch = new OpensearchPage(config);
const routes = [
['', root],
['/root', root],
@@ -24,6 +28,8 @@ module.exports = function(app, config) {
['/title', title],
['/genre', genre],
['/book', book],
['/opensearch', opensearch],
];
const pages = new Map();