Commit bcc3f17e authored by yPhil's avatar yPhil
Browse files

So I guess we're always getting the first item first (not the last) :(

- Switching back to feedParser to check just that
parent 073aa1b9
......@@ -17,6 +17,7 @@ fs.mkdir(path.join(__dirname, pjson.FAVICONS_CACHE_DIR), (err) => {
return console.error(err);
}
console.log('Directory created successfully!');
return true;
});
fs.mkdir(path.join(__dirname, pjson.FAVICONS_CACHE_DIR),
......
......@@ -243,15 +243,15 @@ PTL.feed = {
// console.log('YAAZ item:[%s], data[item]:[%s]', key, JSON.stringify(data.feedItems[key]));
var item = data.feedItems[key];
console.log('newItems: %s (%s)', newItems, JSON.stringify(item));
// console.log('newItems: %s (%s)', newItems, JSON.stringify(item));
if (item.enclosure && item.enclosure.url) {
console.log('item.enclosure.url: %s (%s)', item.enclosure.url);
}
// if (item.enclosure && item.enclosure.url) {
// console.log('item.enclosure.url: %s (%s)', item.enclosure.url);
// }
if (item.enclosure && item.enclosure.type) {
console.log('item.enclosure.type: %s (%s)', item.enclosure.type);
}
// if (item.enclosure && item.enclosure.type) {
// console.log('item.enclosure.type: %s (%s)', item.enclosure.type);
// }
const $description = $.parseHTML(item.description),
imgTypes = ['image',
......@@ -303,7 +303,7 @@ PTL.feed = {
if (item['content:encoded']) {
const $tempItem = $('<null>').append(item['content:encoded']);
console.log('yep!: %s (%s)', $tempItem.find('img').attr('src'));
// console.log('yep!: %s (%s)', $tempItem.find('img').attr('src'));
if ($tempItem.find('img').attr('src')) {
imageUrl = $tempItem.find('img').attr('src');
......@@ -336,14 +336,14 @@ PTL.feed = {
}
if (item.enclosure && item.enclosure.type && item.enclosure.url) {
console.log('item.enclosure.type: %s (%s)', item.enclosure.type);
// console.log('item.enclosure.type: %s (%s)', item.enclosure.type);
if (videoTypes.indexOf(item.enclosure.type) > -1) {
PTL.feed.appendVideoPlayer($itemDiv, item.enclosure.url, item.enclosure.type);
}
if (audioTypes.indexOf(item.enclosure.type) > -1) {
console.log('yoooo: %s (%s)');
// console.log('yoooo: %s (%s)');
PTL.feed.appendAudioPlayer($itemDiv, item.enclosure.url, item.enclosure.type);
}
......@@ -588,7 +588,7 @@ PTL.feed = {
feedStatus = $dataStore.data('status'),
feedIconHash = $dataStore.data('iconhash'),
feedNbItems = $dataStore.data('nbitems'),
feedLastItem = $dataStore.attr('data-lastitem'),
feedLastItem = $dataStore.attr('data-lastitem') || '',
$feedToggle = $feedHeader.children('.feedToggle'),
$feedIcon = $feedToggle.children('.feedIcon').addClass('fold'),
$favIcon = $feedToggle.children('.favicon');
......
let Parser = require('rss-parser');
let parser = new Parser();
let parser = new Parser({
// timeout: 5000,
headers: {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36',
'accept': 'text/html,application/xhtml+xml'
},
maxRedirects: 100,
requestOptions: {
rejectUnauthorized: false
},
defaultRSS: 2.0,
xml2js: {
emptyTag: 'media:community',
},
customFields: {
item: [
['media:community', 'media:content', {keepArray: true}],
]
}
});
exports.getFeed = getFeed;
function getFeed (feedUrl, lastItem, maxItems, callback) {
const CORS_PROXY = 'https://cors-anywhere.herokuapp.com/';
(async () => {
var feedItems = [];
var reached = false;
var newItems = 0;
let feed = await parser.parseURL(feedUrl);
var newLastItem;
parser.parseURL(feedUrl).then((feed) => {
var newLastItem;
console.log(feed.title);
console.log(feed.title);
feed.items.every(function(item, index) {
console.log(item.title);
feed.items.every(function(item, index) {
console.log(item.title);
feedItems.push(item);
feedItems.push(item);
if (typeof newLastItem === 'undefined') {
newLastItem = item.link;
}
if (item.link === lastItem) return false;
else return true;
console.error('item.link: %s (%s)',item.link);
});
newItems = index;
if (item.link === lastItem) {
reached = true;
return false;
}
return true;
callback (null, feedItems, feed.title || 'Untitled', feed.link || feedUrl, newLastItem);
});
console.error('### FEEDER: lastItem [%s] newLastItem [%s] newItems [%s] reached: [%s]', lastItem, newLastItem, newItems, reached);
callback (null, feedItems, feed.title || 'Untitled', feed.link || feedUrl, newLastItem);
}).catch((e) => {
console.error('Catched Error: %s (%s)', e);
callback (e);
});
})();
......
......@@ -12,23 +12,21 @@ const express = require('express'),
sanitize = require('sanitize').middleware,
morgan = require('morgan');
require('events').EventEmitter.defaultMaxListeners = 15;
console.error('####### Pétrolette (re)START ## Version (%s)', pjson.version);
process.on('uncaughtException', function(err) {
console.error('### Pétrolette uncaughtException: %s', err);
});
var options = {
object: false,
reversible: false,
coerce: true,
sanitize: false,
trim: false,
arrayNotation: false,
alternateTextNode: false
};
// var options = {
// object: false,
// reversible: false,
// coerce: true,
// sanitize: false,
// trim: false,
// arrayNotation: false,
// alternateTextNode: false
// };
router.use(sanitize);
......@@ -76,6 +74,8 @@ router.get('/feed', function(req, res) {
feeder.getFeed(req.query.url, req.query.lastItem, req.query.nbItems, function (error, feedItems, feedTitle, feedLink, lastItem) {
console.error('### ROUTER: lastItem [%s]', lastItem);
if (feedItems && !res.headersSent) {
res.send({
feedItems: feedItems,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment