pull RSS through file proxy

pull/749/head
Ryan Tharp 5 years ago
parent b2173ecd97
commit 8fc5b6769a

@ -3,7 +3,6 @@
/* global log, window, textsecure */ /* global log, window, textsecure */
const EventEmitter = require('events'); const EventEmitter = require('events');
const nodeFetch = require('node-fetch');
const PER_MIN = 60 * 1000; const PER_MIN = 60 * 1000;
const PER_HR = 60 * PER_MIN; const PER_HR = 60 * PER_MIN;
@ -54,17 +53,24 @@ class LokiRssAPI extends EventEmitter {
} }
async getFeed() { async getFeed() {
let response; // deal with file server proxy hardcoding
try { const map = {
response = await nodeFetch(this.feedUrl); 'https://loki.network/category/messenger-updates/feed/':
} catch (e) { 'loki/v1/rss/messenger',
log.error('fetcherror', e); 'https://loki.network/feed/': 'loki/v1/rss/loki',
};
if (map[this.feedUrl] === undefined) {
log.warn('LokiRssAPI unsupported rss feed', this.feedUrl);
return; return;
} }
const response = await window.lokiFileServerAPI._server.serverRequest(
map[this.feedUrl]
);
if (!response) { if (!response) {
log.error('LokiRssAPI empty rss proxy response');
return; return;
} }
const responseXML = await response.text(); const responseXML = response.response.data;
let feedDOM = {}; let feedDOM = {};
try { try {
feedDOM = await new window.DOMParser().parseFromString( feedDOM = await new window.DOMParser().parseFromString(
@ -72,18 +78,23 @@ class LokiRssAPI extends EventEmitter {
'text/xml' 'text/xml'
); );
} catch (e) { } catch (e) {
log.error('xmlerror', e); log.error('LokiRssAPI xml parsing error', e, responseXML);
return; return;
} }
const feedObj = xml2json(feedDOM); const feedObj = xml2json(feedDOM);
let receivedAt = new Date().getTime(); let receivedAt = new Date().getTime();
if (!feedObj || !feedObj.rss || !feedObj.rss.channel) { if (!feedObj || !feedObj.rss || !feedObj.rss.channel) {
log.error('rsserror', feedObj, feedDOM, responseXML); log.error(
'LokiRssAPI rss structure error',
feedObj,
feedDOM,
responseXML
);
return; return;
} }
if (!feedObj.rss.channel.item) { if (!feedObj.rss.channel.item) {
// no records // no records, not an error
return; return;
} }
if (feedObj.rss.channel.item.constructor !== Array) { if (feedObj.rss.channel.item.constructor !== Array) {

Loading…
Cancel
Save