daveappserver 0.5.39 → 0.5.44

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,10 +1,11 @@
1
- var myVersion = "0.5.39", myProductName = "daveAppServer";
1
+ var myVersion = "0.5.44", myProductName = "daveAppServer";
2
2
 
3
3
  exports.start = startup;
4
4
  exports.notifySocketSubscribers = notifySocketSubscribers;
5
5
  exports.saveStats = saveStats;
6
6
  exports.getStats = getStats; //6/28/21 by DW
7
7
  exports.getConfig = getConfig;
8
+ exports.publishFile = publishFile; //12/13/21 by DW
8
9
 
9
10
  const fs = require ("fs");
10
11
  var dns = require ("dns");
@@ -281,6 +282,18 @@ function cleanFileStats (stats) { //4/19/21 by DW
281
282
  });
282
283
  }
283
284
 
285
+ function kissOtherLogonsGoodnight (screenname, theNewConnection) { //12/14/21 by DW
286
+ theWsServer.connections.forEach (function (conn, ix) {
287
+ if (conn.appData !== undefined) { //it's one of ours
288
+ if (conn != theNewConnection) { //it's not the new one
289
+ if (conn.appData.screenname == screenname) {
290
+ conn.sendText ("goodnight");
291
+ }
292
+ }
293
+ }
294
+ });
295
+ }
296
+
284
297
  conn.on ("text", function (s) {
285
298
  var words = s.split (" ");
286
299
  if (words.length > 1) { //new protocol as of 11/29/15 by DW
@@ -299,6 +312,7 @@ function cleanFileStats (stats) { //4/19/21 by DW
299
312
  conn.appData.urlToWatch = "";
300
313
  davetwitter.getScreenName (token, secret, function (screenname) {
301
314
  conn.appData.screenname = screenname;
315
+ kissOtherLogonsGoodnight (screenname, conn); //12/14/21 by DW
302
316
  logToConsole (conn, conn.appData.lastVerb, conn.appData.screenname);
303
317
  });
304
318
  break;
@@ -364,6 +378,9 @@ function cleanFileStats (stats) { //4/19/21 by DW
364
378
  }
365
379
  else {
366
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
+ }
367
384
  if (!flprivate) {
368
385
  notifySocketSubscribers ("update", filetext, true, function (conn) { //3/6/2 by DW -- payload is a string
369
386
  if (conn.appData.urlToWatch == url) {
@@ -605,6 +622,10 @@ function cleanFileStats (stats) { //4/19/21 by DW
605
622
  callback (err);
606
623
  }
607
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
+ }
608
629
  callback (undefined);
609
630
  }
610
631
  });
@@ -985,31 +1006,46 @@ function startup (options, callback) {
985
1006
  });
986
1007
  }
987
1008
  function returnServerHomePage () {
988
- request (config.urlServerHomePageSource, function (error, response, templatetext) {
989
- if (!error && response.statusCode == 200) {
990
- var pagetable = {
991
- productName: config.productName,
992
- productNameForDisplay: config.productNameForDisplay,
993
- version: config.version,
994
- urlServerForClient: config.urlServerForClient,
995
- urlWebsocketServerForClient: config.urlWebsocketServerForClient,
996
- flEnableLogin: config.flEnableLogin,
997
- prefsPath: config.prefsPath,
998
- docsPath: config.docsPath,
999
- idGitHubClient: config.githubClientId //11/9/21 by DW
1000
- };
1001
- if (theRequest.addToPagetable !== undefined) { //3/9/21 by DW
1002
- for (var x in theRequest.addToPagetable) {
1003
- pagetable [x] = theRequest.addToPagetable [x];
1004
- }
1005
- }
1006
- if (config.addMacroToPagetable !== undefined) {
1007
- config.addMacroToPagetable (pagetable);
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
+ };
1021
+ if (theRequest.addToPagetable !== undefined) { //3/9/21 by DW
1022
+ for (var x in theRequest.addToPagetable) {
1023
+ pagetable [x] = theRequest.addToPagetable [x];
1008
1024
  }
1009
- var pagetext = utils.multipleReplaceAll (templatetext, pagetable, false, "[%", "%]");
1010
- returnHtml (pagetext);
1011
1025
  }
1012
- });
1026
+ if (config.addMacroToPagetable !== undefined) {
1027
+ config.addMacroToPagetable (pagetable);
1028
+ }
1029
+ var pagetext = utils.multipleReplaceAll (templatetext.toString (), pagetable, false, "[%", "%]");
1030
+ returnHtml (pagetext);
1031
+ }
1032
+ if (config.pathServerHomePageSource !== undefined) {
1033
+ fs.readFile (config.pathServerHomePageSource, function (err, templatetext) {
1034
+ if (err) {
1035
+ console.log ("returnServerHomePage: err.message == " + err.message + ", f == " + config.pathServerHomePageSource);
1036
+ }
1037
+ else {
1038
+ servePage (templatetext);
1039
+ }
1040
+ });
1041
+ }
1042
+ else {
1043
+ request (config.urlServerHomePageSource, function (err, response, templatetext) {
1044
+ if (!err && response.statusCode == 200) {
1045
+ servePage (templatetext);
1046
+ }
1047
+ });
1048
+ }
1013
1049
  }
1014
1050
  function callWithScreenname (callback) {
1015
1051
  davetwitter.getScreenName (token, secret, function (screenname) {
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.39",
4
+ "version": "0.5.44",
5
5
  "main": "appserver.js",
6
6
  "repository": {
7
7
  "type" : "git",
package/readme.md CHANGED
@@ -52,6 +52,12 @@ The second section configures the HTTP server and the connection to Twitter for
52
52
 
53
53
  ### Updates
54
54
 
55
+ #### v0.5.44 -- 3/18/22 by DW
56
+
57
+ 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.
58
+
59
+ It's called when we handle a /publishfile or /writewholefile message.
60
+
55
61
  #### v0.5.32 -- 12/4/21 by DW
56
62
 
57
63
  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>Fri, 18 Mar 2022 14:26:35 GMT</dateModified>
6
6
  <expansionState></expansionState>
7
7
  <vertScrollState>1</vertScrollState>
8
8
  <windowTop>300</windowTop>
@@ -45,6 +45,10 @@
45
45
  </outline>
46
46
  </outline>
47
47
  <outline created="Wed, 15 Sep 2021 14:19:02 GMT" text="### Updates">
48
+ <outline created="Fri, 18 Mar 2022 14:21:28 GMT" text="#### v0.5.44 -- 3/18/22 by DW">
49
+ <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>
50
+ <outline created="Fri, 18 Mar 2022 14:22:36 GMT" text="It's called when we handle a /publishfile or /writewholefile message."></outline>
51
+ </outline>
48
52
  <outline created="Sat, 04 Dec 2021 21:29:57 GMT" text="#### v0.5.32 -- 12/4/21 by DW">
49
53
  <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
54
  <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>