daveappserver 0.6.14 → 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 +72 -46
- 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
|
|
@@ -403,6 +404,21 @@ 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
|
+
s3.newObject (getS3FilePath (screenname, relpath, flprivate), filetext, type, acl, callback);
|
|
421
|
+
}
|
|
406
422
|
//storage functions
|
|
407
423
|
function getFilePath (screenname, relpath, flprivate) {
|
|
408
424
|
const folder = (flprivate) ? config.privateFilesPath : config.publicFilesPath;
|
|
@@ -432,35 +448,40 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
432
448
|
}
|
|
433
449
|
function publishFile (screenname, relpath, type, flprivate, filetext, callback) {
|
|
434
450
|
if (config.flStorageEnabled) {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
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);
|
|
446
461
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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
|
|
455
480
|
});
|
|
456
481
|
}
|
|
457
|
-
|
|
458
|
-
url,
|
|
459
|
-
whenLastUpdate: now
|
|
460
|
-
});
|
|
461
|
-
}
|
|
482
|
+
});
|
|
462
483
|
});
|
|
463
|
-
}
|
|
484
|
+
}
|
|
464
485
|
}
|
|
465
486
|
else {
|
|
466
487
|
callback ({message: "Can't publish the file because the feature is not enabled on the server."});
|
|
@@ -475,26 +496,31 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
475
496
|
callback (err);
|
|
476
497
|
}
|
|
477
498
|
if (config.flStorageEnabled) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
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
|
+
}
|
|
498
524
|
}
|
|
499
525
|
else {
|
|
500
526
|
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.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
|
}
|