fix(core): update
This commit is contained in:
35
ts/servertools/classes.feed.ts
Normal file
35
ts/servertools/classes.feed.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { Handler } from './classes.handler.js';
|
||||
import { Server } from './classes.server.js';
|
||||
import * as plugins from '../typedserver.plugins.js';
|
||||
|
||||
export class Feed {
|
||||
public smartexpressRef: Server;
|
||||
public smartfeedInstance = new plugins.smartfeed.Smartfeed();
|
||||
|
||||
public feedHandler = new Handler('GET', async (req, res) => {
|
||||
if (!this.smartexpressRef.options.feedMetadata) {
|
||||
res.status(500);
|
||||
res.write('feed metadata is missing');
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
if (!this.smartexpressRef.options.articleGetterFunction) {
|
||||
res.status(500);
|
||||
res.write('no article getter function defined.');
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
const xmlString = await this.smartfeedInstance.createFeedFromArticleArray(
|
||||
this.smartexpressRef.options.feedMetadata,
|
||||
await this.smartexpressRef.options.articleGetterFunction()
|
||||
);
|
||||
res.type('.xml');
|
||||
res.write(xmlString);
|
||||
res.end();
|
||||
});
|
||||
|
||||
constructor(smartexpressRefArg: Server) {
|
||||
this.smartexpressRef = smartexpressRefArg;
|
||||
this.smartexpressRef.addRouteBefore('/feed', this.feedHandler);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user