Commit 6cbc0823 authored by yPhil's avatar yPhil
Browse files

Control, I'm here

- Back in business : Most edits backported
- Now onto favicons 404s
parent 1069256e
...@@ -371,8 +371,6 @@ PTL.dialog = { ...@@ -371,8 +371,6 @@ PTL.dialog = {
} }
}); });
console.log('oldNbItems: %s (%s)', oldNbItems);
$feedGuessInput.on('keypress',function(e) { $feedGuessInput.on('keypress',function(e) {
if (e.which == 13) { if (e.which == 13) {
$okButton.click(); $okButton.click();
......
...@@ -409,51 +409,62 @@ PTL.feed = { ...@@ -409,51 +409,62 @@ PTL.feed = {
}, },
errorFeed:function(error, feedUrl) { errorFeed:function(error, feedUrl) {
const type = (error.statusText) ? error.statusText : PTL.tr('Unknown error'); const status = error.status;
const errno = (error.responseJSON) ? error.responseJSON.errno : '0'; const message = error.message;
const message = (error.responseJSON) ? error.responseJSON.message : 'Empty'; const type = error.type;
const $validateLink = $('<a>') const $validateLink = $('<a>')
.attr('href', 'https://validator.w3.org/feed/check.cgi?url=' + feedUrl); .attr('href', 'https://validator.w3.org/feed/check.cgi?url=' + feedUrl);
const $validateLinkIcon = $('<i>')
.attr('class', 'itemIcon icon-w3c')
.attr('title', PTL.tr('Validate /verify this feed file with the W3C'))
.appendTo($validateLink);
const $reportLink = $('<a>') const $reportLink = $('<a>')
.attr('href', 'https://framagit.org/yphil/petrolette/-/issues/new?issue[title]=Feed%20error&issue[description]=' + feedUrl + ' (' + type + ')'); .attr('href', 'https://framagit.org/yphil/petrolette/-/issues/new?issue[title]=Feed%20error&issue[description]=' + feedUrl + ' (' + type + ')');
const $reportLinkIcon = $('<i>')
.attr('class', 'itemIcon icon-petrolette')
.attr('title', PTL.tr('Report feed error'))
.appendTo($reportLink);
const $errKey = $('<strong>') const $errKey = $('<strong>')
.attr('class', 'translate key') .attr('class', 'translate key')
.data('content', PTL.tr('Error:')) .data('content', PTL.tr('Type'))
.text(PTL.tr('Error:')); .text(PTL.tr('Type'));
const $msgKey = $('<strong>') const $msgKey = $('<strong>')
.attr('class', 'translate key') .attr('class', 'translate key')
.data('content', PTL.tr('Message:')) .data('content', PTL.tr('Message'))
.text(PTL.tr('Message:')); .text(PTL.tr('Message'));
const $errValue = $('<strong>') const $errValue = $('<strong>')
.attr('class', 'value') .attr('class', 'value')
.text(type + ' (' + errno + ')'); .text(type + ' (' + status + ')');
const $msgValue = $('<strong>') const $msgValue = $('<strong>')
.attr('class', 'value') .attr('class', 'value')
.text(message); .text(message);
const $errorItem = $('<li>') const $errorItem = $('<li>')
.attr('class', 'feedItem error') .attr('class', 'feedItem error')
.append($validateLink, $reportLink) .append($validateLink)
.append($errKey) .append($reportLink)
.append('&nbsp;') .append($errKey)
.append($errValue) .append('&nbsp;:&nbsp;')
.append('<br>') .append($errValue)
.append($msgKey) .append('<br>')
.append('&nbsp;') .append($msgKey)
.append($msgValue); .append('&nbsp;:&nbsp;')
.append($msgValue);
const $feedBodyUl = $('<ul>').attr('class', 'feedBody') const $feedBodyUl = $('<ul>').attr('class', 'feedBody')
.append($errorItem); .append($errorItem);
return $feedBodyUl; return $feedBodyUl;
}, },
fetchIcon:function(feedHost) { fetchIcon:function(feedHost) {
...@@ -482,13 +493,13 @@ PTL.feed = { ...@@ -482,13 +493,13 @@ PTL.feed = {
dataType: 'json', dataType: 'json',
lastItem: lastItem, lastItem: lastItem,
nbItems: nbItems nbItems: nbItems
}).done(function(data, textStatus, jqXHR) { }).done(function(data, _textStatus, jqXHR) {
resolve(data); resolve(data);
}).fail(function(jqXHR, textStatus, errorThrown) { }).fail(function(jqXHR, textStatus, errorThrown) {
reject(jqXHR); reject(jqXHR, textStatus, errorThrown);
}); });
}); });
}, },
populate:async function($button, progress, newLimit) { populate:async function($button, progress, newLimit) {
...@@ -529,33 +540,40 @@ PTL.feed = { ...@@ -529,33 +540,40 @@ PTL.feed = {
if ($dataStore.data('status') == 'on') { if ($dataStore.data('status') == 'on') {
try { $feedIcon.removeClass('fold');
$refreshButton.addClass('spin');
$feedIcon.removeClass('fold');
$refreshButton.addClass('spin');
let fetchFeed = await PTL.feed.fetchFeed(feedUrl, feedLastItem);
let lastItems = await PTL.feed.lastItems(fetchFeed.feedItems, $dataStore); let fetchFeed = await PTL.feed.fetchFeed(feedUrl, feedLastItem);
$feedBody.html(lastItems[0]); let lastItems = await PTL.feed.lastItems(fetchFeed.feedItems, $dataStore);
$refreshButton.removeClass('spin'); if (fetchFeed.error) {
if (fetchFeed.totalNewItems > 0) { $feedBody
$dataStore.data('lastitem', fetchFeed.lastItem); .empty()
PTL.tab.saveTabs(); .append(PTL.feed.errorFeed(fetchFeed.error, feedUrl))
$badge.text(fetchFeed.totalNewItems).fadeIn('slow'); .css('height', '');
} else { $feedLink.addClass('danger');
$badge.fadeOut('slow'); $refreshButton.removeClass('spin');
}
} else {
} catch (error) {
$feedBody.html(lastItems[0]);
$feedBody.empty().append(PTL.feed.errorFeed(error, feedUrl));
$feedBody.css('height', '');
$refreshButton.removeClass('spin'); $refreshButton.removeClass('spin');
$feedLink
.text(fetchFeed.feedTitle)
.attr('href', fetchFeed.feedLink);
$dataStore.data('name', fetchFeed.feedTitle);
if (fetchFeed.totalNewItems > 0) {
$dataStore.data('lastitem', fetchFeed.lastItem);
PTL.tab.saveTabs();
$badge.text(fetchFeed.totalNewItems).fadeIn('slow');
} else {
$badge.fadeOut('slow');
}
} }
} else { } else {
...@@ -579,7 +597,6 @@ PTL.feed = { ...@@ -579,7 +597,6 @@ PTL.feed = {
PTL.tab.saveTabs(); PTL.tab.saveTabs();
} }
}).catch((_error) => { }).catch((_error) => {
console.log('Fav error: %s (%s)', feedIconHash, feedUrl);
$favIcon.addClass('icon-rss'); $favIcon.addClass('icon-rss');
}); });
} }
......
...@@ -9,7 +9,6 @@ function maybeTranslate(res, charset) { ...@@ -9,7 +9,6 @@ function maybeTranslate(res, charset) {
if (!iconvStream && charset && !/utf-*8/i.test(charset)) { if (!iconvStream && charset && !/utf-*8/i.test(charset)) {
try { try {
iconvStream = iconv.decodeStream(charset); iconvStream = iconv.decodeStream(charset);
console.error('ICONV: Converting from charset %s to utf-8', charset);
iconvStream.on('error', () => { return; }); iconvStream.on('error', () => { return; });
res = res.pipe(iconvStream); res = res.pipe(iconvStream);
} catch (err) { } catch (err) {
...@@ -47,11 +46,8 @@ function getFeed(feedUrl, lastItem, callback) { ...@@ -47,11 +46,8 @@ function getFeed(feedUrl, lastItem, callback) {
'accept': 'text/html,application/xhtml+xml', 'accept': 'text/html,application/xhtml+xml',
redirect: 'follow' redirect: 'follow'
}).then(function(res) { }).then(function(res) {
console.error('res.status: %s (%s)', res.status);
if (res.status != 200) { if (res.status != 200) {
console.error('## statusErr: %s (%s)', res.status, feedUrl);
reject(); reject();
} }
...@@ -98,7 +94,6 @@ function getFeed(feedUrl, lastItem, callback) { ...@@ -98,7 +94,6 @@ function getFeed(feedUrl, lastItem, callback) {
function countItems(item) { function countItems(item) {
i++; i++;
console.error('item: %s (%s)', item.link);
if (newLastItem == undefined) newLastItem = item.link; if (newLastItem == undefined) newLastItem = item.link;
if (item.link == lastItem) totalNewItems = i - 1; if (item.link == lastItem) totalNewItems = i - 1;
} }
......
...@@ -58,13 +58,14 @@ router.get('/favicon', function(req, res) { ...@@ -58,13 +58,14 @@ router.get('/favicon', function(req, res) {
res.body.pipe(dest); res.body.pipe(dest);
res.body.on("end", () => resolve({fileName, url})); res.body.on("end", () => resolve({fileName, url}));
dest.on("error", () => { dest.on("error", () => {
res.status(500).send(false); res.send(false);
reject('No favicon found'); reject('No favicon found');
}); });
}) })
); );
} else { } else {
reject('Not a valid URL');
res.send(false); res.send(false);
} }
}); });
...@@ -76,8 +77,6 @@ router.get('/feed', function(req, res) { ...@@ -76,8 +77,6 @@ router.get('/feed', function(req, res) {
feeder.getFeed(req.query.url, req.query.lastItem, function (error, feedItems, feedTitle, feedLink, lastItem, totalNewItems) { feeder.getFeed(req.query.url, req.query.lastItem, function (error, feedItems, feedTitle, feedLink, lastItem, totalNewItems) {
// console.error('### totalNewItems: [%s] oL:%s, nL:%s', totalNewItems, req.query.lastItem, lastItem);
if (feedItems && !res.headersSent) { if (feedItems && !res.headersSent) {
res.send({ res.send({
feedItems: feedItems, feedItems: feedItems,
...@@ -88,8 +87,9 @@ router.get('/feed', function(req, res) { ...@@ -88,8 +87,9 @@ router.get('/feed', function(req, res) {
}); });
} else if (error && !res.headersSent) { } else if (error && !res.headersSent) {
res.status(500).send(error); res.send({ error: error });
} }
}); });
}); });
...@@ -126,11 +126,14 @@ router.get('/', function(req, res) { ...@@ -126,11 +126,14 @@ router.get('/', function(req, res) {
}); });
router.use(function(req, res) { router.use(function(req, res) {
// res.send('404: Page not Found', 404);
console.error('404 req: %s (%s)', req.url);
res.status(404).send('404: Page not Found'); res.status(404).send('404: Page not Found');
}); });
router.use(function(error, req, res, next) { router.use(function(error, req, res, next) {
console.error('500 req: %s (%s)', req.url);
// res.send('500: Internal Server Error', 500); // res.send('500: Internal Server Error', 500);
res.status(500).send('500: Internal Server Error'); res.status(500).send('500: Internal Server Error');
}); });
......
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