Skip to content

Commit

Permalink
fix import configuration error (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
domechn authored Oct 28, 2023
1 parent b27d814 commit fc10644
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/middlelayers/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export async function saveConfiguration(cfg: GlobalConfig) {
}

// used for import data
export async function saveRawConfiguration(data: string) {
await saveConfigurationById(fixId, data)
export async function importRawConfiguration(data: string) {
await saveConfigurationById(fixId, data, false)
}

export async function getCloudSyncConfiguration(): Promise<ConfigurationModel | undefined> {
Expand All @@ -42,12 +42,12 @@ export async function saveCloudSyncConfiguration(cfg: CloudSyncConfiguration) {
await saveConfigurationById(cloudSyncFixId, data)
}

async function saveConfigurationById(id: string, cfg: string) {
async function saveConfigurationById(id: string, cfg: string, encrypt = true) {
const db = await getDatabase()
// encrypt data
const encrypted = await invoke<string>("encrypt", { data: cfg })
const saveStr = encrypt ? await invoke<string>("encrypt", { data: cfg }) : cfg

await db.execute(`INSERT OR REPLACE INTO configuration (id, data) VALUES (${id}, ?)`, [encrypted])
await db.execute(`INSERT OR REPLACE INTO configuration (id, data) VALUES (${id}, ?)`, [saveStr])
}

export async function exportConfigurationString(): Promise<string | undefined> {
Expand Down
4 changes: 2 additions & 2 deletions src/middlelayers/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { save, open } from "@tauri-apps/api/dialog"
import { writeTextFile, readTextFile } from "@tauri-apps/api/fs"
import { AssetModel, HistoricalData } from './types'
import { getDatabase } from './database'
import { exportConfigurationString, saveRawConfiguration } from './configuration'
import { exportConfigurationString, importRawConfiguration } from './configuration'

type ExportData = {
exportAt: string
Expand Down Expand Up @@ -134,7 +134,7 @@ export async function importHistoricalData(): Promise<boolean> {

// import configuration if exported
if (configuration) {
await saveRawConfiguration(configuration)
await importRawConfiguration(configuration)
}

return true
Expand Down

0 comments on commit fc10644

Please sign in to comment.