This repository was archived by the owner on Sep 24, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -36,12 +36,10 @@ document.addEventListener("readystatechange", () => {
36
36
payloadSizeDisplay . textContent = "{measure and fill json size in KB}" ;
37
37
dataFileContentDisplay . textContent = "{fill json}" ;
38
38
} ) ;
39
-
40
39
manualPullButton . addEventListener ( "click" , e => {
41
40
e . preventDefault ( ) ;
42
41
socket . emit ( "datafile-pull" , sdkKey , socketId ) ;
43
42
} ) ;
44
-
45
43
sdkKeyField . addEventListener ( "change" , e => {
46
44
console . log ( "Ignoring SDK" , sdkKey ) ;
47
45
socket . emit ( "ignoring-sdk-key" , sdkKey ) ;
@@ -61,15 +59,13 @@ const updatePayloadSize = obj => {
61
59
62
60
payloadSizeDisplay . textContent = `${ kb } KB` ;
63
61
} ;
64
-
65
62
const updateJsonDisplay = obj => {
66
63
const cleaned = JSON . stringify ( obj , null , 2 ) ;
67
64
68
65
dataFileContentDisplay . textContent = cleaned . replace ( / ^ [ \t ] * " [ ^ : \n \r ] + (?< ! \\ ) " : / gm, function ( match ) {
69
66
return match . replace ( / " / g, "" ) ;
70
67
} ) ;
71
68
} ;
72
-
73
69
const getSizeInBytes = obj => {
74
70
let str ;
75
71
if ( typeof obj === 'string' ) {
Original file line number Diff line number Diff line change @@ -19,7 +19,15 @@ const io = require("socket.io")(serverPort, {
19
19
const fs = require ( 'fs' ) ;
20
20
const readDataFileFromDisk = sdkKey => {
21
21
console . log ( "Reading datafile from disk" , sdkKey ) ;
22
- return JSON . parse ( fs . readFileSync ( `./datafiles/${ sdkKey } .json` ) . toString ( ) ) ;
22
+ const path = `./datafiles/${ sdkKey } .json` ;
23
+ if ( ! fs . existsSync ( path ) ) {
24
+ return ;
25
+ }
26
+ const buffer = fs . readFileSync ( path ) ;
27
+ if ( ! buffer ) {
28
+ return ;
29
+ }
30
+ return JSON . parse ( buffer . toString ( ) ) ;
23
31
} ;
24
32
25
33
const sendDataFile = ( dataFile , toClientId , toAllClientsWithSdkKey ) => {
@@ -49,7 +57,11 @@ io.on("connection", s => {
49
57
if ( isNullOrWhitespace ( sdkKey ) ) {
50
58
return ;
51
59
}
52
- sendDataFile ( readDataFileFromDisk ( sdkKey ) , socketId , null ) ;
60
+ const dataFile = readDataFileFromDisk ( sdkKey ) ;
61
+ if ( ! dataFile ) {
62
+ return ;
63
+ }
64
+ sendDataFile ( dataFile , socketId , null ) ;
53
65
} ) ;
54
66
} ) ;
55
67
You can’t perform that action at this time.
0 commit comments