master
Dave Winer 9 years ago
parent dae086756b
commit 2d733e79d7

@ -98,8 +98,8 @@ function copyScalars (source, dest) { //8/31/14 by DW
}
function readInclude (theIncludeNode, callback) {
console.log ("readInclude: url == " + theIncludeNode.url);
readOpmlUrl (theIncludeNode.url, function (theOutline, err) {
if (err) {
readOpmlUrl (theIncludeNode.url, function (theOutline) {
if (theOutline === undefined) {
callback (undefined);
}
else {
@ -124,6 +124,9 @@ function outlineVisiter (theOutline, inlevelcallback, outlevelcallback, nodecall
doOneSub (head, ixsub +1);
});
}
else { //6/25/15 by DW -- don't let errors derail us
doOneSub (head, ixsub +1);
}
});
}
else {
@ -208,7 +211,7 @@ function readOpmlString (s, callback) {
theStream.pipe (opmlparser);
opmlparser.on ("error", function (error) {
console.log ("readOpml: opml parser error == " + error.message);
console.log ("readOpmlString: opml parser error == " + error.message);
if (callback != undefined) {
callback (undefined, error);
}
@ -269,173 +272,34 @@ function readOpmlString (s, callback) {
});
});
}
function readOpmlFile (f, callback) {
var outlineArray = new Array ();
var fstream = fs.createReadStream (f);
var opmlparser = new opmlParser ();
var metadata = undefined;
flparseerror = false;
fstream.pipe (opmlparser);
opmlparser.on ("error", function (error) {
console.log ("readOpml: opml parser error == " + error.message);
if (callback != undefined) {
callback (undefined, error);
}
flparseerror = true;
});
opmlparser.on ("readable", function () {
var outline;
while (outline = this.read ()) {
var ix = Number (outline ["#id"]);
outlineArray [ix] = outline;
if (metadata === undefined) {
metadata = this.meta;
}
}
});
opmlparser.on ("end", function () {
if (flparseerror) {
return;
}
var theOutline = new Object ();
//copy elements of the metadata object into the root of the outline
function copyone (name) {
var val = metadata [name];
if ((val !== undefined) && (val != null)) {
theOutline [name] = val;
}
}
copyone ("title");
copyone ("datecreated");
copyone ("datemodified");
copyone ("ownername");
copyone ("owneremail");
copyone ("description");
for (var i = 0; i < outlineArray.length; i++) {
var obj = outlineArray [i];
if (obj != null) {
var idparent = obj ["#parentid"], parent;
if (idparent == 0) {
parent = theOutline;
function readOpmlFile (f, callback) { //6/25/15 by DW
fs.readFile (f, function (err, data) {
if (err) {
console.log ("readOpmlFile: error reading file " + f + " == " + err.message)
callback (undefined);
}
else {
parent = outlineArray [idparent];
}
if (parent.subs === undefined) {
parent.subs = new Array ();
}
parent.subs [parent.subs.length] = obj;
delete obj ["#id"];
delete obj ["#parentid"];
readOpmlString (data.toString (), callback);
}
}
expandIncludes (theOutline, function (expandedOutline) {
if (callback != undefined) {
callback (expandedOutline, undefined);
}
});
});
}
function readOpmlUrl (urlOutline, callback) {
if (opmlData.flUseOutlineCache && (opmlData.outlineCache [urlOutline] !== undefined)) {
if (callback !== undefined) {
callback (opmlData.outlineCache [urlOutline], undefined);
}
request (urlOutline, function (err, response, body) {
if (err !== null) {
console.log ("readOpmlUrl: error reading file " + urlOutline + " == " + err.message)
callback (undefined);
}
else {
var outlineArray = new Array ();
var opmlparser = new opmlParser ();
var metadata = undefined;
var flparseerror = false;
var req;
var theRequest = {
url: urlOutline,
headers: {
"Accept": "text/x-opml, */*",
}
};
req = request (theRequest);
req.on ("response", function (res) {
var stream = this;
if (res.statusCode == 200) {
stream.pipe (opmlparser);
}
});
req.on ("error", function (res) {
console.log ("readOpml: error reading outline. urlOutline == " + urlOutline);
if (callback != undefined) {
callback (undefined, res);
}
});
opmlparser.on ("error", function (error) {
console.log ("readOpml: opml parser error == " + error.message);
if (callback != undefined) {
callback (undefined, error);
}
flparseerror = true;
});
opmlparser.on ("readable", function () {
var outline;
while (outline = this.read ()) {
var ix = Number (outline ["#id"]);
outlineArray [ix] = outline;
if (metadata === undefined) {
metadata = this.meta;
}
}
});
opmlparser.on ("end", function () {
if (flparseerror) {
return;
}
var theOutline = new Object ();
//copy elements of the metadata object into the root of the outline
function copyone (name) {
var val = metadata [name];
if ((val !== undefined) && (val != null)) {
theOutline [name] = val;
}
}
copyone ("title");
copyone ("datecreated");
copyone ("datemodified");
copyone ("ownername");
copyone ("owneremail");
copyone ("description");
for (var i = 0; i < outlineArray.length; i++) {
var obj = outlineArray [i];
if (obj != null) {
var idparent = obj ["#parentid"], parent;
if (idparent == 0) {
parent = theOutline;
if (response.statusCode != 200) {
console.log ("readOpmlUrl: error reading file, statusCode == " + response.statusCode + ", urlOutline == " + urlOutline)
callback (undefined);
}
else {
parent = outlineArray [idparent];
}
if (parent.subs === undefined) {
parent.subs = new Array ();
}
parent.subs [parent.subs.length] = obj;
delete obj ["#id"];
delete obj ["#parentid"];
readOpmlString (body.toString (), callback);
}
}
if (opmlData.flUseOutlineCache) {
opmlData.outlineCache [urlOutline] = theOutline;
}
if (callback != undefined) {
callback (theOutline, undefined);
}
});
}
}

@ -1,4 +1,4 @@
var myVersion = "0.61v", myProductName = "PagePark";
var myVersion = "0.62d", myProductName = "PagePark";
//The MIT License (MIT)

Loading…
Cancel
Save