Commit b02906a0 authored by yPhil's avatar yPhil

Rss: Refactoring: Feed title OK

parent 82dc0328
......@@ -55,6 +55,11 @@
"acorn": "2.7.0"
}
},
"addressparser": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/addressparser/-/addressparser-1.0.1.tgz",
"integrity": "sha1-R6++GiqSYhkdtoOOT9HTm0CCF0Y="
},
"ajv": {
"version": "5.2.3",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-5.2.3.tgz",
......@@ -96,6 +101,11 @@
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
},
"array-indexofobject": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/array-indexofobject/-/array-indexofobject-0.0.1.tgz",
"integrity": "sha1-qqEo5iybPDWAlFaMIZ/2T+SJ1Co="
},
"asn1": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz",
......@@ -678,6 +688,50 @@
"request": "2.83.0"
}
},
"feedparser": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/feedparser/-/feedparser-2.2.2.tgz",
"integrity": "sha1-/pjoB35nRnN88acO2jx3htj2tl0=",
"requires": {
"addressparser": "1.0.1",
"array-indexofobject": "0.0.1",
"lodash.assign": "4.2.0",
"lodash.get": "4.4.2",
"lodash.has": "4.5.2",
"lodash.uniq": "4.5.0",
"readable-stream": "2.3.3",
"sax": "1.2.4"
},
"dependencies": {
"isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
},
"readable-stream": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz",
"integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==",
"requires": {
"core-util-is": "1.0.2",
"inherits": "2.0.3",
"isarray": "1.0.0",
"process-nextick-args": "1.0.7",
"safe-buffer": "5.1.1",
"string_decoder": "1.0.3",
"util-deprecate": "1.0.2"
}
},
"string_decoder": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
"requires": {
"safe-buffer": "5.1.1"
}
}
}
},
"fetch-favicon": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/fetch-favicon/-/fetch-favicon-0.0.2.tgz",
......@@ -1086,6 +1140,26 @@
"resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz",
"integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4="
},
"lodash.assign": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz",
"integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc="
},
"lodash.get": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
},
"lodash.has": {
"version": "4.5.2",
"resolved": "https://registry.npmjs.org/lodash.has/-/lodash.has-4.5.2.tgz",
"integrity": "sha1-0Z9NwQlQWMzL4rDN9O4P5Ko3yGI="
},
"lodash.uniq": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz",
"integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M="
},
"longest": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz",
......@@ -1255,6 +1329,11 @@
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz",
"integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ="
},
"process-nextick-args": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
"integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M="
},
"proxy-addr": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.1.5.tgz",
......@@ -1354,15 +1433,6 @@
"align-text": "0.1.4"
}
},
"rss-parser": {
"version": "2.10.6",
"resolved": "https://registry.npmjs.org/rss-parser/-/rss-parser-2.10.6.tgz",
"integrity": "sha1-S8UkF6k+UvyKcBolJW1gbyor3Kk=",
"requires": {
"entities": "1.1.1",
"xml2js": "0.4.19"
}
},
"safe-buffer": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
......@@ -1663,6 +1733,11 @@
}
}
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
},
"utils-merge": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.0.tgz",
......@@ -1931,20 +2006,6 @@
"integrity": "sha1-TYuPHszTQZqjYgYb7O9RXh5VljU=",
"optional": true
},
"xml2js": {
"version": "0.4.19",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz",
"integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==",
"requires": {
"sax": "1.2.4",
"xmlbuilder": "9.0.4"
}
},
"xmlbuilder": {
"version": "9.0.4",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.4.tgz",
"integrity": "sha1-UZy0ymhtAFqEINNJbz8MruzKWA8="
},
"xregexp": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/xregexp/-/xregexp-2.0.0.tgz",
......
......@@ -52,7 +52,6 @@ $('#feedDialog').dialog({
$tabFeedId.data('type', $(this).attr('id'))
});
Feed.populateFeed($mobFeedRefresh);
Tab.saveTabs();
$(this).dialog( 'close' );
......@@ -60,32 +59,7 @@ $('#feedDialog').dialog({
},
open: function( event, ui ) {
console.log('Elt: ' + $(this).attr('id'))
// $('input#feedUrl').select()
$('input#feedUrl').val($(this).data('feedUrl'));
// $('input#feedLimit').val(feedLimit);
// $('input#feedLimit').val($(this).data('feedLimit'));
console.log('L: (' + $(this).data('feedLimit') + ')')
// $('div#feedLimitSlider').slider({
// value: 0,
// min: 1,
// max: 128,
// step: 1,
// slide: function( event, ui ) {
// console.log('Val: ' + ui.value)
// // $('input#feedLimitSlider').val(ui.value + ' items');
// },
// change: function( event, ui ) {
// console.log('Val: ' + ui.value)
// }
// });
// $('input#feedLimitSlider').val($(this).data('feedLimit'));
$('.feedType #' + $(this).data('feedType')).prop('checked',true).change();
$(this).on('submit', function () {
......@@ -95,7 +69,6 @@ $('#feedDialog').dialog({
$(this).dialog('close');
return false;
});
}
});
......
......@@ -23,12 +23,13 @@ var Feed = (function() {
$feedDelete.click(function() {
var $thisFeedId = $(this).parent().parent().parent().parent().attr('id')
var thisFeedName = $(this).parent().parent().prev().text()
$('#mobDialogs').load('/static/templates/dialog.html', function() {
var $killFeedDialog = $(this).children('#dialog')
$killFeedDialog.dialog({
title: 'Kill the feed?',
title: 'Kill the [' + thisFeedName + '] feed?',
autoOpen: false,
resizable: false,
height: "auto",
......@@ -181,111 +182,44 @@ var Feed = (function() {
var cleanUrl = feedUrl.substring(0, feedUrl.lastIndexOf("/") + 1);
// console.log('## Sending: ' + decodeURI(cleanUrl))
$.get("/feedicon", {
url: decodeURI(feedHost),
dataType: "json",
timeout: 3000
}, function(icon, status) {
if ( !icon || icon.length === 0) icon = "/static/images/generic-rss-32.png";
// $feedIcon.removeClass('icon-down-dir')
// .css('background-image','url(' + icon + ')')
// console.log('U: ' + decodeURI(cleanUrl) + ' I: (' + icon + ')' + 'S: ' + status)
})
// var jqxhr = $.get( "/feedicon", {
// url: decodeURI(feedHost),
// dataType: "json",
// timeout: 3000
// }, function() {
// console.log( "success" );
// })
// .done(function() {
// console.log( "second success" );
// })
// .fail(function() {
// console.log( "error" );
// })
// .always(function() {
// console.log( "finished" );
// });
$.get("/feed", {
feedurl: feedUrl
//
// $.get("/feedicon", {
// url: decodeURI(feedHost),
// dataType: "json",
// timeout: 3000
// }, function(icon, status) {
// if ( !icon || icon.length === 0) icon = "/static/images/generic-rss-32.png";
// })
//
var jqxhr = $.get("/feed", {
feedurl: feedUrl,
dataType: 'json'
}, function(data, status) {
$button.css("color", "#3e3e3e").removeClass('spinner');
$feedBody.empty()
}).done(function(data, title) {
var jdata = $.parseJSON(data)
console.log( "second success: Loaded (%s)", jdata);
if (typeof data.entries !== 'undefined') {
$feedTitle.text(data.title);
data.entries.slice(0, parseInt(feedLimit)).forEach(function(entry) {
if($.type(entry.title) === 'string') {
// console.log('ALL: ' + JSON.stringify(entry))
var content = $.parseHTML(entry.content)
var $entry = $(entry)
// console.log('Enclosure: ' + $entry.find("enclosure").attr('url'))
var $tempDom = $('<output>').append(content);
var $feedItem = $('<li class="feedItem">')
.hover(
function() {
$( this ).addClass('ui-state-active')
// console.log('Elt: ' + LightenColor())
// $( this ).append( $( "<span> ***</span>" ) );
}, function() {
// $( this ).find( "span:last" ).remove();
$( this ).removeClass('ui-state-active')
}
);
var $itemDiv = $('<div class="feedItem">')
var $itemLink = $('<a class="ui-helper-clearfix">').attr('href', entry.link).append(entry.title)
var $hostName = $itemLink.prop('hostname')
var $protocol = $itemLink.prop('protocol')
// console.log('P: ' + $protocol)
$.each(jdata, function(index, element) {
if (typeof $tempDom.find('img').attr('src') !== 'undefined') {
console.log( "Elt: (%s)", element.title);
var $imgUrl = $tempDom.find('img').attr('src')
// $('body').append($('<div>', {
// text: element.name
// }));
if (!r.test($imgUrl))
$imgUrl = $protocol + '' + $hostName + $imgUrl
var $imgLink = $('<a data-fancybox="gallery">').attr('href', $imgUrl)
// console.log('S: ' + $imgUrl)
var $itemImg = $('<img src="' + $imgUrl + '" />')
.appendTo($imgLink)
if (feedType == 'photo')
$itemImg.addClass('full')
if (feedType !== 'text')
$imgLink.appendTo($itemDiv)
}
});
$itemLink.appendTo($itemDiv)
$itemDiv.appendTo($feedItem)
$feedItem.appendTo($feedBody)
}
})
} else {
$feed.children('.mobHeader').addClass('ui-state-error');
$feedTitle.text('Error');
$feedBody.html('<li class="feedItem">Feed Error: ' + feedUrl + '</li>');
}
});
}).fail(function() {
console.log( "error" );
}).always(function() {
console.log( "finished" );
});;
}
};
}());
var express = require('express');
var router = express.Router();
var favicon = require('favicon');
var parser = require('rss-parser');
// var parser = require('rss-parser');
const fileUpload = require('express-fileupload');
// Exp
var FeedParser = require('feedparser');
var request = require('request'); // for fetching the feed
// End exp
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
......@@ -14,6 +21,61 @@ router.use(fileUpload({
preserveExtension: true
}));
function getFeed (urlfeed, callback) {
var req = request (urlfeed);
var feedparser = new FeedParser ();
var feedItems = new Array ();
req.on ("response", function (res) {
var stream = this;
if (res.statusCode == 200) {
stream.pipe (feedparser);
}
});
req.on ("error", function (res) {
console.log ("getFeed: Error reading feed.");
});
feedparser.on ("readable", function () {
try {
var item = this.read (), flnew;
if (item !== null) { //2/9/17 by DW
feedItems.push (item);
}
}
catch (err) {
console.log ("getFeed: err.message == " + err.message);
}
}).on ("end", function () {
var meta = this.meta;
callback (undefined, feedItems, meta.title);
}).on ("error", function (err) {
console.log ("getFeed: Error reading feed.");
callback (err);
});
}
router.get('/feed', function(req, res, next) {
getFeed(req.query.feedurl, function (err, feedItems, feedTitle) {
if (!err) {
function pad (num) {
var s = num.toString (), ctplaces = 3;
while (s.length < ctplaces) {
s = "0" + s;
}
return (s);
}
console.log ("\n\nThere are " + feedTitle + " items in the feed.\n");
for (var i = 0; i < feedItems.length; i++) {
// console.log ("Item #" + pad (i) + ": " + feedItems[i].title + ".\n");
// console.log('ALL: ' + JSON.stringify(feedItems[i]))
}
res.send(feedTitle, feedItems);
}
});
});
router.get('/feedicon', function(req, res, next) {
favicon(req.query.url, function(err, u) {
......@@ -32,21 +94,6 @@ router.get('/feedicon', function(req, res, next) {
});
});
router.get('/feed', function(req, res, next) {
parser.parseURL(req.query.feedurl, function(err, parsed) {
if(err !== null) {
console.log('## Feed ERROR: ' + err + ' (' + req.query.feedurl + ')');
res.send(err.code);
}
if(typeof parsed != 'undefined') {
res.send(parsed.feed);
}
});
});
router.post('/upload', function(req, res) {
if (!req.files)
return res.status(400).send('No files were uploaded.');
......
......@@ -156,9 +156,6 @@
}
});
// $killTabDialog.dialog('option', 'title', 'Kill the ' + $a.text() + ' tab?');
$killTabDialog.data('tabName', $a.text())
.data('panelId', $a.attr('href'))
.data('tabLinkId', $a.prop('id'))
......@@ -166,7 +163,6 @@
});
});
console.log('---- INDEX OK ----');
// Prefs
......@@ -229,9 +225,6 @@
<i id="savingIcon" class="icon-download"></i>
<div id="killFeedDialog" title="" class="mobDOM">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:12px 12px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>
<div id="tabDialog" title="Rename tab" class="mobDOM">
<form>
......@@ -384,6 +377,9 @@
});
});
console.log('---- INDEX OK ----');
//
// $('#mobDialogs').load('/static/templates/dialog.html', function() {
// console.log('Load OK: ' + $(this).get())
......
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