Commit 47923bfb authored by yPhil's avatar yPhil
Browse files

Fetch in favicon calls (#bug previous request legacy call was broken)

parent a56aa10c
This diff is collapsed.
......@@ -41,6 +41,7 @@
"node-fetch": "^2.6.1",
"npm": "^7.5.2",
"pm2": "^4.5.4",
"request": "^2.88.2",
"sanitize": "^2.1.0"
},
"devDependencies": {
......
......@@ -313,22 +313,6 @@ PTL.feed = {
$feedBody.css('height', feedLimit);
$.get("/favicon", {
url: decodeURI(feedHost),
dataType: "json"
}, function() {
// console.log('feedHost: %s (icon %s)', feedHost, icon);
}).done(function(icon) {
$feedToggle.css('background-image','url(' + icon + ')');
$feedIcon.removeClass('icon-rss');
$header.data('img', icon);
}).fail(function() {
$feedIcon.addClass('icon-rss');
$feedToggle.css('background-image', 'none');
});
}
$.each(data.feedItems, function(index, item) {
......@@ -513,10 +497,9 @@ PTL.feed = {
.attr('title', $summary.trim())
.attr('alt', item['mastodon:scope'] ? $summary.trim() : item.title)
.attr('class', 'ptl-img responsively-lazy')
.attr('onerror', "this.style.display='none'")
.appendTo($imageLink);
if (PTL.prefs.readConfig('brokenImages') === 'hide') $image.attr('onerror', "this.style.display='none'");
}
if ($image && feedType == 'photo') $image.addClass('full');
......@@ -555,5 +538,23 @@ PTL.feed = {
if (progress) progress.increment();
}
}
$.get("/favicon", {
url: decodeURI(feedHost),
dataType: "json"
}, function() {
// console.log('feedHost: %s (icon %s)', feedHost, icon);
}).done(function(icon) {
console.log('icon: %s (%s)', icon, feedHost);
$feedToggle.css('background-image','url(' + icon + ')');
$feedIcon.removeClass('icon-rss');
$header.data('img', icon);
}).fail(function() {
$feedIcon.addClass('icon-rss');
$feedToggle.css('background-image', 'none');
});
}
};
......@@ -123,7 +123,7 @@ var PTL = (function() {
}
PTL.sideMenu('close');
PTL.feed.add($column, '', '', 'mixed', 350, 'on', true, false);
PTL.feed.add($column, '', '', 'mixed', 220, 'on', true, false);
});
$feedCodeButton.click(function(event) {
......@@ -222,42 +222,6 @@ var PTL = (function() {
PTL.prefs.writeConfig('theme', $(this).attr('value'));
});
var $brokenImagesBox = $('div#brokenImagesBox'),
$showLabel = $('<label>')
.attr('class', 'translate grow')
.attr('for', 'show')
.data('content', PTL.tr('Show'))
.text(PTL.tr('Show')),
$showInput = $('<input>')
.attr('id', 'show')
.attr('class', 'brokenImagesSwitcher')
.attr('type', 'radio')
.attr('name', 'radio-2')
.attr('value', 'show'),
$hideLabel = $('<label>')
.attr('class', 'translate grow')
.attr('for', 'hide')
.data('content', PTL.tr('Hide'))
.text(PTL.tr('Hide')),
$hideInput = $('<input>')
.attr('id', 'hide')
.attr('class', 'brokenImagesSwitcher')
.attr('type', 'radio')
.attr('name', 'radio-2')
.attr('value', 'hide');
$brokenImagesBox.append($showLabel, $showInput, $hideLabel, $hideInput);
$sideMenu.find('.brokenImagesSwitcher').checkboxradio();
$sideMenu.find("input#" + PTL.prefs.readConfig('brokenImages')).attr("checked", true);
$sideMenu.find('.brokenImagesSwitcher').checkboxradio('refresh');
$('.brokenImagesSwitcher').change(function() {
PTL.prefs.writeConfig('brokenImages', $(this).attr('value'));
});
var $mediaPreloadBox = $('div#mediaPreloadBox'),
$mediaPreloadNoneLabel = $('<label>')
.attr('class', 'translate grow')
......
This diff is collapsed.
......@@ -202,7 +202,7 @@ PTL.util = {
try {
var json = JSON.parse(o);
PTL.util.say(PTL.tr('Valid Pétrolette feeds file'), 'success');
PTL.util.say(PTL.tr('Valid Pétrolette feeds file'), 'success', true);
isJson = true;
json.forEach(function(group) {
......
......@@ -2,6 +2,7 @@ const express = require('express'),
router = express.Router(),
favrat = require('favrat'),
feeder = require('./feeder'),
request = require('request'),
fetch = require('node-fetch'),
feedrat = require('feedrat'),
// feedrat = require(__dirname + '/../../feedrat/'),
......@@ -53,6 +54,8 @@ router.get('/favicon', function(req, res) {
favrat(req.query.url, function(err, url) {
console.error('url: %s (%s)', url);
if (url) {
if (!url.startsWith('http')) url = 'http://' + url.substring(url.indexOf("/") + 1);
......@@ -62,18 +65,25 @@ router.get('/favicon', function(req, res) {
filePath = path.join(pjson.FAVICONS_CACHE_DIR, fileName);
if (fs.existsSync(filePath)) {
console.error('FOUND ICON: %s (%s)', fileName, req.query.url);
res.send('/favicons/' + fileName);
} else {
var p = new Promise(resolve => fetch(url)
.pipe(fs.createWriteStream(filePath, {'Content-Type': 'image/x-icon'}))
.on('finish', resolve({fileName, url})));
p.then(function(r) {
res.send('/favicons/' + r.fileName);
});
fetch(url)
.then(
res =>
new Promise((resolve, reject) => {
const dest = fs.createWriteStream(filePath, {'Content-Type': 'image/x-icon'});
res.body.pipe(dest);
res.body.on("end", () => resolve({fileName, url}));
dest.on("error", reject('No favicon found'));
})
)
.then(x => res.send('/favicons/' + x.fileName));
}
} else {
console.error('NO ICON: %s (%s)', req.query.url);
res.status(500).send('No icon found');
}
});
......
......@@ -302,18 +302,6 @@
</div>
</fieldset>
<legend class="ui-corner-top hover">
<i class="icon-right rotate unfold"></i>
<span class="translate"
data-content="Broken images">Broken images
</span>
</legend>
<fieldset class="menuForm">
<div id="brokenImagesBox"
class="flex-box">
</div>
</fieldset>
<legend class="ui-corner-top hover">
<i class="icon-right rotate unfold"></i>
<span class="translate"
......@@ -326,7 +314,6 @@
</div>
</fieldset>
<legend class="ui-corner-top hover">
<i class="icon-right rotate unfold"></i>
<span class="translate"
......
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