manu-sapiens commited on
Commit
6b9468a
·
1 Parent(s): 9484eef

fixed issue with the /?isVisited=true call

Browse files
Files changed (1) hide show
  1. hf_server.js +92 -79
hf_server.js CHANGED
@@ -3,7 +3,7 @@
3
  * All rights reserved.
4
  */
5
  //@ts-check
6
- const VERSION = '0.6.0.hf.015.c';
7
 
8
  const express = require('express');
9
  const http = require('http');
@@ -98,88 +98,95 @@ const COMMON_STYLES =
98
  }
99
  </style>`;
100
 
101
- const SCRIPTS =
102
- `<script>
103
- // Script to check Hugging Face login status and control 'Clone Repo' button
104
 
105
- function startServer() {
106
- document.getElementById('startServerButton').classList.remove
107
- ('highlight-button-green');
108
- document.getElementById('startServerButton').disabled = true;
109
 
 
 
 
 
110
 
111
- fetch('/start-omnitool-server')
112
- .then(response => response.json())
113
- .then(data => startLogPolling());
114
 
115
-
116
- }
117
-
118
- function exitIframe() {
119
- if (window.self !== window.top)
120
- {
121
- // open a new window to get out of the iframe, then wait 1s, then fetch burst-iframe then reload
122
- window.open(${global.LOCAL_URL}+"?isVisited=true", '_blank');
123
- }
124
- else
125
- {
126
- fetch('/burst-iframe').then(response => response.json()).then(data => {window.location.reload();});
127
- }
128
- }
129
 
130
- function refreshPage() {
131
- window.location.reload();
132
- }
 
 
 
 
 
 
 
 
 
 
 
133
 
134
- function startLogPolling() {
135
-
136
- const interval = setInterval(() => {
137
- fetch('/omnitool-logs')
138
- .then(response => response.json())
139
- .then(data => {
140
- const logContainer = document.getElementById('logContainer');
141
- logContainer.innerText = data.logs.join("");
142
- if (data.ready) {
143
-
144
- scrollToBottom(logContainer);
145
- document.getElementById('refreshButton').disabled = false;
146
- document.getElementById('refreshButton').classList.add('highlight-button');
147
- clearInterval(interval);
148
-
149
- }
150
- else {
151
- scrollToBottom(logContainer);
152
- }
153
- });
154
- }, 500);
155
-
156
- const interval2 = setInterval(() => {
157
- fetch('/omnitool-logs')
158
- .then(response => response.json())
159
- .then(data => {
160
- const logContainer = document.getElementById('logContainer');
161
- logContainer.innerText = data.logs.join("");
162
- if (data.ready) {
163
-
164
- scrollToBottom(logContainer);
165
- document.getElementById('refreshButton').disabled = false;
166
- document.getElementById('refreshButton').classList.add('highlight-button');
167
- clearInterval(interval);
168
-
169
- }
170
- else {
171
- scrollToBottom(logContainer);
172
- }
173
- });
174
- }, 500);
175
- }
176
 
177
- function scrollToBottom(element) {
178
- element.scrollTop = element.scrollHeight;
179
- }
180
-
181
- startLogPolling();
182
- </script>`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
 
184
  const INTRO_MESSAGE =
185
  `<h1>Omnitool.ai on Hugging Face</h1>
@@ -289,7 +296,7 @@ async function checkOmnitoolStatus()
289
  }
290
  } catch (error)
291
  {
292
- console.log('Please press [CREATE Omnitool Server] button');
293
  setOmnitoolRunning(false);
294
  }
295
  }
@@ -380,6 +387,8 @@ async function handleGetRoot(req, res)
380
  page_message += `<div>DUPLICATING and using your own SPACE is FREE. You can do it by pressing this button: <a href="${HF_SPACE_DUPLICATE_URL}" target="_blank" class="button-like-link" id="duplicateRepoButton">DUPLICATE SPACE</a></div><div>However, consider choosing the 20 Gig Storage option (~ 5 USD/month) to persist keys, recipes and outputs between server restarts.</div>`;
381
  page_message += '<p></p>';
382
 
 
 
383
  let buttonsHTML = `
384
  <a href="${HF_SPACE_DUPLICATE_URL}" target="_blank" class="button-like-link" id="duplicateRepoButton">DUPLICATE SPACE</a>`;
385
 
@@ -398,6 +407,8 @@ async function handleGetRoot(req, res)
398
  </body>
399
  </html>`;
400
 
 
 
401
  res.writeHead(200, { 'Content-Type': 'text/html' });
402
  res.end(page_html);
403
  return;
@@ -416,7 +427,7 @@ async function handleGetRoot(req, res)
416
  let buttons_html = `
417
  <button id="exitIframeButton" class="${gotoButtonClass}" onclick="exitIframe()">START</button>
418
  `;
419
-
420
  const page_html = `
421
  <html>
422
  <head>
@@ -432,7 +443,7 @@ async function handleGetRoot(req, res)
432
  </body>
433
  </html>
434
  `;
435
-
436
  res.writeHead(200, { 'Content-Type': 'text/html' });
437
  res.end(page_html);
438
  return;
@@ -451,6 +462,7 @@ async function handleGetRoot(req, res)
451
  <button id="refreshButton" class="${''}" disabled onclick="refreshPage()">REFRESH</button>
452
  `;
453
 
 
454
  const page_html = `
455
  <html>
456
  <head>
@@ -468,6 +480,7 @@ async function handleGetRoot(req, res)
468
  </html>
469
  `;
