Работа над opds
This commit is contained in:
@@ -1,21 +1,55 @@
|
|||||||
|
const WebWorker = require('../WebWorker');//singleton
|
||||||
const XmlParser = require('../xml/XmlParser');
|
const XmlParser = require('../xml/XmlParser');
|
||||||
|
|
||||||
class BasePage {
|
class BasePage {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
|
this.webWorker = new WebWorker(config);
|
||||||
this.rootTag = 'feed';
|
this.rootTag = 'feed';
|
||||||
|
this.opdsRoot = '/opds';
|
||||||
|
}
|
||||||
|
|
||||||
|
makeEntry(entry = {}) {
|
||||||
|
if (!entry.id)
|
||||||
|
throw new Error('makeEntry: no id');
|
||||||
|
if (!entry.title)
|
||||||
|
throw new Error('makeEntry: no title');
|
||||||
|
|
||||||
|
const result = {
|
||||||
|
updated: (new Date()).toISOString().substring(0, 19) + 'Z',
|
||||||
|
};
|
||||||
|
|
||||||
|
return Object.assign(result, entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
makeLink(attrs) {
|
||||||
|
return {'*ATTRS': attrs};
|
||||||
|
}
|
||||||
|
|
||||||
|
navLink(attrs) {
|
||||||
|
return this.makeLink({
|
||||||
|
href: this.opdsRoot + (attrs.href || ''),
|
||||||
|
rel: attrs.rel || '',
|
||||||
|
type: 'application/atom+xml; profile=opds-catalog; kind=navigation',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
makeBody(content) {
|
makeBody(content) {
|
||||||
if (!this.id)
|
const base = this.makeEntry({id: this.id, title: this.title});
|
||||||
throw new Error('makeBody: no id');
|
base['*ATTRS'] = {
|
||||||
|
'xmlns': 'http://www.w3.org/2005/Atom',
|
||||||
|
'xmlns:dc': 'http://purl.org/dc/terms/',
|
||||||
|
'xmlns:opds': 'http://opds-spec.org/2010/catalog',
|
||||||
|
};
|
||||||
|
|
||||||
content.id = this.id;
|
base.link = [
|
||||||
|
this.navLink({rel: 'start'}),
|
||||||
|
];
|
||||||
|
|
||||||
const xml = new XmlParser();
|
const xml = new XmlParser();
|
||||||
const xmlObject = {};
|
const xmlObject = {};
|
||||||
xmlObject[this.rootTag] = content;
|
xmlObject[this.rootTag] = Object.assign(base, content);
|
||||||
|
|
||||||
xml.fromObject(xmlObject);
|
xml.fromObject(xmlObject);
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,34 @@ class RootPage extends BasePage {
|
|||||||
super(config);
|
super(config);
|
||||||
|
|
||||||
this.id = 'root';
|
this.id = 'root';
|
||||||
|
this.title = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
async body() {
|
async body() {
|
||||||
const result = {};
|
const result = {};
|
||||||
|
const ww = this.webWorker;
|
||||||
|
|
||||||
|
if (!this.title) {
|
||||||
|
const dbConfig = await ww.dbConfig();
|
||||||
|
const collection = dbConfig.inpxInfo.collection.split('\n');
|
||||||
|
this.title = collection[0].trim();
|
||||||
|
if (!this.title)
|
||||||
|
this.title = 'Неизвестная коллекция';
|
||||||
|
}
|
||||||
|
|
||||||
|
result.link = [
|
||||||
|
this.navLink({rel: 'start'}),
|
||||||
|
this.navLink({rel: 'self'}),
|
||||||
|
];
|
||||||
|
|
||||||
|
result.entry = [
|
||||||
|
this.makeEntry({
|
||||||
|
id: 'author',
|
||||||
|
title: 'Авторы',
|
||||||
|
link: this.navLink({rel: 'subsection', href: '/author'}),
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
return this.makeBody(result);
|
return this.makeBody(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ const express = require('express');
|
|||||||
const http = require('http');
|
const http = require('http');
|
||||||
const WebSocket = require ('ws');
|
const WebSocket = require ('ws');
|
||||||
|
|
||||||
const opds = require('./core/opds');
|
|
||||||
const utils = require('./core/utils');
|
const utils = require('./core/utils');
|
||||||
|
|
||||||
const ayncExit = new (require('./core/AsyncExit'))();
|
const ayncExit = new (require('./core/AsyncExit'))();
|
||||||
@@ -155,6 +154,7 @@ async function main() {
|
|||||||
if (devModule)
|
if (devModule)
|
||||||
devModule.logQueries(app);
|
devModule.logQueries(app);
|
||||||
|
|
||||||
|
const opds = require('./core/opds');
|
||||||
opds(app, config);
|
opds(app, config);
|
||||||
initStatic(app, config);
|
initStatic(app, config);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user