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