Commit 1e5f4c20 authored by yPhil's avatar yPhil
Browse files

Saved favicon hash / path

- The favicon is now savec with the feed, so it's that many requests the server don't have to handle
- The logger now ignores favicon calls, too
- Some feeds added, others cleaned up (340 total now)
parent 98d979c7
Pipeline #407250 passed with stage
in 1 minute and 40 seconds
{
"name": "petrolette",
"description": "News reading webapp.",
"version": "1.2.6",
"version": "1.2.7",
"private": true,
"license": "GPL-3.0-only",
"FAVICONS_CACHE_DIR": "favicons-cache",
......
......@@ -2,7 +2,7 @@
PTL.feed = {
add:function($column, url, name, type, limit, status, clickNew, isQueryString, progress) {
add:function($column, url, name, type, limit, status, iconhash, clickNew, isQueryString, progress) {
var feedIndex = $('#tabs').find('.feed').length;
......@@ -11,8 +11,8 @@ PTL.feed = {
.data('url', url)
.data('name', name)
.data('type', type)
.data('limit', limit);
.data('limit', limit)
.data('iconhash', iconhash);
const $feedImg = $('<img>')
.attr({
......@@ -94,7 +94,8 @@ PTL.feed = {
.data('name', name)
.data('type', type)
.data('limit', limit)
.data('status', status);
.data('status', status)
.data('iconhash', iconhash);
if ($feedControls.data('status') == 'on') {
$reloadIcon.removeClass('icon-pin')
......@@ -185,6 +186,7 @@ PTL.feed = {
feedType = $dataStore.data('type'),
feedLimit = newLimit || $dataStore.data('limit'),
feedStatus = $dataStore.data('status'),
feedIconHash = $dataStore.data('iconhash'),
$feedToggle = $feed.find('.feed-toggle'),
$feedIcon = $feed.find('.feed-toggle > i.feedIcon'),
$myFeedIcon = $feedToggle.find('.favicon');
......@@ -196,11 +198,6 @@ PTL.feed = {
timeStamp = dateObj.getHours() + ":" + dateObj.getMinutes() + ":" + dateObj.getSeconds(),
subdomain = l.hostname.substr(0, l.hostname.indexOf('.'));
// if (subdomain === 'rss' || subdomain === 'feeds') {
// console.log('wopop!: %s (%s)', subdomain);
// feedHost = l.protocol + '//' + l.hostname.replace(subdomain + '.', '');
// }
$feedIcon.addClass('fold');
$button.removeClass('spin');
......@@ -216,21 +213,37 @@ PTL.feed = {
.attr('href', feedUrl)
.attr('title', feedTitle + ' (' + feedUrl + ')');
$.get("/favicon", {
url: decodeURI(feedHost),
dataType: "json"
}).done(function(icon) {
if (feedIconHash) {
console.log('Found!: %s (%s)', feedIconHash, feedUrl);
$myFeedIcon.attr('src', '/favicons/' + feedIconHash + '.favicon');
} else {
console.log('unFound!: %s (%s)', feedIconHash, feedUrl);
$.get("/favicon", {
url: decodeURI(feedHost),
dataType: "json"
}).done(function(hash) {
if (hash) {
$myFeedIcon.attr('src', '/favicons/' + hash + '.favicon');
$dataStore.data('iconhash', hash);
if (icon) {
$myFeedIcon.attr('src', icon);
} else {
PTL.tab.saveTabs();
console.log('H: %s (%s)', $dataStore.data('iconhash'));
} else {
// $feedIcon.addClass('icon-rss');
}
}).fail(function(jqXHR, textStatus, errorThrown) {
// $feedIcon.addClass('icon-rss');
}
});
}).fail(function(jqXHR, textStatus, errorThrown) {
// console.log('ERROR: %s (%s) [%s]', feedUrl, textStatus, errorThrown);
// $feedIcon.addClass('icon-rss');
});
}
if ($dataStore.data('status') == 'on') {
......
......@@ -80,6 +80,8 @@ PTL.tab = {
},
populate:function(feeds) {
console.log('FEEDS: %s (%s)', JSON.stringify(feeds));
if (!feeds || feeds.length <= 0) {
PTL.util.say(PTL.tr('No feeds found'), 'warning');
feeds = ['empty'];
......@@ -121,12 +123,14 @@ PTL.tab = {
thisFeed.type = v.type;
thisFeed.limit = v.limit;
thisFeed.status = v.status;
thisFeed.iconhash = v.iconhash;
thisColFeeds.push(thisFeed);
allFeeds.push(thisColFeeds);
});
thisTabCols.push(thisColFeeds);
// console.log('thisColFeeds: %s (%s)', JSON.stringify(thisColFeeds));
});
PTL.tab.add($('#tabs'), thisGroup.name, thisTabCols, progress);
});
......@@ -232,7 +236,8 @@ PTL.tab = {
feeds.forEach(function(feed) {
var type = PTL.feedTypes.includes(feed.type) ? feed.type : 'mixed',
limit = Number.isInteger(feed.limit) ? feed.limit : 260;
PTL.feed.add($column, feed.url, feed.name, type, limit, feed.status, false, false, progress);
// console.log('feeed: %s (%s)', JSON.stringify(feed));
PTL.feed.add($column, feed.url, feed.name, type, limit, feed.status, feed.iconhash, false, false, progress);
});
}
......@@ -276,6 +281,7 @@ PTL.tab = {
feed.type = $dataStore.data('type');
feed.limit = $dataStore.data('limit');
feed.status = $dataStore.data('status');
feed.iconhash = $dataStore.data('iconhash');
column.push(feed);
......
......@@ -32,25 +32,6 @@ var options = {
router.use(sanitize);
router.get('/feed', function(req, res) {
feeder.getFeed(req.query.feedurl, function (err, feedItems, feedTitle, feedLink) {
if (feedItems && !res.headersSent) {
res.send({
feedItems: feedItems,
feedLink: feedLink,
feedTitle: feedTitle
});
} else if (!res.headersSent) {
res.send({error:err, errno:err.errno, message:err.message});
}
});
});
router.use(morgan('combined'));
router.get('/favicon', function(req, res) {
favrat(req.query.url, function(err, url) {
......@@ -63,7 +44,7 @@ router.get('/favicon', function(req, res) {
fileName = hash + '.favicon',
filePath = path.join(pjson.FAVICONS_CACHE_DIR, fileName);
res.send('/favicons/' + fileName);
res.send(hash);
fetch(url)
.then(
......@@ -85,6 +66,25 @@ router.get('/favicon', function(req, res) {
});
});
router.use(morgan('combined'));
router.get('/feed', function(req, res) {
feeder.getFeed(req.query.feedurl, function (err, feedItems, feedTitle, feedLink) {
if (feedItems && !res.headersSent) {
res.send({
feedItems: feedItems,
feedLink: feedLink,
feedTitle: feedTitle
});
} else if (!res.headersSent) {
res.send({error:err, errno:err.errno, message:err.message});
}
});
});
router.get('/robots.txt', function (req, res) {
res.type('text/plain');
res.send("User-agent: *\nDisallow: /feed\nDisallow: /discover\nDisallow: /favicon");
......
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