daveappserver 0.5.41 → 0.5.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/appserver.js CHANGED
@@ -1,4 +1,4 @@
1
- var myVersion = "0.5.41", myProductName = "daveAppServer";
1
+ var myVersion = "0.5.46", myProductName = "daveAppServer";
2
2
 
3
3
  exports.start = startup;
4
4
  exports.notifySocketSubscribers = notifySocketSubscribers;
@@ -378,6 +378,9 @@ function cleanFileStats (stats) { //4/19/21 by DW
378
378
  }
379
379
  else {
380
380
  var url = (flprivate) ? undefined : config.urlServerForClient + screenname + "/" + relpath;
381
+ if (config.publishFile !== undefined) { //3/18/22 by DW
382
+ config.publishFile (f, screenname, relpath, type, flprivate, filetext, url);
383
+ }
381
384
  if (!flprivate) {
382
385
  notifySocketSubscribers ("update", filetext, true, function (conn) { //3/6/2 by DW -- payload is a string
383
386
  if (conn.appData.urlToWatch == url) {
@@ -619,6 +622,10 @@ function cleanFileStats (stats) { //4/19/21 by DW
619
622
  callback (err);
620
623
  }
621
624
  else {
625
+ if (config.publishFile !== undefined) { //3/18/22 by DW
626
+ var url = (flprivate) ? undefined : config.urlServerForClient + screenname + "/" + relpath;
627
+ config.publishFile (f, screenname, relpath, type, flprivate, filetext, url);
628
+ }
622
629
  callback (undefined);
623
630
  }
624
631
  });
@@ -998,37 +1005,58 @@ function startup (options, callback) {
998
1005
  }
999
1006
  });
1000
1007
  }
