This commit is contained in:
YasinOnm08 2024-10-07 11:16:51 +02:00
parent 2e67f911c1
commit 0f610d3c18
11 changed files with 408 additions and 288 deletions

View file

@ -2,7 +2,7 @@
export const getAllLocalStorageItems = (): Record<string, string | null> => {
const allData: Record<string, string | null> = {};
if (typeof localStorage !== 'undefined') {
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key) {
@ -10,6 +10,7 @@ export const getAllLocalStorageItems = (): Record<string, string | null> => {
allData[key] = value;
}
}
}
return allData;
};

View file

@ -20,23 +20,25 @@ const InputOutputBackend: React.FC = () => {
const [timeZone, setTimeZone] = useState<string>("GMT");
const [dateFormat, setDateFormat] = useState<string>("DD-MM-YYYY");
const [messages, setMessages] = useState<Message[]>([]);
const [myBoolean, setMyBoolean] = useState<boolean>(() => localStorage.getItem('myBoolean') === 'true') || false;
const [myBoolean, setMyBoolean] = useState<boolean>(false);
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_create")
apiURL.hostname = window.location.hostname;
// Fetch local storage values and update state on component mount
useEffect(() => {
setPreferredCurrency(localStorage.getItem("preferredCurrency") || "USD");
setPreferredLanguage(localStorage.getItem("preferredLanguage") || "english");
setTimeFormat(localStorage.getItem("timeFormat") || "24-hour");
setPreferredMeasurement(localStorage.getItem("preferredMeasurement") || "metric");
setTimeZone(localStorage.getItem("timeZone") || "GMT");
setDateFormat(localStorage.getItem("dateFormat") || "DD-MM-YYYY");
setMyBoolean(localStorage.getItem('myBoolean') === 'true');
}, []);
if (typeof window !== 'undefined') {
apiURL.hostname = window.location.hostname;
} else {
apiURL.hostname = "localhost"
}
// Update messages when any of the settings change
useEffect(() => {
if (typeof localStorage !== 'undefined') {
setPreferredCurrency(localStorage.getItem("preferredCurrency") || "USD");
setPreferredLanguage(localStorage.getItem("preferredLanguage") || "english");
setTimeFormat(localStorage.getItem("timeFormat") || "24-hour");
setPreferredMeasurement(localStorage.getItem("preferredMeasurement") || "metric");
setTimeZone(localStorage.getItem("timeZone") || "GMT");
setDateFormat(localStorage.getItem("dateFormat") || "DD-MM-YYYY");
setMyBoolean(localStorage.getItem('myBoolean') === 'true');
}
const measurementString = (preferredMeasurement == "Metric")
? "All measurements follow the metric system. Refuse to use any other measurement system."
: "All measurements follow the imperial system. Refuse to use any other measurement system.";
@ -113,7 +115,12 @@ const InputOutputBackend: React.FC = () => {
if (!getWorkerRef.current) {
getWorkerRef.current = new Worker(new URL("./threads/GetWorker.ts", import.meta.url))
const windowname = window.location.hostname
let windowname = "localhost"
if (typeof window !== 'undefined') {
windowname = window.location.hostname
} else {
windowname = "localhost"
}
getWorkerRef.current.postMessage({ action: "start", access_token: accessToken, windowname })
@ -169,12 +176,15 @@ const InputOutputBackend: React.FC = () => {
setInputDisabled(true)
if (postWorkerRef.current) {
addMessage("user", inputValue)
const type = localStorage.getItem('type')
let type:string = "local"
let api_key: string = ""
if (type != null && type != 'local') {
const try_key = localStorage.getItem(type)
if (try_key) {
api_key = try_key
if (typeof localStorage !== 'undefined') {
type = localStorage.getItem('type') || "local"
if (type != null && type != 'local') {
const try_key = localStorage.getItem(type)
if (try_key) {
api_key = try_key
}
}
}
setInputMessage("")

View file

@ -125,9 +125,11 @@ export const checkCredentials = async (usernameOrEmail: string, password: string
};
const sendBack = await sendToDatabase(data);
if (sendBack) {
localStorage.setItem("accountEmail", await getEmail(usernameOrEmail, password))
localStorage.setItem("accountName", await getName(usernameOrEmail, password))
localStorage.setItem("accountPassword", password)
if (typeof localStorage !== 'undefined') {
localStorage.setItem("accountEmail", await getEmail(usernameOrEmail, password))
localStorage.setItem("accountName", await getName(usernameOrEmail, password))
localStorage.setItem("accountPassword", password)
}
}
return sendBack
};

View file

@ -6,7 +6,11 @@ export const sendToVoiceRecognition = (audio_data: Blob): Promise<string> => {
formdata.append("audio", audio_data)
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/voice_recognition")
apiURL.hostname = window.location.hostname;
if (typeof window !== 'undefined') {
apiURL.hostname = window.location.hostname;
} else {
apiURL.hostname = "localhost"
}
return axios.post(apiURL.href, formdata)
.then((response) => {