Commit 412fca03 authored by yPhil's avatar yPhil
Browse files

Server promises

- New, proper feedParser call
- The query string is shorter / lighter
- Small UI thing: Logo click focuses current tab, not first
parent 37ea4b6d
Pipeline #410727 passed with stage
in 36 seconds
......@@ -637,7 +637,7 @@ PTL.dialog = {
.text(PTL.tr('Move focus to the next tab and immediately activate.'))));
$dialog.find('h1').text(PTL.tr('Keyboard shortcuts'))
.next('p#dialogBlurb').text(PTL.tr('A click on the Pétrolette logo puts the focus on the first tab'))
.next('p#dialogBlurb').text(PTL.tr('A click on the Pétrolette logo puts the focus on the current tab'))
.next('h2').text(PTL.tr('When focus is on a tab'))
.next('p')
.append($kbShortCutsTab)
......
......@@ -256,7 +256,7 @@ PTL.feed = {
$feedLink.removeClass('danger');
$.get("/feed", {
feedurl: feedUrl,
url: feedUrl,
dataType: 'json'
}, function() {
......
......@@ -63,8 +63,7 @@ PTL.i18n.translations = {
"Focus first tab" : { fr: "Focus sur le premier onglet", ja: "フォーカスファーストタブ", es: "Foco primera pestaña" },
"A click on the Pétrolette logo puts the focus on the first tab" : { fr: "Un clic sur le logo Pétrolette met le focus sur le premier onglet", ja: "Pétroletteのロゴをクリックすると、最初のタブに焦点を当てます。", es: "Un clic en el logotipo de Pétrolette pone el enfoque en la primera pestaña" },
"A click on the Pétrolette logo puts the focus on the current tab" : { fr: "Un clic sur le logo Pétrolette met l'accent sur l'onglet en cours", ja: "Pétroletteのロゴをクリックすると、現在のタブに焦点が合わせる", es: "Un clic en el logotipo de Pétrolette pone el enfoque en la pestaña actual" },
"Feed name (optional)" : { fr: "Nom du flux (optionnel)", ja: "フロー名(オプション)", es: "Nombre de la fuente (Opcional)" },
......
......@@ -47,8 +47,8 @@ var PTL = (function() {
});
$('#logoTitle > .logoTitle').click(function(){
$('#ui-id-1').focus().trigger('click');
});
$('.ui-state-active a').focus();
});
$logoType.click(function(){
PTL.dialog.about($logoType.attr('data-version'));
......
......@@ -5,16 +5,6 @@ const fetch = require('node-fetch'),
exports.getFeed = getFeed;
function maybeDecompress (res, encoding) {
var decompress;
if (encoding.match(/\bdeflate\b/)) {
decompress = zlib.createInflate();
} else if (encoding.match(/\bgzip\b/)) {
decompress = zlib.createGunzip();
}
return decompress ? res.pipe(decompress) : res;
}
function maybeTranslate (res, charset) {
var iconvStream;
// Decode using iconv-lite if its not utf8 already.
......@@ -44,13 +34,6 @@ function getParams(str) {
return params;
}
function done(err) {
if (err) {
// console.error('err: %s Stack %s', err, err.stack);
return;
}
}
function getFeed (feedUrl, callback) {
// Get a response stream
fetch(feedUrl, {
......@@ -59,36 +42,38 @@ function getFeed (feedUrl, callback) {
redirect: 'follow'
}).then(function (res) {
// Setup feedparser stream
var feedparser = new FeedParser();
var feedItems = [];
feedparser.on('error', function(error) {
console.error('## feedParserErr: %s (%s)', error.message, feedUrl);
return callback({error:error, errno:res.status, message:error.message});
});
feedparser.on('end', done);
feedparser.on('readable', function() {
try {
var item = this.read();
if (item !== null) feedItems.push (item);
}
catch (err) {
console.error('## feedParserCatchErr: %s (%s)', err, feedUrl);
}
}).on ('end', function () {
var meta = this.meta;
return callback (null, feedItems, meta.title || 'Untitled', meta.link || feedUrl);
});
if (res.status != 200) {
return callback({error:'error', errno:res.status, message:'Bad server response'});
}
var feedparser = new FeedParser();
var feedItems = [];
var charset = getParams(res.headers.get('content-type') || '').charset;
var responseStream = res.body;
responseStream = maybeTranslate(responseStream, charset);
responseStream.pipe(feedparser);
return new Promise((resolve, reject) => {
feedparser.on('error', function(error) {
console.error('## feedParserErr: %s (%s)', error.message, feedUrl);
reject();
return callback({error:error, errno:res.status, message:error.message});
}).on('readable', function() {
try {
var item = this.read();
if (item !== null) feedItems.push (item);
}
catch (err) {
console.error('## feedParserCatchErr: %s (%s)', err, feedUrl);
}
}).on ('end', function () {
var meta = this.meta;
resolve();
return callback (null, feedItems, meta.title || 'Untitled', meta.link || feedUrl);
});
});
}).catch((err) => {
return callback({error:err, resStatus:0, message:err.message});
});
......
......@@ -70,7 +70,7 @@ router.use(morgan('combined'));
router.get('/feed', function(req, res) {
feeder.getFeed(req.query.feedurl, function (err, feedItems, feedTitle, feedLink) {
feeder.getFeed(req.query.url, function (err, feedItems, feedTitle, feedLink) {
if (feedItems && !res.headersSent) {
res.send({
......
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