1001
- function returnServerHomePage () {
1002
- request (config.urlServerHomePageSource, function (error, response, templatetext) {
1003
- if (!error && response.statusCode == 200) {
1004
- var pagetable = {
1005
- productName: config.productName,
1006
- productNameForDisplay: config.productNameForDisplay,
1007
- version: config.version,
1008
- urlServerForClient: config.urlServerForClient,
1009
- urlWebsocketServerForClient: config.urlWebsocketServerForClient,
1010
- flEnableLogin: config.flEnableLogin,
1011
- prefsPath: config.prefsPath,
1012
- docsPath: config.docsPath,
1013
- idGitHubClient: config.githubClientId //11/9/21 by DW
1014
- };
1015
- if (theRequest.addToPagetable !== undefined) { //3/9/21 by DW
1016
- for (var x in theRequest.addToPagetable) {
1017
- pagetable [x] = theRequest.addToPagetable [x];
1018
- }
1019
- }
1020
- if (config.addMacroToPagetable !== undefined) {
1021
- config.addMacroToPagetable (pagetable);
1008
+ function returnServerHomePage (screenname) {
1009
+ function servePage (templatetext) {
1010
+ var pagetable = {
1011
+ productName: config.productName,
1012
+ productNameForDisplay: config.productNameForDisplay,
1013
+ version: config.version,
1014
+ urlServerForClient: config.urlServerForClient,
1015
+ urlWebsocketServerForClient: config.urlWebsocketServerForClient,
1016
+ flEnableLogin: config.flEnableLogin,
1017
+ prefsPath: config.prefsPath,
1018
+ docsPath: config.docsPath,
1019
+ idGitHubClient: config.githubClientId, //11/9/21 by DW
1020
+ screenname //4/30/22 by DW
1021
+ };
1022
+ if (theRequest.addToPagetable !== undefined) { //3/9/21 by DW
1023
+ for (var x in theRequest.addToPagetable) {
1024
+ pagetable [x] = theRequest.addToPagetable [x];
1022
1025
  }
1023
- var pagetext = utils.multipleReplaceAll (templatetext, pagetable, false, "[%", "%]");
1024
- returnHtml (pagetext);
1025
1026
  }
1026
- });
1027
+ if (config.addMacroToPagetable !== undefined) {
1028
+ config.addMacroToPagetable (pagetable);
1029
+ }
1030
+ var pagetext = utils.multipleReplaceAll (templatetext.toString (), pagetable, false, "[%", "%]");
1031
+ returnHtml (pagetext);
1032
+ }
1033
+ if (config.pathServerHomePageSource !== undefined) {
1034
+ fs.readFile (config.pathServerHomePageSource, function (err, templatetext) {
1035
+ if (err) {
1036
+ console.log ("returnServerHomePage: err.message == " + err.message + ", f == " + config.pathServerHomePageSource);
1037
+ }
1038
+ else {
1039
+ servePage (templatetext);
1040
+ }
1041
+ });
1042
+ }
1043
+ else {
1044
+ request (config.urlServerHomePageSource, function (err, response, templatetext) {
1045
+ if (!err && response.statusCode == 200) {
1046
+ servePage (templatetext);
1047
+ }
1048
+ });
1049
+ }
1027
1050
  }
1028
- function callWithScreenname (callback) {
1051
+ function callWithScreenname (callback, flMustHaveToken=true) {
1029
1052
  davetwitter.getScreenName (token, secret, function (screenname) {
1030
1053
  if (screenname === undefined) {
1031
- returnError ({message: "Can't do the thing you want because the accessToken is not valid."});
1054
+ if (flMustHaveToken) {
1055
+ returnError ({message: "Can't do the thing you want because the accessToken is not valid."});
1056
+ }
1057
+ else {
1058
+ callback (undefined);
1059
+ }
1032
1060
  }
1033
1061
  else {
1034
1062
  callback (screenname);
@@ -1074,7 +1102,9 @@ function startup (options, callback) {
1074
1102
  case "get":
1075
1103
  switch (theRequest.lowerpath) {
1076
1104
  case "/":
1077
- returnServerHomePage ();
1105
+ callWithScreenname (function (screenname) {
1106
+ returnServerHomePage (screenname);
1107
+ }, false);
1078
1108
  return (true);
1079
1109
  case "/now":
1080
1110
  returnPlainText (new Date ());
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "daveappserver",
3
3
  "description": "Factored code that was appearing in all my servers.",
4
- "version": "0.5.41",
4
+ "version": "0.5.46",
5
5
  "main": "appserver.js",
6
6
  "repository": {
7
7
  "type" : "git",
package/readme.md CHANGED
@@ -52,6 +52,16 @@ The second section configures the HTTP server and the connection to Twitter for
52
52
 
53
53
  ### Updates
54
54
 
55
+ #### v0.5.45 -- 4/30/22 by DW
56
+
57
+ pagetable now contains the user's screenname. It's important that the addMacroToPagetable callback have access to the screenname, we need it to construct the url for the user's RSS feed in littleFeedReader.
58
+
59
+ #### v0.5.44 -- 3/18/22 by DW
60
+
61
+ New callback, config.publishFile. If defined we call back with the file, screenname, relpath, flprivate, filetext and the url of the file if it's public.
62
+
63
+ It's called when we handle a /publishfile or /writewholefile message.
64
+
55
65
  #### v0.5.32 -- 12/4/21 by DW
56
66
 
57
67
  Added a new callback, publicFileSaved, which is called when the user updates a public file.
package/readme.opml CHANGED
@@ -2,7 +2,7 @@
2
2
  <opml version="2.0">
3
3
  <head>
4
4
  <title>readme.md</title>
5
- <dateModified>&lt;%dateModified%></dateModified>
5
+ <dateModified>Sat, 30 Apr 2022 14:19:31 GMT</dateModified>
6
6
  <expansionState></expansionState>
7
7
  <vertScrollState>1</vertScrollState>
8
8
  <windowTop>300</windowTop>
@@ -45,6 +45,13 @@
45
45
  </outline>
46
46
  </outline>
47
47
  <outline created="Wed, 15 Sep 2021 14:19:02 GMT" text="### Updates">
48
+ <outline created="Sat, 30 Apr 2022 14:17:59 GMT" text="#### v0.5.45 -- 4/30/22 by DW">
49
+ <outline created="Sat, 30 Apr 2022 14:16:10 GMT" text="pagetable now contains the user's screenname. It's important that the addMacroToPagetable callback have access to the screenname, we need it to construct the url for the user's RSS feed in littleFeedReader. "></outline>
50
+ </outline>
51
+ <outline created="Fri, 18 Mar 2022 14:21:28 GMT" text="#### v0.5.44 -- 3/18/22 by DW">
52
+ <outline created="Fri, 18 Mar 2022 14:21:59 GMT" text="New callback, config.publishFile. If defined we call back with the file, screenname, relpath, flprivate, filetext and the url of the file if it's public."></outline>
53
+ <outline created="Fri, 18 Mar 2022 14:22:36 GMT" text="It's called when we handle a /publishfile or /writewholefile message."></outline>
54
+ </outline>
48
55
  <outline created="Sat, 04 Dec 2021 21:29:57 GMT" text="#### v0.5.32 -- 12/4/21 by DW">
49
56
  <outline created="Sat, 04 Dec 2021 21:30:33 GMT" text="Added a new callback, publicFileSaved, which is called when the user updates a public file. "></outline>
50
57
  <outline created="Sat, 04 Dec 2021 21:29:58 GMT" text="Fixed a bug where a user couldn't create a new file if their public files folder was empty. "></outline>