daveappserver 0.6.14 → 0.6.16
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 +73 -46
- package/package.json +2 -1
package/appserver.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var myVersion = "0.6.
|
|
1
|
+
var myVersion = "0.6.16", 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
|
|
@@ -403,6 +404,22 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
403
404
|
}
|
|
404
405
|
}
|
|
405
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
|
+
const acl = undefined; //use the default
|
|
421
|
+
s3.newObject (getS3FilePath (screenname, relpath, flprivate), filetext, type, acl, callback);
|
|
422
|
+
}
|
|
406
423
|
//storage functions
|
|
407
424
|
function getFilePath (screenname, relpath, flprivate) {
|
|
408
425
|
const folder = (flprivate) ? config.privateFilesPath : config.publicFilesPath;
|
|
@@ -432,35 +449,40 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
432
449
|
}
|
|
433
450
|
function publishFile (screenname, relpath, type, flprivate, filetext, callback) {
|
|
434
451
|
if (config.flStorageEnabled) {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
config.publishFile (f, screenname, relpath, type, flprivate, filetext, url);
|
|
452
|
+
if (config.flUseS3ForStorage) {
|
|
453
|
+
saveFileToS3 (screenname, relpath, type, flprivate, filetext, callback);
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
var f = getFilePath (screenname, relpath, flprivate);
|
|
457
|
+
utils.sureFilePath (f, function () {
|
|
458
|
+
var now = new Date ();
|
|
459
|
+
fs.writeFile (f, filetext, function (err) {
|
|
460
|
+
if (err) {
|
|
461
|
+
callback (err);
|
|
446
462
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
463
|
+
else {
|
|
464
|
+
var url = (flprivate) ? undefined : config.urlServerForClient + screenname + "/" + relpath;
|
|
465
|
+
if (config.publishFile !== undefined) { //3/18/22 by DW
|
|
466
|
+
config.publishFile (f, screenname, relpath, type, flprivate, filetext, url);
|
|
467
|
+
}
|
|
468
|
+
if (!flprivate) {
|
|
469
|
+
notifySocketSubscribers ("update", filetext, true, function (conn) { //3/6/2 by DW -- payload is a string
|
|
470
|
+
if (conn.appData.urlToWatch == url) {
|
|
471
|
+
return (true);
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
return (false);
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
callback (undefined, {
|
|
479
|
+
url,
|
|
480
|
+
whenLastUpdate: now
|
|
455
481
|
});
|
|
456
482
|
}
|
|
457
|
-
|
|
458
|
-
url,
|
|
459
|
-
whenLastUpdate: now
|
|
460
|
-
});
|
|
461
|
-
}
|
|
483
|
+
});
|
|
462
484
|
});
|
|
463
|
-
}
|
|
485
|
+
}
|
|
464
486
|
}
|
|
465
487
|
else {
|
|
466
488
|
callback ({message: "Can't publish the file because the feature is not enabled on the server."});
|
|
@@ -475,26 +497,31 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
475
497
|
callback (err);
|
|
476
498
|
}
|
|
477
499
|
if (config.flStorageEnabled) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
500
|
+
if (config.flUseS3ForStorage) {
|
|
501
|
+
getFileFromS3 (screenname, relpath, flprivate, callback);
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
var f = getFilePath (screenname, relpath, flprivate);
|
|
505
|
+
fs.readFile (f, function (err, filetext) {
|
|
506
|
+
if (err) {
|
|
507
|
+
errcallback (err);
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
fs.stat (f, function (err, stats) {
|
|
511
|
+
if (err) {
|
|
512
|
+
errcallback (err);
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
var data = {
|
|
516
|
+
filedata: filetext.toString (),
|
|
517
|
+
filestats: cleanFileStats (stats)
|
|
518
|
+
};
|
|
519
|
+
callback (undefined, data);
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}
|
|
498
525
|
}
|
|
499
526
|
else {
|
|
500
527
|
callback ({message: "Can't publish the file because the feature is not enabled on the server."});
|
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.16",
|
|
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
|
}
|