daveappserver 0.6.12 → 0.6.15
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 +112 -58
- package/package.json +2 -1
package/appserver.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var myVersion = "0.6.
|
|
1
|
+
var myVersion = "0.6.15", myProductName = "daveAppServer";
|
|
2
2
|
|
|
3
3
|
exports.start = startup;
|
|
4
4
|
exports.notifySocketSubscribers = notifySocketSubscribers;
|
|
@@ -21,6 +21,7 @@ const davetwitter = require ("davetwitter");
|
|
|
21
21
|
const filesystem = require ("davefilesystem");
|
|
22
22
|
const folderToJson = require ("foldertojson");
|
|
23
23
|
const zip = require ("davezip");
|
|
24
|
+
const s3 = require ("daves3");
|
|
24
25
|
const qs = require ("querystring");
|
|
25
26
|
const mail = require ("davemail");
|
|
26
27
|
const requireFromString = require ("require-from-string"); //2/10/23 by DW
|
|
@@ -335,6 +336,7 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
335
336
|
if (conn.appData !== undefined) { //it's one of ours
|
|
336
337
|
if (conn != theNewConnection) { //it's not the new one
|
|
337
338
|
if (conn.appData.screenname == screenname) {
|
|
339
|
+
console.log ("kissOtherLogonsGoodnight: \"" + conn.appData.screenname + "\" = \"" + screenname + "\""); //2/12/23 by DW
|
|
338
340
|
conn.sendText ("goodnight");
|
|
339
341
|
}
|
|
340
342
|
}
|
|
@@ -344,7 +346,6 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
344
346
|
|
|
345
347
|
conn.on ("text", function (s) {
|
|
346
348
|
var words = s.split (" ");
|
|
347
|
-
console.log ("handleWebSocketConnection: s == " + s); //6/7/21 by DW
|
|
348
349
|
if (words.length > 1) { //new protocol as of 11/29/15 by DW
|
|
349
350
|
conn.appData.whenLastUpdate = now;
|
|
350
351
|
conn.appData.lastVerb = words [0];
|
|
@@ -353,17 +354,31 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
353
354
|
conn.appData.urlToWatch = utils.trimWhitespace (words [1]);
|
|
354
355
|
logToConsole (conn, conn.appData.lastVerb, conn.appData.urlToWatch);
|
|
355
356
|
break;
|
|
356
|
-
|
|
357
357
|
case "user": //9/29/21 by DW
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
358
|
+
if (config.flUseTwitterIdentity) { //2/12/23 by DW
|
|
359
|
+
var token = words [1], secret = words [2];
|
|
360
|
+
conn.appData.twOauthToken = token;
|
|
361
|
+
conn.appData.twOauthTokenSecret = secret;
|
|
362
|
+
conn.appData.urlToWatch = "";
|
|
363
|
+
davetwitter.getScreenName (token, secret, function (screenname) {
|
|
364
|
+
conn.appData.screenname = screenname;
|
|
365
|
+
kissOtherLogonsGoodnight (screenname, conn); //12/14/21 by DW
|
|
366
|
+
logToConsole (conn, conn.appData.lastVerb, conn.appData.screenname);
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
var emailAddress = words [1], emailSecret = words [2];
|
|
371
|
+
config.isUserInDatabase (emailAddress, function (flInDatabase, userRec) {
|
|
372
|
+
if (flInDatabase) {
|
|
373
|
+
conn.appData.emailAddress = userRec.emailAddress;
|
|
374
|
+
conn.appData.screenname = userRec.emailAddress;
|
|
375
|
+
conn.appData.emailSecret = userRec.emailSecret;
|
|
376
|
+
conn.appData.urlToWatch = "";
|
|
377
|
+
kissOtherLogonsGoodnight (conn.appData.screenname, conn);
|
|
378
|
+
logToConsole (conn, conn.appData.lastVerb, conn.appData.screenname);
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
}
|
|
367
382
|
break;
|
|
368
383
|
|
|
369
384
|
}
|
|
@@ -389,6 +404,21 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
389
404
|
}
|
|
390
405
|
}
|
|
391
406
|
}
|
|
407
|
+
//s3 storage -- 2/14/23 by DW
|
|
408
|
+
|
|
409
|
+
function getS3FilePath (screenname, relpath, flprivate) {
|
|
410
|
+
const folder = (flprivate) ? config.privateFilesPath : config.publicFilesPath;
|
|
411
|
+
const f = folder + screenname + "/" + relpath;
|
|
412
|
+
const s3path = config.s3PathForStorage + f;
|
|
413
|
+
return (s3path);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function getFileFromS3 (screenname, relpath, flprivate, callback) {
|
|
417
|
+
s3.getObject (getS3FilePath (screenname, relpath, flprivate), callback);
|
|
418
|
+
}
|
|
419
|
+
function saveFileToS3 (screenname, relpath, type, flprivate, filetext, callback) {
|
|
420
|
+
s3.newObject (getS3FilePath (screenname, relpath, flprivate), filetext, type, acl, callback);
|
|
421
|
+
}
|
|
392
422
|
//storage functions
|
|
393
423
|
function getFilePath (screenname, relpath, flprivate) {
|
|
394
424
|
const folder = (flprivate) ? config.privateFilesPath : config.publicFilesPath;
|
|
@@ -418,35 +448,40 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
418
448
|
}
|
|
419
449
|
function publishFile (screenname, relpath, type, flprivate, filetext, callback) {
|
|
420
450
|
if (config.flStorageEnabled) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
config.publishFile (f, screenname, relpath, type, flprivate, filetext, url);
|
|
451
|
+
if (config.flUseS3ForStorage) {
|
|
452
|
+
saveFileToS3 (screenname, relpath, type, flprivate, filetext, callback);
|
|
453
|
+
}
|
|
454
|
+
else {
|
|
455
|
+
var f = getFilePath (screenname, relpath, flprivate);
|
|
456
|
+
utils.sureFilePath (f, function () {
|
|
457
|
+
var now = new Date ();
|
|
458
|
+
fs.writeFile (f, filetext, function (err) {
|
|
459
|
+
if (err) {
|
|
460
|
+
callback (err);
|
|
432
461
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
462
|
+
else {
|
|
463
|
+
var url = (flprivate) ? undefined : config.urlServerForClient + screenname + "/" + relpath;
|
|
464
|
+
if (config.publishFile !== undefined) { //3/18/22 by DW
|
|
465
|
+
config.publishFile (f, screenname, relpath, type, flprivate, filetext, url);
|
|
466
|
+
}
|
|
467
|
+
if (!flprivate) {
|
|
468
|
+
notifySocketSubscribers ("update", filetext, true, function (conn) { //3/6/2 by DW -- payload is a string
|
|
469
|
+
if (conn.appData.urlToWatch == url) {
|
|
470
|
+
return (true);
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
return (false);
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
callback (undefined, {
|
|
478
|
+
url,
|
|
479
|
+
whenLastUpdate: now
|
|
441
480
|
});
|
|
442
481
|
}
|
|
443
|
-
|
|
444
|
-
url,
|
|
445
|
-
whenLastUpdate: now
|
|
446
|
-
});
|
|
447
|
-
}
|
|
482
|
+
});
|
|
448
483
|
});
|
|
449
|
-
}
|
|
484
|
+
}
|
|
450
485
|
}
|
|
451
486
|
else {
|
|
452
487
|
callback ({message: "Can't publish the file because the feature is not enabled on the server."});
|
|
@@ -461,26 +496,31 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
461
496
|
callback (err);
|
|
462
497
|
}
|
|
463
498
|
if (config.flStorageEnabled) {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
499
|
+
if (config.flUseS3ForStorage) {
|
|
500
|
+
getFileFromS3 (screenname, relpath, flprivate, callback);
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
var f = getFilePath (screenname, relpath, flprivate);
|
|
504
|
+
fs.readFile (f, function (err, filetext) {
|
|
505
|
+
if (err) {
|
|
506
|
+
errcallback (err);
|
|
507
|
+
}
|
|
508
|
+
else {
|
|
509
|
+
fs.stat (f, function (err, stats) {
|
|
510
|
+
if (err) {
|
|
511
|
+
errcallback (err);
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
var data = {
|
|
515
|
+
filedata: filetext.toString (),
|
|
516
|
+
filestats: cleanFileStats (stats)
|
|
517
|
+
};
|
|
518
|
+
callback (undefined, data);
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
}
|
|
484
524
|
}
|
|
485
525
|
else {
|
|
486
526
|
callback ({message: "Can't publish the file because the feature is not enabled on the server."});
|
|
@@ -1305,7 +1345,21 @@ function startup (options, callback) {
|
|
|
1305
1345
|
}
|
|
1306
1346
|
else {
|
|
1307
1347
|
if ((params.emailaddress !== undefined) && (params.emailcode !== undefined)) {
|
|
1308
|
-
|
|
1348
|
+
config.isUserInDatabase (params.emailaddress, function (flInDatabase, userRec) {
|
|
1349
|
+
if (flInDatabase) {
|
|
1350
|
+
if (params.emailcode == userRec.emailSecret) {
|
|
1351
|
+
callback (params.emailaddress);
|
|
1352
|
+
}
|
|
1353
|
+
else {
|
|
1354
|
+
const message = "Can't do what you wanted the correct email authentication wasn't provided.";
|
|
1355
|
+
returnError ({message});
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
else {
|
|
1359
|
+
const message = "Can't do what you wanted because the email address isn't in the database.";
|
|
1360
|
+
returnError ({message});
|
|
1361
|
+
}
|
|
1362
|
+
});
|
|
1309
1363
|
}
|
|
1310
1364
|
else {
|
|
1311
1365
|
const message = "Can't do what you wanted because the call is missing email authentication.";
|
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.6.
|
|
4
|
+
"version": "0.6.15",
|
|
5
5
|
"main": "appserver.js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type" : "git",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"foldertojson": "*",
|
|
22
22
|
"davetwitter": "*",
|
|
23
23
|
"davezip": "*",
|
|
24
|
+
"daves3": "*",
|
|
24
25
|
"davehttp": "*",
|
|
25
26
|
"davemail": "*"
|
|
26
27
|
}
|