Spaces:
Running
Running
Commit
·
e343169
1
Parent(s):
aa22602
improved welcome message
Browse files- myNodeServer.js +32 -45
myNodeServer.js
CHANGED
@@ -19,9 +19,11 @@ const OMNI_URL = 'http://127.0.0.1:1688'; // URL of the OMNITOOL service
|
|
19 |
const PROXY_PORT_OMNITOOL = 4444;
|
20 |
const CONTAINER_PORT_OMNITOOL = 1688;
|
21 |
const OMNITOOL_HEALTH_PING = '/api/v1/mercenaries/ping';
|
|
|
22 |
|
23 |
|
24 |
-
|
|
|
25 |
const OMNITOOL_SPACE_OWNER = 'manu-sapiens';
|
26 |
const HF_SPACE_URL = `https://huggingface.co/spaces/${OMNITOOL_SPACE_OWNER}/${OMNITOOL_SPACE_NAME}`;
|
27 |
const HF_SPACE_DUPLICATE_URL = `${HF_SPACE_URL}?duplicate=true`;
|
@@ -69,10 +71,10 @@ const COMMON_STYLES = `
|
|
69 |
display: inline-block;
|
70 |
background-color: #f0f0f0; /* Button color */
|
71 |
color: #000; /* Text color */
|
72 |
-
padding: 10px
|
73 |
text-align: center;
|
74 |
text-decoration: none;
|
75 |
-
border: 1px solid #
|
76 |
border-radius: 5px;
|
77 |
font-size: 16px;
|
78 |
cursor: pointer;
|
@@ -242,10 +244,6 @@ async function proxyRequest(req, res)
|
|
242 |
|
243 |
function getButtonsString(buttonsHTML)
|
244 |
{
|
245 |
-
// Add a button for the Hugging Face API call
|
246 |
-
const huggingFaceButton = '<button onclick="getHuggingFaceUserName()">Get Hugging Face User Name</button>';
|
247 |
-
|
248 |
-
|
249 |
// Message to display based on CONNECTED_TO_MASTER
|
250 |
let connectionStatusMessage;
|
251 |
if (global.CONNECTED_TO_MASTER)
|
@@ -259,23 +257,28 @@ function getButtonsString(buttonsHTML)
|
|
259 |
return `
|
260 |
<html>
|
261 |
<head>
|
262 |
-
<title>
|
263 |
${COMMON_STYLES}
|
264 |
</head>
|
265 |
<body>
|
266 |
-
<h1>
|
267 |
<p>Version: ${VERSION}</p>
|
268 |
-
<
|
269 |
-
<
|
270 |
-
<
|
271 |
-
<p
|
272 |
-
<p>
|
273 |
-
<p>
|
274 |
-
|
275 |
-
${
|
|
|
|
|
|
|
|
|
|
|
276 |
${buttonsHTML}
|
277 |
-
${huggingFaceButton}
|
278 |
${LOG_CONTAINER_HTML}
|
|
|
279 |
<script>
|
280 |
// Script to check Hugging Face login status and control 'Clone Repo' button
|
281 |
|
@@ -323,23 +326,6 @@ function getButtonsString(buttonsHTML)
|
|
323 |
element.scrollTop = element.scrollHeight;
|
324 |
}
|
325 |
|
326 |
-
// Function to handle the Hugging Face API call
|
327 |
-
function getHuggingFaceUserName() {
|
328 |
-
fetch('https://huggingface.co/api/whoami-v2')
|
329 |
-
.then(response => response.json())
|
330 |
-
.then(data => {
|
331 |
-
if(data && data.name) {
|
332 |
-
alert('Hugging Face User Name: ' + data.name);
|
333 |
-
} else {
|
334 |
-
alert('No name field in the response.');
|
335 |
-
}
|
336 |
-
})
|
337 |
-
.catch(error => {
|
338 |
-
console.error('Error fetching Hugging Face user name:', error);
|
339 |
-
alert('Error fetching data.');
|
340 |
-
});
|
341 |
-
}
|
342 |
-
|
343 |
startLogPolling();
|
344 |
</script>
|
345 |
</body>
|
@@ -363,7 +349,6 @@ async function handleGetRoot(req, res)
|
|
363 |
{
|
364 |
console.log('Omnitool server is not running');
|
365 |
let startButtonClass = '';
|
366 |
-
let cloneButtonClass = '';
|
367 |
if (!global.ALREADY_STARTING) startButtonClass = 'highlight-button';
|
368 |
const gotoButtonClass = '';
|
369 |
|
@@ -394,17 +379,17 @@ async function handleGetRoot(req, res)
|
|
394 |
proxyRequest(req, res);
|
395 |
}
|
396 |
|
397 |
-
function extractSpaceOwner(url, spaceName)
|
398 |
-
{
|
399 |
-
const regex = new RegExp(`^(?:https?:\\/\\/)?([^\\/]*?)-${spaceName}\\.hf\\.space\\/?$`);
|
400 |
-
const match = url.match(regex);
|
401 |
-
return match ? match[1] : null;
|
402 |
-
}
|
403 |
-
|
404 |
function setGlobals(req)
|
405 |
{
|
|
|
|
|
406 |
console.log(`Setting global using req.headers['host'] = ${req.headers['host']}`);
|
407 |
global.LOCAL_URL = req.headers['host'];
|
|
|
|
|
|
|
|
|
|
|
408 |
if (req.protocol === "https") global.PROTOCOL = 'https'; else global.PROTOCOL = 'http';
|
409 |
console.log(`global.LOCAL_URL = ${global.LOCAL_URL}\nglobal.PROTOCOL = ${global.PROTOCOL}`);
|
410 |
|
@@ -417,8 +402,10 @@ function setGlobals(req)
|
|
417 |
|
418 |
// New logic to set CONNECTED_TO_MASTER
|
419 |
global.CONNECTED_TO_MASTER = false;
|
420 |
-
|
421 |
-
|
|
|
|
|
422 |
|
423 |
if (global.SPACE_OWNER === OMNITOOL_SPACE_OWNER) { global.CONNECTED_TO_MASTER = true; }
|
424 |
console.log(`global.CONNECTED_TO_MASTER = ${global.CONNECTED_TO_MASTER}`);
|
|
|
19 |
const PROXY_PORT_OMNITOOL = 4444;
|
20 |
const CONTAINER_PORT_OMNITOOL = 1688;
|
21 |
const OMNITOOL_HEALTH_PING = '/api/v1/mercenaries/ping';
|
22 |
+
const FAVICON = 'https://github.com/omnitool-ai/omnitool/raw/main/packages/omni-ui/omni-web/public/favicon.jpg'
|
23 |
|
24 |
|
25 |
+
|
26 |
+
const OMNITOOL_SPACE_NAME = 'omnitool-test-3';
|
27 |
const OMNITOOL_SPACE_OWNER = 'manu-sapiens';
|
28 |
const HF_SPACE_URL = `https://huggingface.co/spaces/${OMNITOOL_SPACE_OWNER}/${OMNITOOL_SPACE_NAME}`;
|
29 |
const HF_SPACE_DUPLICATE_URL = `${HF_SPACE_URL}?duplicate=true`;
|
|
|
71 |
display: inline-block;
|
72 |
background-color: #f0f0f0; /* Button color */
|
73 |
color: #000; /* Text color */
|
74 |
+
padding: 5px 10px;
|
75 |
text-align: center;
|
76 |
text-decoration: none;
|
77 |
+
border: 1px solid #000;
|
78 |
border-radius: 5px;
|
79 |
font-size: 16px;
|
80 |
cursor: pointer;
|
|
|
244 |
|
245 |
function getButtonsString(buttonsHTML)
|
246 |
{
|
|
|
|
|
|
|
|
|
247 |
// Message to display based on CONNECTED_TO_MASTER
|
248 |
let connectionStatusMessage;
|
249 |
if (global.CONNECTED_TO_MASTER)
|
|
|
257 |
return `
|
258 |
<html>
|
259 |
<head>
|
260 |
+
<title>Omnitool</title>
|
261 |
${COMMON_STYLES}
|
262 |
</head>
|
263 |
<body>
|
264 |
+
<h1>Omnitool.ai on Hugging Face</h1>
|
265 |
<p>Version: ${VERSION}</p>
|
266 |
+
<div>Welcome to Omnitool.ai running on Hugging Face!</div>
|
267 |
+
<div>This is a fully functional version.</div>
|
268 |
+
<div>For more details visit us at <a href="https://omnitool.ai" target="_blank" class="button-like-link" id="duplicateRepoButton">omnitool.ai</a></div>
|
269 |
+
<p>-----------------------------------</p>
|
270 |
+
<p>This Space URL: ${global.LOCAL_URL}</p>
|
271 |
+
<p>This Space Owner: ${global.SPACE_OWNER}</p>
|
272 |
+
<p>Using REFERENCE Space: ${global.CONNECTED_TO_MASTER}</p>
|
273 |
+
<p>Omnitool SERVER Launched: ${global.ALREADY_STARTING}</p>
|
274 |
+
<p>Omnitool SERVER Ready: ${global.OMNITOOL_READY}</p>
|
275 |
+
<p>-----------------------------------</p>
|
276 |
+
<p></p>
|
277 |
+
${connectionStatusMessage}
|
278 |
+
<p></p>
|
279 |
${buttonsHTML}
|
|
|
280 |
${LOG_CONTAINER_HTML}
|
281 |
+
|
282 |
<script>
|
283 |
// Script to check Hugging Face login status and control 'Clone Repo' button
|
284 |
|
|
|
326 |
element.scrollTop = element.scrollHeight;
|
327 |
}
|
328 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
329 |
startLogPolling();
|
330 |
</script>
|
331 |
</body>
|
|
|
349 |
{
|
350 |
console.log('Omnitool server is not running');
|
351 |
let startButtonClass = '';
|
|
|
352 |
if (!global.ALREADY_STARTING) startButtonClass = 'highlight-button';
|
353 |
const gotoButtonClass = '';
|
354 |
|
|
|
379 |
proxyRequest(req, res);
|
380 |
}
|
381 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
382 |
function setGlobals(req)
|
383 |
{
|
384 |
+
|
385 |
+
|
386 |
console.log(`Setting global using req.headers['host'] = ${req.headers['host']}`);
|
387 |
global.LOCAL_URL = req.headers['host'];
|
388 |
+
|
389 |
+
// !!!!!!!!!
|
390 |
+
// TEST ONLY: global.LOCAL_URL = 'manu-sapiens-omnitool-test-3.hf.space/';
|
391 |
+
// !!!!!!!!!
|
392 |
+
|
393 |
if (req.protocol === "https") global.PROTOCOL = 'https'; else global.PROTOCOL = 'http';
|
394 |
console.log(`global.LOCAL_URL = ${global.LOCAL_URL}\nglobal.PROTOCOL = ${global.PROTOCOL}`);
|
395 |
|
|
|
402 |
|
403 |
// New logic to set CONNECTED_TO_MASTER
|
404 |
global.CONNECTED_TO_MASTER = false;
|
405 |
+
const recreated_string = `-${OMNITOOL_SPACE_NAME}.hf.space`;
|
406 |
+
// remove the protocol, a possible trailing / and the recreated string from the url
|
407 |
+
global.SPACE_OWNER = global.LOCAL_URL.replace(/\/$/, '').replace(recreated_string, '');
|
408 |
+
console.log(`global.SPACE_OWNER = ${global.SPACE_OWNER}`);
|
409 |
|
410 |
if (global.SPACE_OWNER === OMNITOOL_SPACE_OWNER) { global.CONNECTED_TO_MASTER = true; }
|
411 |
console.log(`global.CONNECTED_TO_MASTER = ${global.CONNECTED_TO_MASTER}`);
|