typescriptified and also removed hardcoded addresses
This commit is contained in:
parent
61919ad094
commit
091744d75b
5 changed files with 42 additions and 18 deletions
|
@ -1,10 +1,14 @@
|
|||
import axios from "axios";
|
||||
|
||||
let accesstoken
|
||||
let windownameGlobal = ""
|
||||
|
||||
let accesstoken = ""
|
||||
onmessage = (event) => {
|
||||
const { action, access_token } = event.data
|
||||
const { action, access_token, windowname } = event.data
|
||||
accesstoken = access_token
|
||||
|
||||
windownameGlobal = windowname
|
||||
|
||||
if (action === "start") {
|
||||
fetchData()
|
||||
} else if (action === "terminate") {
|
||||
|
@ -14,9 +18,12 @@ onmessage = (event) => {
|
|||
|
||||
const fetchData = () => {
|
||||
|
||||
const apiURL = "http://localhost:5000/interstellar_ai/api/ai_get?access_token=" + accesstoken
|
||||
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_get?access_token=" + accesstoken)
|
||||
apiURL.hostname = windownameGlobal;
|
||||
|
||||
axios.get(apiURL)
|
||||
console.log(apiURL.href)
|
||||
|
||||
axios.get(apiURL.href)
|
||||
.then(response => {
|
||||
const data = response.data
|
||||
postMessage(data)
|
|
@ -1,7 +1,7 @@
|
|||
import axios from "axios";
|
||||
|
||||
onmessage = (e) => {
|
||||
const { messages, ai_model, model_type, access_token, api_key } = e.data
|
||||
const { messages, ai_model, model_type, access_token, api_key, windowname } = e.data
|
||||
|
||||
|
||||
const Message = {
|
||||
|
@ -12,7 +12,13 @@ onmessage = (e) => {
|
|||
api_key: api_key
|
||||
}
|
||||
|
||||
axios.post("http://localhost:5000/interstellar_ai/api/ai_send", Message)
|
||||
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_send")
|
||||
console.log(windowname)
|
||||
apiURL.hostname = windowname;
|
||||
|
||||
console.log(apiURL.href)
|
||||
|
||||
axios.post(apiURL.href, Message)
|
||||
.then(response => {
|
||||
const status = response.data.status
|
||||
postMessage({ status })
|
Loading…
Add table
Add a link
Reference in a new issue