Commit 6663b1a1 authored by yPhil's avatar yPhil

Lib: JS files cleanup: npm standard: utilities.js OK

parent 981b7d0b
......@@ -45,7 +45,7 @@
"ignore": [
"public/lib/js/jquery.localize.js",
"test.js",
"public/css"
"public/css/**/*.js"
]
}
}
......@@ -13,14 +13,14 @@ router.get('/', function (req, res, next) {
function getFeed (urlfeed, callback) {
var req = request(urlfeed)
var feedparser = new FeedParser()
var feedItems = new Array()
var feedItems = []
req.on('response', function (res) {
var stream = this
if (res.statusCode == 200) {
if (res.statusCode === 200) {
stream.pipe(feedparser)
// console.log ("OK: (code %s) reading (%s)", res.statusCode, urlfeed);
// console.log ("OK: (code %s) reading (%s)", res.statusCode, urlfeed);
} else {
// console.log ("Error (code %s) reading (%s)", res.statusCode, urlfeed);
// console.log ("Error (code %s) reading (%s)", res.statusCode, urlfeed);
}
})
req.on('error', function (res) {
......@@ -28,7 +28,7 @@ function getFeed (urlfeed, callback) {
})
feedparser.on('readable', function () {
try {
var item = this.read(), flnew
var item = this.read()
if (item !== null) { // 2/9/17 by DW
feedItems.push(item)
}
......@@ -37,7 +37,7 @@ function getFeed (urlfeed, callback) {
}
}).on('end', function () {
var meta = this.meta
callback(undefined, feedItems, meta.title)
callback(null, feedItems, meta.title)
}).on('error', function (err) {
console.log('getFeed: Error reading (%s) feed.', urlfeed)
callback(err)
......@@ -47,41 +47,19 @@ function getFeed (urlfeed, callback) {
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)
}
res.status(200).json({'feedItems': feedItems, 'feedTitle': feedTitle})
}
})
})
function getDomain (url) {
var m = url.match(/^http:\/\/[^/]+/)
return m ? m[0] : null
}
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))
// }
if (u) {
res.send(u)
} else if (err) {
res.status(500).send('No icon found' + err)
} else {
res.status(500).send('No icon found')
res.status(500).send('No icon found (no error returned)')
}
})
})
......@@ -90,8 +68,10 @@ router.get('/discover', function (req, res, next) {
feedrat(req.query.url, function (err, feed) {
if (feed && typeof feed !== 'undefined') {
res.send(feed)
} else if (err) {
res.status(500).send('No feed found' + err)
} else {
res.status(500).send('No feed found')
res.status(500).send('No feed found (no error returned)')
}
})
})
......@@ -99,10 +79,10 @@ router.get('/discover', function (req, res, next) {
router.post('/upload', function (req, res) {
if (!req.files) { return res.status(400).send('No files were uploaded.') }
// The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
// The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
let sampleFile = req.files.sampleFile
// Use the mv() method to place the file somewhere on your server
// Use the mv() method to place the file somewhere on your server
sampleFile.mv('/tmp/plop.json', function (err) {
if (err) { return res.status(500).send(err) }
......
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