Работа над opds
This commit is contained in:
@@ -94,7 +94,7 @@ class AuthorPage extends BasePage {
|
|||||||
this.makeEntry({
|
this.makeEntry({
|
||||||
id: book._uid,
|
id: book._uid,
|
||||||
title,
|
title,
|
||||||
link: this.navLink({href: `/book?uid=${encodeURIComponent(book._uid)}`}),
|
link: this.acqLink({href: `/book?uid=${encodeURIComponent(book._uid)}`}),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,7 @@ class AuthorPage extends BasePage {
|
|||||||
this.makeEntry({
|
this.makeEntry({
|
||||||
id: b.book._uid,
|
id: b.book._uid,
|
||||||
title,
|
title,
|
||||||
link: this.navLink({href: `/book?uid=${encodeURIComponent(b.book._uid)}`}),
|
link: this.acqLink({href: `/book?uid=${encodeURIComponent(b.book._uid)}`}),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -146,7 +146,7 @@ class AuthorPage extends BasePage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result.entry = entry;
|
result.entry = entry;
|
||||||
return this.makeBody(result);
|
return this.makeBody(result, req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,28 +50,36 @@ class BasePage {
|
|||||||
|
|
||||||
navLink(attrs) {
|
navLink(attrs) {
|
||||||
return this.makeLink({
|
return this.makeLink({
|
||||||
href: this.opdsRoot + (attrs.href || ''),
|
href: (attrs.hrefAsIs ? attrs.href : `${this.opdsRoot}${attrs.href || ''}`),
|
||||||
rel: attrs.rel || 'subsection',
|
rel: attrs.rel || 'subsection',
|
||||||
type: 'application/atom+xml; profile=opds-catalog; kind=navigation',
|
type: 'application/atom+xml;profile=opds-catalog;kind=navigation',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
acqLink(attrs) {
|
acqLink(attrs) {
|
||||||
|
return this.makeLink({
|
||||||
|
href: this.opdsRoot + (attrs.href || ''),
|
||||||
|
rel: attrs.rel || 'subsection',
|
||||||
|
type: 'application/atom+xml;profile=opds-catalog;kind=acquisition',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
downLink(attrs) {
|
||||||
if (!attrs.href)
|
if (!attrs.href)
|
||||||
throw new Error('acqLink: no href');
|
throw new Error('downLink: no href');
|
||||||
if (!attrs.type)
|
if (!attrs.type)
|
||||||
throw new Error('acqLink: no type');
|
throw new Error('downLink: no type');
|
||||||
|
|
||||||
return this.makeLink({
|
return this.makeLink({
|
||||||
href: attrs.href,
|
href: attrs.href,
|
||||||
rel: 'http://opds-spec.org/acquisition/open-access',
|
rel: 'http://opds-spec.org/acquisition',
|
||||||
type: attrs.type,
|
type: attrs.type,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
imgLink(attrs) {
|
imgLink(attrs) {
|
||||||
if (!attrs.href)
|
if (!attrs.href)
|
||||||
throw new Error('acqLink: no href');
|
throw new Error('imgLink: no href');
|
||||||
|
|
||||||
return this.makeLink({
|
return this.makeLink({
|
||||||
href: attrs.href,
|
href: attrs.href,
|
||||||
@@ -80,14 +88,14 @@ class BasePage {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
baseLinks() {
|
baseLinks(req) {
|
||||||
return [
|
return [
|
||||||
this.navLink({rel: 'start'}),
|
this.navLink({rel: 'start'}),
|
||||||
this.navLink({rel: 'self', href: (this.id ? `/${this.id}` : '')}),
|
this.navLink({rel: 'self', href: req.originalUrl, hrefAsIs: true}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
makeBody(content) {
|
makeBody(content, req) {
|
||||||
const base = this.makeEntry({id: this.id, title: this.title});
|
const base = this.makeEntry({id: this.id, title: this.title});
|
||||||
base['*ATTRS'] = {
|
base['*ATTRS'] = {
|
||||||
'xmlns': 'http://www.w3.org/2005/Atom',
|
'xmlns': 'http://www.w3.org/2005/Atom',
|
||||||
@@ -96,7 +104,7 @@ class BasePage {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!content.link)
|
if (!content.link)
|
||||||
base.link = this.baseLinks();
|
base.link = this.baseLinks(req);
|
||||||
|
|
||||||
const xml = new XmlParser();
|
const xml = new XmlParser();
|
||||||
const xmlObject = {};
|
const xmlObject = {};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
const path = require('path');
|
||||||
const BasePage = require('./BasePage');
|
const BasePage = require('./BasePage');
|
||||||
|
|
||||||
class BookPage extends BasePage {
|
class BookPage extends BasePage {
|
||||||
@@ -16,21 +17,29 @@ class BookPage extends BasePage {
|
|||||||
if (bookUid) {
|
if (bookUid) {
|
||||||
const {bookInfo} = await this.webWorker.getBookInfo(bookUid);
|
const {bookInfo} = await this.webWorker.getBookInfo(bookUid);
|
||||||
if (bookInfo) {
|
if (bookInfo) {
|
||||||
entry.push(
|
const e = this.makeEntry({
|
||||||
this.makeEntry({
|
id: bookUid,
|
||||||
id: bookUid,
|
title: bookInfo.book.title || 'Без названия',
|
||||||
title: bookInfo.book.title || 'Без названия',
|
link: [
|
||||||
link: [
|
this.downLink({href: bookInfo.link, type: `application/${bookInfo.book.ext}+zip`}),
|
||||||
//this.imgLink({href: bookInfo.cover, type: coverType}),
|
],
|
||||||
this.acqLink({href: bookInfo.link, type: `application/${bookInfo.book.ext}+gzip`}),
|
});
|
||||||
],
|
|
||||||
})
|
if (bookInfo.cover) {
|
||||||
);
|
let coverType = 'image/jpeg';
|
||||||
|
if (path.extname(bookInfo.cover) == '.png')
|
||||||
|
coverType = 'image/png';
|
||||||
|
|
||||||
|
e.link.push(this.imgLink({href: bookInfo.cover, type: coverType}));
|
||||||
|
e.link.push(this.imgLink({href: bookInfo.cover, type: coverType, thumb: true}));
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.push(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.entry = entry;
|
result.entry = entry;
|
||||||
return this.makeBody(result);
|
return this.makeBody(result, req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class RootPage extends BasePage {
|
|||||||
this.authorPage = new AuthorPage(config);
|
this.authorPage = new AuthorPage(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
async body() {
|
async body(req) {
|
||||||
const result = {};
|
const result = {};
|
||||||
|
|
||||||
if (!this.title) {
|
if (!this.title) {
|
||||||
@@ -26,7 +26,7 @@ class RootPage extends BasePage {
|
|||||||
this.authorPage.myEntry(),
|
this.authorPage.myEntry(),
|
||||||
];
|
];
|
||||||
|
|
||||||
return this.makeBody(result);
|
return this.makeBody(result, req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user