daveappserver 0.7.3 → 0.7.6
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 +135 -109
- package/package.json +1 -1
package/appserver.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var myVersion = "0.7.
|
|
1
|
+
var myVersion = "0.7.6", myProductName = "daveAppServer";
|
|
2
2
|
|
|
3
3
|
exports.start = startup;
|
|
4
4
|
exports.notifySocketSubscribers = notifySocketSubscribers;
|
|
@@ -478,44 +478,49 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
478
478
|
});
|
|
479
479
|
}
|
|
480
480
|
function publishFile (screenname, relpath, type, flprivate, filetext, callback) {
|
|
481
|
-
if (config.
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
config.publishFile (f, screenname, relpath, type, flprivate, filetext, url);
|
|
481
|
+
if (config.publishStaticFile !== undefined) { //9/20/23 by DW
|
|
482
|
+
config.publishStaticFile (screenname, relpath, type, flprivate, filetext, callback);
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
if (config.flStorageEnabled) {
|
|
486
|
+
if (config.flUseS3ForStorage) {
|
|
487
|
+
saveFileToS3 (screenname, relpath, type, flprivate, filetext, callback);
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
var f = getFilePath (screenname, relpath, flprivate);
|
|
491
|
+
utils.sureFilePath (f, function () {
|
|
492
|
+
var now = new Date ();
|
|
493
|
+
fs.writeFile (f, filetext, function (err) {
|
|
494
|
+
if (err) {
|
|
495
|
+
callback (err);
|
|
497
496
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
497
|
+
else {
|
|
498
|
+
var url = (flprivate) ? undefined : config.urlServerForClient + screenname + "/" + relpath;
|
|
499
|
+
if (config.publishFile !== undefined) { //3/18/22 by DW
|
|
500
|
+
config.publishFile (f, screenname, relpath, type, flprivate, filetext, url);
|
|
501
|
+
}
|
|
502
|
+
if (!flprivate) {
|
|
503
|
+
notifySocketSubscribers ("update", filetext, true, function (conn) { //3/6/2 by DW -- payload is a string
|
|
504
|
+
if (conn.appData.urlToWatch == url) {
|
|
505
|
+
return (true);
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
return (false);
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
callback (undefined, {
|
|
513
|
+
url,
|
|
514
|
+
whenLastUpdate: now
|
|
506
515
|
});
|
|
507
516
|
}
|
|
508
|
-
|
|
509
|
-
url,
|
|
510
|
-
whenLastUpdate: now
|
|
511
|
-
});
|
|
512
|
-
}
|
|
517
|
+
});
|
|
513
518
|
});
|
|
514
|
-
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
callback ({message: "Can't publish the file because the feature is not enabled on the server."});
|
|
515
523
|
}
|
|
516
|
-
}
|
|
517
|
-
else {
|
|
518
|
-
callback ({message: "Can't publish the file because the feature is not enabled on the server."});
|
|
519
524
|
}
|
|
520
525
|
}
|
|
521
526
|
function getFile (screenname, relpath, flprivate, callback) {
|
|
@@ -526,35 +531,50 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
526
531
|
}
|
|
527
532
|
callback (err);
|
|
528
533
|
}
|
|
529
|
-
|
|
530
|
-
if (config.
|
|
531
|
-
|
|
534
|
+
function getFromStaticFIlesystem () {
|
|
535
|
+
if (config.flStorageEnabled) {
|
|
536
|
+
if (config.flUseS3ForStorage) {
|
|
537
|
+
getFileFromS3 (screenname, relpath, flprivate, callback);
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
var f = getFilePath (screenname, relpath, flprivate);
|
|
541
|
+
fs.readFile (f, function (err, filetext) {
|
|
542
|
+
if (err) {
|
|
543
|
+
errcallback (err);
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
fs.stat (f, function (err, stats) {
|
|
547
|
+
if (err) {
|
|
548
|
+
errcallback (err);
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
var data = {
|
|
552
|
+
filedata: filetext.toString (),
|
|
553
|
+
filestats: cleanFileStats (stats)
|
|
554
|
+
};
|
|
555
|
+
callback (undefined, data);
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
}
|
|
532
561
|
}
|
|
533
562
|
else {
|
|
534
|
-
|
|
535
|
-
fs.readFile (f, function (err, filetext) {
|
|
536
|
-
if (err) {
|
|
537
|
-
errcallback (err);
|
|
538
|
-
}
|
|
539
|
-
else {
|
|
540
|
-
fs.stat (f, function (err, stats) {
|
|
541
|
-
if (err) {
|
|
542
|
-
errcallback (err);
|
|
543
|
-
}
|
|
544
|
-
else {
|
|
545
|
-
var data = {
|
|
546
|
-
filedata: filetext.toString (),
|
|
547
|
-
filestats: cleanFileStats (stats)
|
|
548
|
-
};
|
|
549
|
-
callback (undefined, data);
|
|
550
|
-
}
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
});
|
|
563
|
+
callback ({message: "Can't get the file because the feature is not enabled on the server."});
|
|
554
564
|
}
|
|
555
565
|
}
|
|
566
|
+
if (config.getStaticFile !== undefined) { //9/20/23 by DW
|
|
567
|
+
config.getStaticFile (screenname, relpath, flprivate, function (err, data) {
|
|
568
|
+
if (err) {
|
|
569
|
+
getFromStaticFIlesystem ();
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
callback (undefined, data);
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
}
|
|
556
576
|
else {
|
|
557
|
-
|
|
577
|
+
getFromStaticFIlesystem ();
|
|
558
578
|
}
|
|
559
579
|
}
|
|
560
580
|
function getFileList (screenname, flprivate, callback) {
|
|
@@ -1411,69 +1431,76 @@ function startup (options, callback) {
|
|
|
1411
1431
|
});
|
|
1412
1432
|
}
|
|
1413
1433
|
function returnServerHomePage () {
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
if (theRequest.addToPagetable !== undefined) { //3/9/21 by DW
|
|
1439
|
-
for (var x in theRequest.addToPagetable) {
|
|
1440
|
-
pagetable [x] = theRequest.addToPagetable [x];
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
if (config.addMacroToPagetable !== undefined) {
|
|
1444
|
-
config.addMacroToPagetable (pagetable, theRequest); //8/10/22 by DW
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
function replaceAllAndReturnHtml () {
|
|
1448
|
-
var pagetext = utils.multipleReplaceAll (templatetext.toString (), pagetable, false, "[%", "%]");
|
|
1449
|
-
returnHtml (pagetext);
|
|
1450
|
-
}
|
|
1451
|
-
if (config.asyncAddMacroToPagetable !== undefined) { //8/10/22 by DW
|
|
1452
|
-
config.asyncAddMacroToPagetable (pagetable, theRequest, function () {
|
|
1453
|
-
replaceAllAndReturnHtml ();
|
|
1434
|
+
var pagetable = {
|
|
1435
|
+
productName: config.productName,
|
|
1436
|
+
productNameForDisplay: config.productNameForDisplay,
|
|
1437
|
+
version: config.version,
|
|
1438
|
+
urlServerForClient: config.urlServerForClient,
|
|
1439
|
+
urlWebsocketServerForClient: config.urlWebsocketServerForClient,
|
|
1440
|
+
flEnableLogin: config.flEnableLogin,
|
|
1441
|
+
prefsPath: config.prefsPath,
|
|
1442
|
+
docsPath: config.docsPath,
|
|
1443
|
+
flUseTwitterIdentity: config.flUseTwitterIdentity, //2/6/23 by DW
|
|
1444
|
+
idGitHubClient: config.githubClientId, //11/9/21 by DW
|
|
1445
|
+
flWebsocketEnabled: config.flWebsocketEnabled, //2/8/23 by DW
|
|
1446
|
+
urlServerHomePageSource: config.urlServerHomePageSource, //9/16/23 by DW
|
|
1447
|
+
pathServerHomePageSource: config.pathServerHomePageSource //9/16/23 by DW
|
|
1448
|
+
};
|
|
1449
|
+
function getTemplateText (callback) {
|
|
1450
|
+
if (pagetable.pathServerHomePageSource !== undefined) {
|
|
1451
|
+
fs.readFile (pagetable.pathServerHomePageSource, function (err, templatetext) {
|
|
1452
|
+
if (err) {
|
|
1453
|
+
callback (err);
|
|
1454
|
+
}
|
|
1455
|
+
else {
|
|
1456
|
+
callback (undefined, templatetext);
|
|
1457
|
+
}
|
|
1454
1458
|
});
|
|
1455
1459
|
}
|
|
1456
1460
|
else {
|
|
1457
|
-
|
|
1461
|
+
request (pagetable.urlServerHomePageSource, function (err, response, templatetext) {
|
|
1462
|
+
if (err) {
|
|
1463
|
+
callback (err);
|
|
1464
|
+
}
|
|
1465
|
+
else {
|
|
1466
|
+
if ((response.statusCode >= 200) && (response.statusCode <= 299)) {
|
|
1467
|
+
callback (undefined, templatetext);
|
|
1468
|
+
}
|
|
1469
|
+
else {
|
|
1470
|
+
const message = "HTTP error == " + response.statusCode;
|
|
1471
|
+
callback ({message});
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
});
|
|
1458
1475
|
}
|
|
1459
1476
|
}
|
|
1460
|
-
|
|
1461
|
-
|
|
1477
|
+
function buildAndServeHomepage () {
|
|
1478
|
+
getTemplateText (function (err, templatetext) {
|
|
1462
1479
|
if (err) {
|
|
1463
|
-
|
|
1480
|
+
returnError (err);
|
|
1464
1481
|
}
|
|
1465
1482
|
else {
|
|
1466
|
-
|
|
1483
|
+
const pagetext = utils.multipleReplaceAll (templatetext.toString (), pagetable, false, "[%", "%]");
|
|
1484
|
+
returnHtml (pagetext);
|
|
1467
1485
|
}
|
|
1468
1486
|
});
|
|
1469
1487
|
}
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1488
|
+
if (theRequest.addToPagetable !== undefined) { //3/9/21 by DW
|
|
1489
|
+
for (var x in theRequest.addToPagetable) {
|
|
1490
|
+
pagetable [x] = theRequest.addToPagetable [x];
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
if (config.addMacroToPagetable !== undefined) {
|
|
1494
|
+
config.addMacroToPagetable (pagetable, theRequest); //8/10/22 by DW
|
|
1495
|
+
}
|
|
1496
|
+
if (config.asyncAddMacroToPagetable !== undefined) { //8/10/22 by DW
|
|
1497
|
+
config.asyncAddMacroToPagetable (pagetable, theRequest, function () {
|
|
1498
|
+
buildAndServeHomepage ();
|
|
1475
1499
|
});
|
|
1476
1500
|
}
|
|
1501
|
+
else {
|
|
1502
|
+
buildAndServeHomepage ();
|
|
1503
|
+
}
|
|
1477
1504
|
}
|
|
1478
1505
|
function callWithScreenname (callback) {
|
|
1479
1506
|
if (config.flUseTwitterIdentity) { //2/6/23 by DW
|
|
@@ -1784,7 +1811,6 @@ function startup (options, callback) {
|
|
|
1784
1811
|
}
|
|
1785
1812
|
}
|
|
1786
1813
|
|
|
1787
|
-
|
|
1788
1814
|
utils.copyScalars (options, config); //1/22/21 by DW
|
|
1789
1815
|
readConfigJson (function () { //readConfig (fnameConfig, config, true, function () { //anything can be overridden by config.json
|
|
1790
1816
|
readConfig (fnameStats, stats, false, function () {
|