function serveOutline (theOutline, fname) { if (hasAcceptHeader ("text/x-opml")) { callback (true, 200, "text/xml", outlineToOPML (theOutline, fname)); } else { callback (true, 200, "application/json", utils.jsonStringify (theOutline)); } }
utils.sureFilePath (f, function () { fs.writeFile (f, utils.jsonStringify (stats), function (err) { if (err) { console.log ("writeStats: error == " + err.message); } if (callback != undefined) { callback (); } }); });
opmlToJs.parse (opmltext, function (theOutline) { var pagetable = { bodytext: utils.jsonStringify (theOutline), title: utils.stringLastField (path, "/"), description: "", image: "", sitename: "", url: "http://" + httpRequest.headers.host + httpRequest.url }; utils.copyScalars (theOutline.opml.head, pagetable); var htmltext = utils.multipleReplaceAll (theTemplate, pagetable, false, "[%", "%]"); httpReturn (htmltext, "text/html"); });
getTopLevelPrefs (function () { console.log ("\n" + myProductName + " v" + myVersion + " running on port " + pageparkPrefs.myPort + ".\n"); console.log ("startup: pageparkPrefs == " + utils.jsonStringify (pageparkPrefs)); readStats (fnameStats, pageparkStats, function () { utils.sureFilePath (getFullFilePath (domainsPath) + "x", function () { //make sure domains folder exists var now = new Date (); pageparkStats.ctStarts++; pageparkStats.whenLastStart = now; pageparkStats.ctHitsSinceStart = 0; //9/30/17 by DW flStatsDirty = true; http.createServer (handleHttpRequest).listen (pageparkPrefs.myPort); webSocketStartup (); //9/29/17 by DW setInterval (everySecond, 1000); }); }); });
fs.stat (f, function (err, stats) { if (err) { switch (lowerpath) { case "/version": httpRespond (200, "text/plain", myVersion); break; case "/now": httpRespond (200, "text/plain", now.toString ()); break; case "/status": var status = { prefs: pageparkPrefs, status: pageparkStats } httpRespond (200, "text/plain", utils.jsonStringify (status)); break; default: if (!serveRedirect (lowerpath, config)) { //12/8/15 by DW -- it wasn't a redirect return404 (); } break; } } else { if (!serveRedirect (lowerpath, config)) { //7/30/15 by DW -- it wasn't a redirect if (stats.isDirectory ()) { if (!utils.endsWith (f, "/")) { returnRedirect (httpRequest.url + "/", false); //7/5/17 by DW } else { findSpecificFile (f, pageparkPrefs.indexFilename, function (findex) { serveFile (findex, config); }); } } else { serveFile (f, config); } } } });
function notifySocketSubscribers (verb, jstruct) { if (theWsServer !== undefined) { var ctUpdates = 0, now = new Date (), jsontext = ""; if (jstruct !== undefined) { //10/7/16 by DW jsontext = utils.jsonStringify (jstruct); } for (var i = 0; i < theWsServer.connections.length; i++) { var conn = theWsServer.connections [i]; if (conn.pageParkData !== undefined) { //it's one of ours try { conn.sendText (verb + "\r" + jsontext); conn.pageParkData.whenLastUpdate = now; conn.pageParkData.ctUpdates++; ctUpdates++; } catch (err) { console.log ("notifySocketSubscribers: socket #" + i + ": error updating"); } } } } }
isNameAvailable (name, function (name, flAvailable, msg) { if (flAvailable) { var path = s3NamesPath + name + ".json" var metadata = { "name": name, "opmlUrl": url, "owner": owner, "whenCreated": new Date ().toString () }; s3.newObject (path, utils.jsonStringify (metadata), "application/json", "private", function (err, data) { console.log ("reserveName: path == " + path); if (err) { callback (name, false, err.message); } else { callback (name, true, ""); } }); } else { callback (name, false, "The name \"" + name + "\" is already in use."); } });