Fix history bug

This commit is contained in:
micialware committed 2026-08-20 18:18:14 +03:00
1 parent 9456eec2af
commit c5c1f34e1c
7 files changed
+38 -34

No files matched your search

+8 -7
View File
@@ -1,5 +1,6 @@
use crate::dictionary::app_data_dir;
use std::io;
use reqwest::Error;
use tokio::fs::{File, OpenOptions};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use zstd::{DEFAULT_COMPRESSION_LEVEL, Decoder, Encoder};
@@ -34,16 +35,16 @@ fn compress(data: Vec<u8>) -> Vec<u8> {
encoder.finish().unwrap()
}
pub async fn load_data(id: String, temp: bool) -> Result<(), ()> {
pub async fn load_data(id: String, temp: bool) -> Result<(), Error> {
let api_url = API_URL.to_string();
let id_url = format!("{api_url}download/{id}");
let client = reqwest::Client::new();
let data = client
.get(&id_url)
.send()
.await.map_err(|_| ())?
.await?
.bytes()
.await.map_err(|_| ())?
.await?
.to_vec();
let data = decompress(data);
@@ -51,16 +52,16 @@ pub async fn load_data(id: String, temp: bool) -> Result<(), ()> {
let file_name = if temp { "data.db.tmp" } else { "data.db" };
let db_file = path.join(file_name);
tokio::fs::write(db_file, data).await.map_err(|_| ())?;
tokio::fs::write(db_file, data).await.unwrap();
let version_url = format!("{API_URL}{id}/version");
let version = client
.get(&version_url)
.send()
.await.map_err(|_| ())?
.await?
.text()
.await.map_err(|_| ())?;
set_local_version(version.parse::<u32>().map_err(|_| ())?).await;
.await?;
set_local_version(version.parse::<u32>().unwrap_or_default()).await;
Ok(())
}