470
 
 
471
  res.writeHead(200, { 'Content-Type': 'text/html' });
472
  res.end(page_html);
473
  return;
 
3
  * All rights reserved.
4
  */
5
  //@ts-check
6
+ const VERSION = '0.6.0.hf.015.d';
7
 
8
  const express = require('express');
9
  const http = require('http');
 
98
  }
99
  </style>`;
100
 
101
+ function getScriptsHtml(url)
102
+ {
 
103
 
104
+ const scripts_html =
105
+ `<script>
106
+ // Script to check Hugging Face login status and control 'Clone Repo' button
 
107
 
108
+ function startServer() {
109
+ document.getElementById('startServerButton').classList.remove
110
+ ('highlight-button-green');
111
+ document.getElementById('startServerButton').disabled = true;
112
 
 
 
 
113
 
114
+ fetch('/start-omnitool-server')
115
+ .then(response => response.json())
116
+ .then(data => startLogPolling());
 
 
 
 
 
 
 
 
 
 
 
117
 
118
+
119
+ }
120
+
121
+ function exitIframe() {
122
+ if (window.self !== window.top)
123
+ {
124
+ // open a new window to get out of the iframe, then wait 1s, then fetch burst-iframe then reload
125
+ window.open("${global.PROTOCOL}://${global.LOCAL_URL}/?isVisited=true", '_blank');
126
+ }
127
+ else
128
+ {
129
+ fetch('/burst-iframe').then(response => response.json()).then(data => {window.location.reload();});
130
+ }
131
+ }
132
 
133
+ function refreshPage() {
134
+ window.location.reload();
135
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
 
137
+ function startLogPolling() {
138
+
139
+ const interval = setInterval(() => {
140
+ fetch('/omnitool-logs')
141
+ .then(response => response.json())
142
+ .then(data => {
143
+ const logContainer = document.getElementById('logContainer');
144
+ logContainer.innerText = data.logs.join("");
145
+ if (data.ready) {
146
+
147
+ scrollToBottom(logContainer);
148
+ document.getElementById('refreshButton').disabled = false;
149
+ document.getElementById('refreshButton').classList.add('highlight-button');
150
+ clearInterval(interval);
151
+
152
+ }
153
+ else {
154
+ scrollToBottom(logContainer);
155
+ }
156
+ });
157
+ }, 500);
158
+
159
+ const interval2 = setInterval(() => {
160
+ fetch('/omnitool-logs')
161
+ .then(response => response.json())
162
+ .then(data => {
163
+ const logContainer = document.getElementById('logContainer');
164
+ logContainer.innerText = data.logs.join("");
165
+ if (data.ready) {
166
+
167
+ scrollToBottom(logContainer);
168
+ document.getElementById('refreshButton').disabled = false;
169
+ document.getElementById('refreshButton').classList.add('highlight-button');
170
+ clearInterval(interval);
171
+
172
+ }
173
+ else {
174
+ scrollToBottom(logContainer);
175
+ }
176
+ });
177
+ }, 500);
178
+ }
179
+
180
+ function scrollToBottom(element) {
181
+ element.scrollTop = element.scrollHeight;
182
+ }
183
+
184
+ startLogPolling();
185
+ </script>`;
186
+
187
+ console.log(`scripts_html = ${scripts_html}`);
188
+ return scripts_html;
189
+ }
190
 
191
  const INTRO_MESSAGE =
192
  `<h1>Omnitool.ai on Hugging Face</h1>
 
296
  }
297
  } catch (error)
298
  {
299
+ console.log('Please press [START] button');
300
  setOmnitoolRunning(false);
301
  }
302
  }
 
387
  page_message += `<div>DUPLICATING and using your own SPACE is FREE. You can do it by pressing this button: <a href="${HF_SPACE_DUPLICATE_URL}" target="_blank" class="button-like-link" id="duplicateRepoButton">DUPLICATE SPACE</a></div><div>However, consider choosing the 20 Gig Storage option (~ 5 USD/month) to persist keys, recipes and outputs between server restarts.</div>`;
388
  page_message += '<p></p>';
389
 
390
+ const SCRIPTS = getScriptsHtml();
391
+
392
  let buttonsHTML = `
393
  <a href="${HF_SPACE_DUPLICATE_URL}" target="_blank" class="button-like-link" id="duplicateRepoButton">DUPLICATE SPACE</a>`;
394
 
 
407
  </body>
408
  </html>`;
409
 
410
+ console.log(`page_html = ${page_html}`);
411
+
412
  res.writeHead(200, { 'Content-Type': 'text/html' });
413
  res.end(page_html);
414
  return;
 
427
  let buttons_html = `
428
  <button id="exitIframeButton" class="${gotoButtonClass}" onclick="exitIframe()">START</button>
429
  `;
430
+ const SCRIPTS = getScriptsHtml();
431
  const page_html = `
432
  <html>
433
  <head>
 
443
  </body>
444
  </html>
445
  `;
446
+ console.log(`page_html = ${page_html}`);
447
  res.writeHead(200, { 'Content-Type': 'text/html' });
448
  res.end(page_html);
449
  return;
 
462
  <button id="refreshButton" class="${''}" disabled onclick="refreshPage()">REFRESH</button>
463
  `;
464
 
465
+ const SCRIPTS = getScriptsHtml();
466
  const page_html = `
467
  <html>
468
  <head>
 
480
  </html>
481
  `;
482
 
483
+ console.log(`page_html = ${page_html}`);
484
  res.writeHead(200, { 'Content-Type': 'text/html' });
485
  res.end(page_html);
486
  return;