Commit 7af77bd8 authored by yPhil's avatar yPhil

Discover: Candidate OK

parent 2945794d
This diff is collapsed.
......@@ -164,13 +164,17 @@ label {
margin: 5px 0;
}
#feedUrl,
div#testFlex div,
#feedType label {
/* #feedUrl, */
/* div.testFlex div, */
/* #feedType label { */
/* flex: 1; */
/* } */
.prefsForm > * {
flex: 1;
}
div#testFlex {
div.testFlex {
display:flex;
}
......
......@@ -95,13 +95,6 @@ var Dialog = (function() {
var $spinner = $(this).find('#spinner').spinner();
var myVal
$spinner.on( "spinstart", function(event, ui) {
myVal = $(this).val()
});
$spinner.on( "spinstop", function(event, ui) {
$dialog.find('div#feedLimit').slider( "option", "value", $(this).val());
$dialog.find(".ui-slider-handle").text($(this).val());
......@@ -111,10 +104,6 @@ var Dialog = (function() {
var $feed = $dataStore.parent().parent();
if (isNewFeed === true) {
console.log('NEW!')
}
$dialog.dialog({
autoOpen: false,
resizable: false,
......@@ -126,11 +115,7 @@ var Dialog = (function() {
$(this).dialog( 'close' );
if (isNewFeed) {
$feed.hide('slide', 1000, function() {
$feed.remove();
});
$feed.hide('slide', 1000, function() { $feed.remove() });
}
},
......@@ -145,8 +130,6 @@ var Dialog = (function() {
Feed.populateFeed($feedPrefsButton);
Tab.saveTabs();
// $(this).find('.feedType').checkboxradio( "destroy" );
$(this).dialog( 'close' );
$('#mobDialogs').empty();
......@@ -156,12 +139,49 @@ var Dialog = (function() {
var $dialog = $(this),
$tabFeedId = $('li#' + $dataStore.data('id')),
$mobFeedRefresh = $tabFeedId.find('.mobFeedRefresh');
$mobFeedRefresh = $tabFeedId.find('.mobFeedRefresh'),
$guessButton = $dialog.find('button#feedGuess').button(),
$guessSpinner = $dialog.find('button#feedGuess > i'),
$guessField = $dialog.find('input#feedGuess'),
$guessGroup = $dialog.find('div#feedGuess').controlgroup(),
$urlGroup = $guessGroup.parent(),
$guessCandidate = $('<div id="guessCandidate">');
var oldUrl = $dataStore.data('url'),
oldType = $dataStore.data('type'),
oldLimit = $dataStore.data('limit');
// $dialog.find('div#feedGuessContainer').controlgroup();
$guessField.val(oldUrl);
$guessButton.click(function(event) {
console.log('\nGuess: %s', $guessField.val());
$guessSpinner.addClass('spinner');
$.get("/discover", {
url: $guessField.val(),
dataType: "json",
timeout: 2000
}, function(feed, status) {
$guessSpinner.removeClass('spinner')
.removeClass('icon-cog');
}).done(function(feed, status) {
console.log( 'DONE %s OK (status %s)', feed, status);
// $guessCandidate.append(feed).appendTo($urlGroup);
$guessField.val(feed);
$guessSpinner.addClass('icon-ok');
}).fail(function(feed, status) {
console.log( '%s: ERROR (status: %s)', $guessField.val(), status);
$guessSpinner.addClass('icon-cancel-circled');
}).always(function(feed, status) {
console.log( 'Always %s (status: %s)', $guessField.val(), status);
});
});
$spinner.spinner( "value", oldLimit);
$(this).find('input#feedUrl').val(oldUrl);
......
......@@ -70,7 +70,7 @@ var Feed = (function() {
function() {
var iconImg = $feedToggle.css('background-image');
console.log('IMG: (%s)', iconImg);
// console.log('IMG: (%s)', iconImg);
$(this).data('img',iconImg);
......@@ -157,7 +157,7 @@ var Feed = (function() {
$.get("/feedicon", {
url: decodeURI(feedHost),
dataType: "json",
timeout: 3000
timeout: 2000
}, function(icon, status) {
if ( !icon || icon.length === 0) icon = '/static/images/feed-generic-rss.png';
......@@ -165,13 +165,13 @@ var Feed = (function() {
}).done(function(icon, status) {
// console.log( 'DONE %s OK (status %s)', icon, status);
$feedIcon.css('background-image','url("' + icon + '")');
}).fail(function(icon, status) {
// console.log( 'FAVICON %s ERROR (status: %s)', feedHost, status);
$feedIcon.css('background-image','url("/static/images/feed-generic-rss.png")');
}).always(function(icon, status) {
}).fail(function(icon, status) {
// console.log( 'FAVICON %s ERROR (status: %s)', feedHost, status);
$feedIcon.css('background-image','url("/static/images/feed-generic-rss.png")');
}).always(function(icon, status) {
// console.log( '\nALWAYS for %s: %s (status: %s)', feedHost, JSON.stringify(icon), status);
});
// console.log( '\nALWAYS for %s: %s (status: %s)', feedHost, JSON.stringify(icon), status);
});
$.get("/feed", {
feedurl: feedUrl,
......
......@@ -32,6 +32,21 @@
onclick="select()"
autofocus
/>
<div id="feedGuess" class="testFlex">
<input type="text"
name="guess"
id="feedGuess"
placeholder="URL (https://reddit.com)"
value=""
class="text ui-widget-content grow left twin"
onclick="select()"
/>
<button type="button" id="feedGuess" class="shrink twin right">
<i class="icon-cog"></i>
</button>
</div>
</fieldset>
<fieldset id="feedType" class="prefsForm ui-widget ui-widget-content ui-corner-all">
......@@ -48,7 +63,7 @@
<fieldset id="feedLimit" class="ui-widget ui-widget-content ui-corner-all">
<legend class="ui-corner-top" class="ui-corner-top">Limit # of items</legend>
<div id="testFlex">
<div class="testFlex">
<div class="feedLimit grow left twin">
<label for="feedLimit" class="ui-helper-hidden">
<input type="text" id="feedLimit" />
......
......@@ -51,7 +51,7 @@
<fieldset class="prefsForm ui-widget ui-widget-content ui-corner-all">
<legend class="ui-corner-top">Help</legend>
<button id="donate" class="unique icon-heartbeat" onclick="location.href='https://liberapay.com/yassinphilip';"> Donate</button>
<button id="donate" class="unique icon-heartbeat" title="I'm an indie developer, and I need your help" onclick="location.href='https://liberapay.com/yassinphilip';"> Donate</button>
</fieldset>
<fieldset id="mobNotify" class="ui-widget ui-widget-content ui-corner-all">
......
......@@ -4,6 +4,8 @@ var favicon = require('favicon');
var FeedParser = require('feedparser');
var request = require('request'); // for fetching the feed
var feedrat = require('feedrat');
var cheerio = require('cheerio');
router.get('/', function(req, res, next) {
......@@ -67,132 +69,33 @@ function getDomain(url) {
return m ? m[0] : null;
}
router.get('/favicon', function(req, res, next) {
var thisUri = req.query.url;
var req = request(req.query.url, function(error, response, html) {
var okTypes = [
'image/x-icon',
'image/png',
'image/vnd.microsoft.icon'
];
var $ = cheerio.load(html, {
xmlMode: true
});
$.prototype.exists = function (selector) {
return this.find(selector).length > 0;
}
var $link = $('link');
if ($link.length !== 0){
if (thisUri !== null && thisUri !== '') {
console.log('\nDomain (%s)', getDomain(thisUri));
var obviousIcon = getDomain(thisUri) + '/favicon.ico';
var pngIcon = getDomain(thisUri) + '/favicon.png';
request
.get(obviousIcon)
.on('response', function(response) {
if (response.statusCode == 200) {
console.log('(obvious) ICON! (%s)', obviousIcon)
}
})
.on('error', function(err) {
console.log('NO (obvious) ICON! (%s)', err)
})
request
.get(pngIcon)
.on('response', function(response) {
if (response.statusCode == 200) {
console.log('(png) ICON! (%s)', pngIcon)
}
})
.on('error', function(err) {
console.log('NO (png) ICON! (%s)', err)
})
// if (typeof $link.attr('rel') !== 'undefined' && $link.attr('rel') === 'alternate') {
// // console.log('REL (%s): %s', thisUri, $link.attr('href'));
// var altIcon = $link.attr('href') + '/favicon.ico';
// request
// .get(altIcon)
// .on('response', function(response) {
// if (response.statusCode == 200 && okTypes.indexOf(response.headers['content-type']) >= 0) {
// console.log('ALT ICON! (%s)', altIcon) // 200
// }
// })
// .on('error', function(err) {
// console.log('NO (alt) ICON! (%s)', err)
// })
router.get('/feedicon', function(req, res, next) {
favicon(req.query.url, function(err, u) {
// }
if (typeof u === 'undefined' || !u) {
}
// console.log('Url: ' + req.query.feedhost + '\nFavicon: ' + favicon_url)
// res.send(err.code);
// console.log('Error getting (%s) icon', JSON.stringify(req.query.url))
} else {
// console.log('Url: ' + req.query.feedhost + '\nError: ' + JSON.stringify(err))
res.send(u)
// console.log('Err: ' + JSON.stringify(err))
}
});
});
// req.on('response', function(response) {
// console.log('OK: %s', response.statusCode) // 200
// // console.log(response.headers['content-type']) // 'image/png'
// })
// req.on('error', function(err) {
// console.log('Err: %s', err) // 200
// })
// if (!error && response.statusCode == 200) {
// var $ = cheerio.load(html, {
// xmlMode: true
// });
// $.prototype.exists = function (selector) {
// return this.find(selector).length > 0;
// }
// if ($('link').attr('rel').exists()) {
// console.log('Link: %s', $('link').attr('href'))
// if (isValidUri(getDomain($('link').attr('href')) + '/favicon.ico')) {
// console.log('Found VALID alt!');
// } else {
// console.log('bummer! (%s)', isValidUri(getDomain($('link').attr('href')) + '/favicon.ico'));
// }
// }
// }
})
router.get('/feedicon', function(req, res, next) {
router.get('/discover', function(req, res, next) {
favicon(req.query.url, function(err, u) {
feedrat(req.query.url, function(err, u) {
if (typeof u === 'undefined' || !u) {
// console.log('Url: ' + req.query.feedhost + '\nFavicon: ' + favicon_url)
console.log('Url: ' + req.query.url)
// res.send(err.code);
// console.log('Error getting (%s) icon', JSON.stringify(req.query.url))
res.send(err);
} else {
// console.log('Url: ' + req.query.feedhost + '\nError: ' + JSON.stringify(err))
res.send(u)
......@@ -201,6 +104,7 @@ router.get('/feedicon', function(req, res, next) {
});
});
router.post('/upload', function(req, res) {
if (!req.files)
return res.status(400).send('No files were uploaded.');
......
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