forked from React-Group/interstellar_ai
settingsUtils comment
This commit is contained in:
parent
da9e98edf9
commit
621daf6669
1 changed files with 11 additions and 7 deletions
|
@ -10,6 +10,7 @@ export function exportSettings(): string {
|
||||||
for (let i = 0; i < localStorage.length; i++) {
|
for (let i = 0; i < localStorage.length; i++) {
|
||||||
const key = localStorage.key(i);
|
const key = localStorage.key(i);
|
||||||
if (key) {
|
if (key) {
|
||||||
|
// Exclude sensitive information
|
||||||
if (key !== "accountName" && key !== "accountPassword" && key !== "accountEmail") {
|
if (key !== "accountName" && key !== "accountPassword" && key !== "accountEmail") {
|
||||||
settings[key] = localStorage.getItem(key) || "";
|
settings[key] = localStorage.getItem(key) || "";
|
||||||
}
|
}
|
||||||
|
@ -39,25 +40,28 @@ export function importSettings(jsonData: string): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send current settings to the database
|
||||||
export const sendToDatabase = async () => {
|
export const sendToDatabase = async () => {
|
||||||
const useName = localStorage.getItem("accountName")
|
const useName = localStorage.getItem("accountName");
|
||||||
const usePassword = localStorage.getItem("accountPassword")
|
const usePassword = localStorage.getItem("accountPassword");
|
||||||
|
|
||||||
if (useName && usePassword) {
|
if (useName && usePassword) {
|
||||||
const result = await changeSettings(useName, usePassword, JSON.parse(exportSettings()))
|
const result = await changeSettings(useName, usePassword, JSON.parse(exportSettings()));
|
||||||
if (result == true) {
|
if (result === true) {
|
||||||
|
// Only reload if the settings change was successful
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window.location.reload();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Import settings from the database based on username and password
|
||||||
export const importDatabase = async (useName: string, usePassword: string) => {
|
export const importDatabase = async (useName: string, usePassword: string) => {
|
||||||
const databaseSettings = await getSettings(useName, usePassword);
|
const databaseSettings = await getSettings(useName, usePassword);
|
||||||
|
|
||||||
// Ensure user settings exist before flattening and storing
|
// Ensure user settings exist before flattening and storing
|
||||||
if (typeof databaseSettings == 'object' && databaseSettings) {
|
if (typeof databaseSettings === 'object' && databaseSettings) {
|
||||||
importSettings(JSON.stringify(databaseSettings, null, 2)); // Pass only the current user's settings
|
importSettings(JSON.stringify(databaseSettings, null, 2)); // Pass only the current user's settings
|
||||||
} else {
|
} else {
|
||||||
console.error('Database settings are not in the expected format.');
|
console.error('Database settings are not in the expected format.');
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
Loading…
Reference in a new issue