BookPage.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const path = require('path');
  2. const BasePage = require('./BasePage');
  3. class BookPage extends BasePage {
  4. constructor(config) {
  5. super(config);
  6. this.id = 'book';
  7. this.title = 'Книга';
  8. }
  9. async body(req) {
  10. const result = {};
  11. const bookUid = req.query.uid;
  12. const entry = [];
  13. if (bookUid) {
  14. const {bookInfo} = await this.webWorker.getBookInfo(bookUid);
  15. if (bookInfo) {
  16. const e = this.makeEntry({
  17. id: bookUid,
  18. title: bookInfo.book.title || 'Без названия',
  19. link: [
  20. this.downLink({href: bookInfo.link, type: `application/${bookInfo.book.ext}+zip`}),
  21. ],
  22. });
  23. if (bookInfo.cover) {
  24. let coverType = 'image/jpeg';
  25. if (path.extname(bookInfo.cover) == '.png')
  26. coverType = 'image/png';
  27. e.link.push(this.imgLink({href: bookInfo.cover, type: coverType}));
  28. e.link.push(this.imgLink({href: bookInfo.cover, type: coverType, thumb: true}));
  29. }
  30. entry.push(e);
  31. }
  32. }
  33. result.entry = entry;
  34. return this.makeBody(result, req);
  35. }
  36. }
  37. module.exports = BookPage;