Commit f57e1d92 authored by yPhil's avatar yPhil
Browse files

Untested commit before backporting

- First, PTL.feed.image()
- Then, PTL.feed.build()
- Then, port back this branch edits
parent aee9bbdd
Pipeline #411539 passed with stage
in 51 seconds
This diff is collapsed.
......@@ -125,7 +125,7 @@ var PTL = (function() {
}
PTL.sideMenu('close');
PTL.feed.add($column, '', '', 'mixed', 220, 'on', '', true, false);
PTL.feed.add($column, '', '', 'mixed', 220, 'on', '', '', 30, true, false);
});
$feedCodeButton.click(function(event) {
......
......@@ -124,6 +124,7 @@ PTL.tab = {
thisFeed.limit = v.limit;
thisFeed.status = v.status;
thisFeed.iconhash = v.iconhash;
thisFeed.nbitems = v.nbitems;
thisColFeeds.push(thisFeed);
allFeeds.push(thisColFeeds);
......@@ -227,15 +228,16 @@ PTL.tab = {
$column.appendTo($tabPanel);
if (PTL.queryString) {
PTL.feed.add($column, encodeURI(PTL.queryString), '', 'mixed', 260, 'on', "", true, true);
PTL.feed.add($column, encodeURI(PTL.queryString), '', 'mixed', 260, 'on', '', '', 30, true, true);
PTL.queryString = null;
}
if (!newTab) {
feeds.forEach(function(feed) {
const type = PTL.feedTypes.includes(feed.type) ? feed.type : 'mixed',
nbitems = Number.isInteger(feed.nbitems) ? feed.nbitems : 30,
limit = Number.isInteger(feed.limit) ? feed.limit : 260;
PTL.feed.add($column, feed.url, feed.name, type, limit, feed.status, feed.iconhash, false, false, progress);
PTL.feed.add($column, feed.url, feed.name, type, limit, feed.status, feed.iconhash, feed.nbitems, feed.lastitem, false, false, progress);
});
}
......@@ -280,6 +282,9 @@ PTL.tab = {
feed.limit = $dataStore.data('limit');
feed.status = $dataStore.data('status');
feed.iconhash = $dataStore.data('iconhash');
feed.feedhash = $dataStore.data('feedhash');
feed.nbitems = $dataStore.data('nbitems');
feed.lastitem = $dataStore.data('lastitem');
column.push(feed);
......
......@@ -11,8 +11,8 @@ function maybeTranslate (res, charset) {
if (!iconvStream && charset && !/utf-*8/i.test(charset)) {
try {
iconvStream = iconv.decodeStream(charset);
console.log('Converting from charset %s to utf-8', charset);
iconvStream.on('error', done);
console.error('ICONV: Converting from charset %s to utf-8', charset);
iconvStream.on('error', () => {return;});
// If we're using iconvStream, stream will be the output of iconvStream
// otherwise it will remain the output of request
res = res.pipe(iconvStream);
......@@ -34,7 +34,7 @@ function getParams(str) {
return params;
}
function getFeed (feedUrl, callback) {
function getFeed (feedUrl, count, callback) {
// Get a response stream
fetch(feedUrl, {
'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',
......@@ -53,6 +53,9 @@ function getFeed (feedUrl, callback) {
var responseStream = res.body;
responseStream = maybeTranslate(responseStream, charset);
responseStream.pipe(feedparser);
var lastGuid;
var i = 0;
return new Promise((resolve, reject) => {
feedparser.on('error', function(error) {
......@@ -62,7 +65,31 @@ function getFeed (feedUrl, callback) {
}).on('readable', function() {
try {
var item = this.read();
if (item !== null) feedItems.push (item);
if (item !== null && item.guid) {
console.error('### ITEM: %s (%s)', item.guid || 'NOTHING', feedUrl);
} else {
console.error('### NOPE: (%s)', feedUrl);
}
if (item !== null){
i++;
if (typeof lastGuid === 'undefined') {
lastGuid = item.guid;
}
if (i < count) {
console.error('### PUSHING: #%s GUID: %s (count is %s)', i, item.guid || 'No guid', count);
feedItems.push(item);
} else {
console.error('### Count reached i:%s, count:%s, LAST: [%s]', i, count, lastGuid);
this.resume();
}
} else {
console.error('### NULL: (%s)', feedUrl);
}
}
catch (err) {
console.error('## feedParserCatchErr: %s (%s)', err, feedUrl);
......@@ -70,9 +97,8 @@ function getFeed (feedUrl, callback) {
}).on ('end', function () {
var meta = this.meta;
resolve();
return callback (null, feedItems, meta.title || 'Untitled', meta.link || feedUrl);
return callback (null, feedItems, meta.title || 'Untitled', meta.link || feedUrl, lastGuid);
});
});
}).catch((err) => {
......
......@@ -70,13 +70,14 @@ router.use(morgan('combined'));
router.get('/feed', function(req, res) {
feeder.getFeed(req.query.url, function (err, feedItems, feedTitle, feedLink) {
feeder.getFeed(req.query.url, req.query.count, function (err, feedItems, feedTitle, feedLink, lastGuid) {
if (feedItems && !res.headersSent) {
res.send({
feedItems: feedItems,
feedLink: feedLink,
feedTitle: feedTitle
feedTitle: feedTitle,
lastGuid: lastGuid
});
} else if (!res.headersSent) {
......
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