manu-sapiens commited on
Commit
8b08965
·
1 Parent(s): 6244632

delaying mirroring to when omnitool is ready

Browse files
Files changed (1) hide show
  1. hf_server.js +40 -1
hf_server.js CHANGED
@@ -3,7 +3,7 @@
3
  * All rights reserved.
4
  */
5
  //@ts-check
6
- const VERSION = '0.6.0.hf.014.c';
7
 
8
  const express = require('express');
9
  const http = require('http');
@@ -159,6 +159,10 @@ function setOmnitoolRunning(set_running)
159
  console.log('Omnitool server is RUNNING! ');
160
  global.OMNITOOL_RUNNING = true;
161
  }, DELAY_OMNITOOL_SET_TO_RUNNING); // Delay by 2 second
 
 
 
 
162
  }
163
 
164
  }
@@ -231,6 +235,7 @@ async function handleGetBurstIframe(req, res)
231
 
232
  const reply = { burst_iframe: true };
233
  res.end(JSON.stringify(reply));
 
234
  return;
235
  }
236
 
@@ -447,6 +452,40 @@ function omnitoolProxyMiddleware(req, res, next)
447
  }
448
  }
449
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
450
 
451
  async function main(app)
452
  {
 
3
  * All rights reserved.
4
  */
5
  //@ts-check
6
+ const VERSION = '0.6.0.hf.014.d';
7
 
8
  const express = require('express');
9
  const http = require('http');
 
159
  console.log('Omnitool server is RUNNING! ');
160
  global.OMNITOOL_RUNNING = true;
161
  }, DELAY_OMNITOOL_SET_TO_RUNNING); // Delay by 2 second
162
+
163
+ // start mirroring to /data when the server is running
164
+ startMirrorToDataDir();
165
+
166
  }
167
 
168
  }
 
235
 
236
  const reply = { burst_iframe: true };
237
  res.end(JSON.stringify(reply));
238
+
239
  return;
240
  }
241
 
 
452
  }
453
  }
454
 
455
+ function startMirrorToDataDir()
456
+ {
457
+ if (!fs.existsSync(targetDir)) return;
458
+
459
+ const watcher = chokidar.watch(sourceDir, {
460
+ ignored: /[\/\\]\./,
461
+ persistent: true
462
+ });
463
+
464
+ watcher
465
+ .on('add', function(path) {
466
+ const targetFile = path.replace(sourceDir, targetDir);
467
+ fs.copyFile(path, targetFile, (err) => {
468
+ if (err) throw err;
469
+ console.log('File', path, 'has been added and copied to', targetFile);
470
+ });
471
+ })
472
+ .on('change', function(path) {
473
+ const targetFile = path.replace(sourceDir, targetDir);
474
+ fs.copyFile(path, targetFile, (err) => {
475
+ if (err) throw err;
476
+ console.log('File', path, 'has been changed and copied to', targetFile);
477
+ });
478
+ })
479
+ .on('unlink', function(path) {
480
+ const targetFile = path.replace(sourceDir, targetDir);
481
+ fs.unlink(targetFile, (err) => {
482
+ if (err) throw err;
483
+ console.log('File', path, 'has been removed');
484
+ });
485
+ });
486
+
487
+ return watcher;
488
+ }
489
 
490
  async function main(app)
491
  {