|
|
|
@ -4,7 +4,7 @@ use rayon::prelude::*;
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
use std::fs;
|
|
|
|
|
|
|
|
|
|
use crate::{ai::Params, config::CONFIG};
|
|
|
|
|
use crate::ai::Params;
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
|
|
|
pub struct HistoryEntry {
|
|
|
|
@ -14,11 +14,8 @@ pub struct HistoryEntry {
|
|
|
|
|
pub result: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn write_history(entry: HistoryEntry) -> Result<()> {
|
|
|
|
|
// should be safe to unwrap as this function will never be called without it
|
|
|
|
|
let history_dir = CONFIG.app.history_dir.as_ref().unwrap();
|
|
|
|
|
|
|
|
|
|
fs::create_dir_all(history_dir)?;
|
|
|
|
|
pub fn write_history(entry: HistoryEntry, history_dir: String) -> Result<()> {
|
|
|
|
|
fs::create_dir_all(&history_dir)?;
|
|
|
|
|
|
|
|
|
|
let json = serde_json::to_string(&entry)?;
|
|
|
|
|
|
|
|
|
@ -30,9 +27,7 @@ pub fn write_history(entry: HistoryEntry) -> Result<()> {
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn read_all_history() -> Result<Vec<HistoryEntry>> {
|
|
|
|
|
// should be safe to unwrap as this function will never be called without it
|
|
|
|
|
let history_dir = CONFIG.app.history_dir.as_ref().unwrap();
|
|
|
|
|
pub fn read_all_history(history_dir: String) -> Result<Vec<HistoryEntry>> {
|
|
|
|
|
let (tx, rx) = flume::unbounded();
|
|
|
|
|
|
|
|
|
|
fs::read_dir(history_dir)
|
|
|
|
|