forked from React-Group/interstellar_ai
Merge branch 'main' into main
This commit is contained in:
commit
219b301d62
8 changed files with 164 additions and 81 deletions
|
@ -40,7 +40,8 @@ python3 api.py
|
|||
```
|
||||
3. In the main project folder, you will run:
|
||||
```
|
||||
npm run dev
|
||||
npm run build
|
||||
npm start
|
||||
npx electron .
|
||||
```
|
||||
4. Open http://localhost:3000/ in your browser.
|
||||
5. Enjoy!
|
||||
4. Enjoy!
|
|
@ -5,6 +5,7 @@ import {
|
|||
getSettings
|
||||
} from '../backend/database';
|
||||
import Settings from './settings/Settings'; // Import the Settings component
|
||||
import { importDatabase } from './settings/settingUtils';
|
||||
|
||||
const Login: React.FC = () => {
|
||||
// State to handle popup visibility
|
||||
|
@ -40,6 +41,14 @@ const Login: React.FC = () => {
|
|||
if (savedAccountName !== null && savedAccountPassword !== null) {
|
||||
const success = await checkCredentials(savedAccountName, savedAccountPassword);
|
||||
setIsLoggedIn(success); // Automatically log in
|
||||
const useName = localStorage.getItem("accountName");
|
||||
const usePassword = localStorage.getItem("accountPassword");
|
||||
|
||||
if (useName && usePassword) {
|
||||
await importDatabase(useName, usePassword);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
check();
|
||||
|
@ -69,6 +78,14 @@ const Login: React.FC = () => {
|
|||
}
|
||||
}
|
||||
setShowLoginPopup(false); // Close the login popup
|
||||
const useName = localStorage.getItem("accountName");
|
||||
const usePassword = localStorage.getItem("accountPassword");
|
||||
|
||||
if (useName && usePassword) {
|
||||
await importDatabase(useName, usePassword);
|
||||
}
|
||||
|
||||
window.location.reload();
|
||||
} else {
|
||||
alert('Incorrect credentials');
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//#region imports
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { applyTheme } from './theme';
|
||||
import { exportSettings, importSettings } from './settingUtils'; // Import utility functions
|
||||
import { exportSettings, importSettings, sendToDatabase, importDatabase } from './settingUtils'; // Import utility functions
|
||||
import { getAllLocalStorageItems } from '../../backend/GetLocalStorage';
|
||||
import ColorSetting from './ColorSettings';
|
||||
import TextSettings from './TextSettings'
|
||||
|
@ -15,8 +15,6 @@ import {
|
|||
changeSettings,
|
||||
createAccount,
|
||||
deleteAccount,
|
||||
getSettings,
|
||||
sendToDatabase
|
||||
} from '../../backend/database';
|
||||
import ThemeDropdown from './DropDownTheme';
|
||||
|
||||
|
@ -314,27 +312,6 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
|||
}
|
||||
}, []); // Runs only once when the component mounts
|
||||
|
||||
const importDatabase = async (useName: string, usePassword: string) => {
|
||||
const databaseSettings = await getSettings(useName, usePassword);
|
||||
|
||||
// Ensure user settings exist before flattening and storing
|
||||
if (typeof databaseSettings == 'object' && databaseSettings) {
|
||||
JSON.stringify(importSettings(databaseSettings), null, 2); // Pass only the current user's settings
|
||||
} else {
|
||||
console.error('Database settings are not in the expected format.');
|
||||
}
|
||||
}
|
||||
|
||||
const sendToDatabase = async () => {
|
||||
let useName = localStorage.getItem("accountName")
|
||||
let usePassword = localStorage.getItem("accountPassword")
|
||||
if (useName && usePassword) {
|
||||
if (await changeSettings(useName, usePassword, JSON.parse(exportSettings()))) {
|
||||
alert('Data has been transferred')
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Effect hooks to update localStorage whenever any state changes
|
||||
useEffect(() => {
|
||||
// Flatten nested objects
|
||||
|
@ -795,7 +772,6 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
|||
getAllLocalStorageItems();
|
||||
closeSettings();
|
||||
sendToDatabase();
|
||||
window.location.reload();
|
||||
}}>
|
||||
Apply
|
||||
</button>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// settingsManager.ts
|
||||
import { changeSettings, getSettings } from "@/app/backend/database";
|
||||
|
||||
// Method to export localStorage to a JSON object
|
||||
export function exportSettings(): string {
|
||||
|
@ -37,3 +38,27 @@ export function importSettings(jsonData: string): void {
|
|||
console.error("Invalid JSON data:", error);
|
||||
}
|
||||
}
|
||||
|
||||
export const sendToDatabase = async () => {
|
||||
let useName = localStorage.getItem("accountName")
|
||||
let usePassword = localStorage.getItem("accountPassword")
|
||||
if (useName && usePassword) {
|
||||
let result = await changeSettings(useName, usePassword, JSON.parse(exportSettings()))
|
||||
if (result == true) {
|
||||
alert('Data has been transferred')
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
export const importDatabase = async (useName: string, usePassword: string) => {
|
||||
const databaseSettings = await getSettings(useName, usePassword);
|
||||
|
||||
// Ensure user settings exist before flattening and storing
|
||||
if (typeof databaseSettings == 'object' && databaseSettings) {
|
||||
importSettings(JSON.stringify(databaseSettings, null, 2)); // Pass only the current user's settings
|
||||
} else {
|
||||
console.error('Database settings are not in the expected format.');
|
||||
}
|
||||
}
|
||||
|
|
22
deployment_scripts/linux/prepare-free.sh
Executable file
22
deployment_scripts/linux/prepare-free.sh
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
chmod +x root.sh
|
||||
pkexec ./root.sh
|
||||
npm install
|
||||
npm run build
|
||||
|
||||
cd py
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
python3 -m pip install -r requirements.txt
|
||||
|
||||
ollama pull qwen2-math:1.5b
|
||||
ollama pull starcoder2
|
||||
ollama pull llama3.2
|
||||
|
||||
ollama pull wizard-math
|
||||
ollama pull starcoder2:7b
|
||||
ollama pull llama3.1
|
||||
|
||||
cd ..
|
||||
chmod +x run.sh
|
22
deployment_scripts/linux/prepare-nonfree.sh
Executable file
22
deployment_scripts/linux/prepare-nonfree.sh
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
chmod +x root.sh
|
||||
pkexec ./root.sh
|
||||
npm install
|
||||
npm run build
|
||||
|
||||
cd py
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
python3 -m pip install -r requirements.txt
|
||||
|
||||
ollama pull qwen2-math:1.5b
|
||||
ollama pull qwen2.5-coder:1.5b
|
||||
ollama pull phi3.5
|
||||
|
||||
ollama pull mathstral
|
||||
ollama pull qwen2.5-coder
|
||||
ollama pull qwen2.5
|
||||
|
||||
cd ..
|
||||
chmod +x run.sh
|
7
deployment_scripts/linux/root.sh
Normal file
7
deployment_scripts/linux/root.sh
Normal file
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
apt install npm nodejs python3-full -y
|
||||
if ! ollama; then
|
||||
curl -fsSL https://ollama.com/install.sh | sh
|
||||
fi
|
||||
systemctl enable ollama --now
|
13
deployment_scripts/linux/run.sh
Normal file
13
deployment_scripts/linux/run.sh
Normal file
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd py
|
||||
python api.py &
|
||||
pid_py=$!
|
||||
|
||||
npm start &
|
||||
pid_node=$!
|
||||
|
||||
npx electron .
|
||||
|
||||
kill $pid_py
|
||||
kill $pid_node
|
Loading…
Reference in a new issue