typescriptified and also removed hardcoded addresses
This commit is contained in:
parent
61919ad094
commit
091744d75b
5 changed files with 42 additions and 18 deletions
37
app/backend/threads/GetWorker.ts
Normal file
37
app/backend/threads/GetWorker.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import axios from "axios";
|
||||
|
||||
let windownameGlobal = ""
|
||||
|
||||
let accesstoken = ""
|
||||
onmessage = (event) => {
|
||||
const { action, access_token, windowname } = event.data
|
||||
accesstoken = access_token
|
||||
|
||||
windownameGlobal = windowname
|
||||
|
||||
if (action === "start") {
|
||||
fetchData()
|
||||
} else if (action === "terminate") {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const fetchData = () => {
|
||||
|
||||
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_get?access_token=" + accesstoken)
|
||||
apiURL.hostname = windownameGlobal;
|
||||
|
||||
console.log(apiURL.href)
|
||||
|
||||
axios.get(apiURL.href)
|
||||
.then(response => {
|
||||
const data = response.data
|
||||
postMessage(data)
|
||||
setTimeout(fetchData, 100)
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('Error fetching data:', error);
|
||||
postMessage({ error: "failed fetching data" })
|
||||
setTimeout(() => fetchData(), 1000)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue