Skip to content
Snippets Groups Projects
Commit 8178eafc authored by echicken's avatar echicken :chicken:
Browse files

Allow passing file:// URLs to the Feed constructor.

If you have a local XML document containing an RSS or Atom feed,
you can point to it like: file:///this/is/where/it/is.xml.
For Dan_C, a variation on nelgin's proposed solution.
parent de455e84
No related branches found
No related tags found
No related merge requests found
Pipeline #64 passed
......@@ -160,15 +160,24 @@ const Feed = function (url, follow_redirects) {
this.channels = [];
this.load = function () {
var httpRequest = new HTTPRequest();
httpRequest.follow_redirects = follow_redirects || 0;
var response = httpRequest.Get(url);
if (typeof response == "undefined" || response == "") {
throw new Error('Empty response from server.');
var doc;
if (url.search('file://') == 0) {
var f = new File(url.substring(7));
if (!f.open('f')) throw new Error(f.error);
doc = f.read();
f.close();
f = undefined;
} else {
var httpRequest = new HTTPRequest();
httpRequest.follow_redirects = follow_redirects || 0;
doc = httpRequest.Get(url);
if (typeof doc == "undefined" || doc == "") {
throw new Error('Empty response from server.');
}
httpRequest = undefined;
}
var feed = new XML(response.replace(/^<\?xml.*\?>/g, ""));
httpRequest = undefined;
response = undefined;
var feed = new XML(doc.replace(/^<\?xml.*\?>/g, ""));
doc = undefined;
switch (feed.localName()) {
case "rss":
var channels = feed.channel.length();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment