Spaces:
Running
Running
Commit
·
dab5564
1
Parent(s):
db72027
fixed mirroring issues
Browse files- hf_server.js +37 -27
- omnitool_init.sh +3 -0
hf_server.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* All rights reserved.
|
4 |
*/
|
5 |
//@ts-check
|
6 |
-
const VERSION = '0.6.0.hf.014.
|
7 |
|
8 |
const express = require('express');
|
9 |
const http = require('http');
|
@@ -28,7 +28,7 @@ const OMNITOOL_SPACE_URL = "omnitool-ai-omnitool-on-hf.hf.space";
|
|
28 |
const HF_SPACE_URL = "https://huggingface.co/spaces/omnitool-ai/omnitool_on_hf";
|
29 |
const HF_SPACE_DUPLICATE_URL = "https://huggingface.co/spaces/omnitool-ai/omnitool_on_hf?duplicate=true";
|
30 |
|
31 |
-
const sourceDir = '
|
32 |
const targetDir = '/data';
|
33 |
|
34 |
const DELAY_OMNITOOL_SET_TO_RUNNING = 2000; // 2 seconds
|
@@ -113,10 +113,13 @@ async function startOmnitoolServer()
|
|
113 |
global.logs.push(data.toString());
|
114 |
console.log(`omnitool stdout: ${data}`);
|
115 |
|
116 |
-
if (
|
117 |
{
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
120 |
}
|
121 |
|
122 |
});
|
@@ -308,11 +311,9 @@ function getButtonsString(buttonsHTML)
|
|
308 |
|
309 |
|
310 |
}
|
311 |
-
|
312 |
function exitIframe() {
|
313 |
-
fetch('/burst-iframe')
|
314 |
-
.then(response => response.json())
|
315 |
-
.then(data => window.open('/', '_blank'));
|
316 |
}
|
317 |
|
318 |
function startLogPolling() {
|
@@ -534,17 +535,20 @@ function startMirrorToDataDir()
|
|
534 |
});
|
535 |
|
536 |
watcher
|
537 |
-
.on('add', function(
|
538 |
-
if (
|
539 |
|
540 |
-
const targetFile =
|
541 |
-
//console.warn(`TargetFile = ${targetFile}. File ${
|
542 |
try {
|
543 |
-
|
|
|
544 |
if (err)
|
545 |
{
|
546 |
//throw err;
|
547 |
-
|
|
|
|
|
548 |
}});
|
549 |
}
|
550 |
catch(error)
|
@@ -552,17 +556,20 @@ function startMirrorToDataDir()
|
|
552 |
console.error(`WATCHER: error: ${error}`);
|
553 |
}
|
554 |
})
|
555 |
-
.on('change', function(
|
556 |
-
if (
|
557 |
-
|
558 |
-
const targetFile =
|
559 |
-
//console.warn(`TargetFile = ${targetFile}. File ${
|
560 |
try{
|
561 |
-
|
|
|
562 |
if (err)
|
563 |
{
|
564 |
//throw err;
|
565 |
-
|
|
|
|
|
566 |
}
|
567 |
});
|
568 |
}
|
@@ -572,18 +579,21 @@ function startMirrorToDataDir()
|
|
572 |
}
|
573 |
|
574 |
})
|
575 |
-
.on('unlink', function(
|
576 |
-
if (
|
577 |
|
578 |
-
const targetFile =
|
579 |
-
//console.warn(`TargetFile = ${targetFile}. File ${
|
580 |
try
|
581 |
{
|
|
|
582 |
fs.unlink(targetFile, (err) => {
|
583 |
if (err)
|
584 |
{
|
585 |
// throw err;
|
586 |
-
|
|
|
|
|
587 |
}
|
588 |
});
|
589 |
}
|
|
|
3 |
* All rights reserved.
|
4 |
*/
|
5 |
//@ts-check
|
6 |
+
const VERSION = '0.6.0.hf.014.m';
|
7 |
|
8 |
const express = require('express');
|
9 |
const http = require('http');
|
|
|
28 |
const HF_SPACE_URL = "https://huggingface.co/spaces/omnitool-ai/omnitool_on_hf";
|
29 |
const HF_SPACE_DUPLICATE_URL = "https://huggingface.co/spaces/omnitool-ai/omnitool_on_hf?duplicate=true";
|
30 |
|
31 |
+
const sourceDir = 'omnitool/packages/omni-server/data.local';
|
32 |
const targetDir = '/data';
|
33 |
|
34 |
const DELAY_OMNITOOL_SET_TO_RUNNING = 2000; // 2 seconds
|
|
|
113 |
global.logs.push(data.toString());
|
114 |
console.log(`omnitool stdout: ${data}`);
|
115 |
|
116 |
+
if (!global.OMNITOOL_RUNNING)
|
117 |
{
|
118 |
+
if (data.toString().includes(`Server has started and is ready to accept connections`))
|
119 |
+
{
|
120 |
+
console.log('Omnitool server started successfully');
|
121 |
+
setOmnitoolRunning(true);
|
122 |
+
}
|
123 |
}
|
124 |
|
125 |
});
|
|
|
311 |
|
312 |
|
313 |
}
|
314 |
+
|
315 |
function exitIframe() {
|
316 |
+
fetch('/burst-iframe').then(response => response.json()).then(data => {window.open('/', '_blank');});
|
|
|
|
|
317 |
}
|
318 |
|
319 |
function startLogPolling() {
|
|
|
535 |
});
|
536 |
|
537 |
watcher
|
538 |
+
.on('add', function(file_path) {
|
539 |
+
//if (file_path.includes('-journal') || file_path.includes('httpd.db')) return;
|
540 |
|
541 |
+
const targetFile = file_path.replace(sourceDir, targetDir);
|
542 |
+
//console.warn(`TargetFile = ${targetFile}. File ${file_path} added and copied from ${sourceDir} to ${targetDir}`);
|
543 |
try {
|
544 |
+
fsExtra.ensureDirSync(path.dirname(targetFile));
|
545 |
+
fs.copyFile(file_path, targetFile, (err) => {
|
546 |
if (err)
|
547 |
{
|
548 |
//throw err;
|
549 |
+
const error_message = `ERROR when doing: File ${file_path} added -> copied to ${targetFile}`;
|
550 |
+
console.log(error_message);
|
551 |
+
global.logs.push(error_message);
|
552 |
}});
|
553 |
}
|
554 |
catch(error)
|
|
|
556 |
console.error(`WATCHER: error: ${error}`);
|
557 |
}
|
558 |
})
|
559 |
+
.on('change', function(file_path) {
|
560 |
+
//if (file_path.includes('-journal') || file_path.includes('httpd.db')) return;
|
561 |
+
|
562 |
+
const targetFile = file_path.replace(sourceDir, targetDir);
|
563 |
+
//console.warn(`TargetFile = ${targetFile}. File ${file_path} changed and copied from ${sourceDir} to ${targetDir}`);
|
564 |
try{
|
565 |
+
fsExtra.ensureDirSync(path.dirname(targetFile));
|
566 |
+
fs.copyFile(file_path, targetFile, (err) => {
|
567 |
if (err)
|
568 |
{
|
569 |
//throw err;
|
570 |
+
const error_message = `ERROR when doing: File ${file_path} changed -> copied to ${targetFile}`;
|
571 |
+
console.log(error_message);
|
572 |
+
global.logs.push(error_message);
|
573 |
}
|
574 |
});
|
575 |
}
|
|
|
579 |
}
|
580 |
|
581 |
})
|
582 |
+
.on('unlink', function(file_path) {
|
583 |
+
//if (file_path.includes('-journal') || file_path.includes('httpd.db')) return;
|
584 |
|
585 |
+
const targetFile = file_path.replace(sourceDir, targetDir);
|
586 |
+
//console.warn(`TargetFile = ${targetFile}. File ${file_path} removed from ${targetDir}`);
|
587 |
try
|
588 |
{
|
589 |
+
fsExtra.ensureDirSync(path.dirname(targetFile));
|
590 |
fs.unlink(targetFile, (err) => {
|
591 |
if (err)
|
592 |
{
|
593 |
// throw err;
|
594 |
+
const error_message = `ERROR when doing: File ${file_path} has been removed from ${targetDir}`;
|
595 |
+
console.log(error_message);
|
596 |
+
global.logs.push(error_message);
|
597 |
}
|
598 |
});
|
599 |
}
|
omnitool_init.sh
CHANGED
@@ -28,6 +28,9 @@ fi
|
|
28 |
echo "[->] UPDATE OMNITOOL if needed"
|
29 |
cd ./omnitool
|
30 |
output=$(git pull)
|
|
|
|
|
|
|
31 |
if echo "$output" | grep -q "Already up to date."; then
|
32 |
echo "The repository is already up to date."
|
33 |
else
|
|
|
28 |
echo "[->] UPDATE OMNITOOL if needed"
|
29 |
cd ./omnitool
|
30 |
output=$(git pull)
|
31 |
+
|
32 |
+
mkdir -p ./data
|
33 |
+
|
34 |
if echo "$output" | grep -q "Already up to date."; then
|
35 |
echo "The repository is already up to date."
|
36 |
else
|