Adding words by parts

This commit is contained in:
2026-08-15 21:32:24 +03:00
parent 8f789facd7
commit 51c8d7be74
23 changed files with 409 additions and 241 deletions
+41 -8
View File
@@ -2,7 +2,7 @@ use crate::dictionary::app_data_dir;
use std::io;
use tokio::fs::{File, OpenOptions};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use zstd::{Decoder, Encoder, DEFAULT_COMPRESSION_LEVEL};
use zstd::{DEFAULT_COMPRESSION_LEVEL, Decoder, Encoder};
// const API_URL: &str = "http://127.0.0.1:8089/";
const API_URL: &str = "https://learning.micialware.ru/";
@@ -17,7 +17,15 @@ pub async fn send_data(id: String) {
let id_url = format!("{api_url}upload/stream/{id}");
let client = reqwest::Client::new();
let new_version = client.post(&id_url).body(data).send().await.unwrap().text().await.unwrap();
let new_version = client
.post(&id_url)
.body(data)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
set_local_version(new_version.parse::<u32>().unwrap()).await;
}
@@ -49,7 +57,14 @@ pub async fn load_data(id: String, temp: bool) {
tokio::fs::write(db_file, data).await.unwrap();
let version_url = format!("{API_URL}{id}/version");
let version = client.get(&version_url).send().await.unwrap().text().await.unwrap();
let version = client
.get(&version_url)
.send()
.await
.unwrap()
.text()
.await
.unwrap();
set_local_version(version.parse::<u32>().unwrap()).await;
}
@@ -90,18 +105,36 @@ pub async fn get_local_version() -> u32 {
let file = app_data_dir().join("data.meta");
if file.exists() {
let mut data = String::new();
File::open(file.clone()).await.unwrap().read_to_string(&mut data).await.unwrap();
File::open(file.clone())
.await
.unwrap()
.read_to_string(&mut data)
.await
.unwrap();
return data.parse::<u32>().unwrap();
}
let mut file = OpenOptions::new().write(true).create(true).truncate(true).open(file).await.unwrap();
let mut file = OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(file)
.await
.unwrap();
file.write_all("0".as_bytes()).await.unwrap();
0
}
pub async fn set_local_version(version: u32) {
let file_path = app_data_dir().join("data.meta");
let mut file = OpenOptions::new().write(true).create(true).truncate(true).open(file_path).await.unwrap();
file.write_all(version.to_string().as_bytes()).await.unwrap();
let mut file = OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(file_path)
.await
.unwrap();
file.write_all(version.to_string().as_bytes())
.await
.unwrap();
}