Rename DictionaryTest to DictionaryQuiz

This commit is contained in:
micialware committed 2026-08-20 17:48:03 +03:00
1 parent c9508922f4
commit 9456eec2af
8 files changed
+35 -34

No files matched your search

+1 -1
View File
@@ -93,7 +93,7 @@ pub fn delete_stats(stat: &[CardStatistics], connection: &Connection) {
.join(", ");
connection
.execute(
format!("DELETE FROM card_stats WHERE id in {ids}").as_str(),
format!("DELETE FROM card_stats WHERE id in ({ids})").as_str(),
(),
)
.unwrap();
+1 -1
View File
@@ -39,7 +39,7 @@ fn parse_history_items(strings: Vec<String>) -> Vec<HistoryItem> {
continue;
}
items.push(HistoryItem {
timestamp: DateTime::from_timestamp(time.parse().unwrap_or_default(), 0).unwrap(),
timestamp: DateTime::from_timestamp(time.parse().unwrap_or_default(), 0).unwrap_or_default(),
word_id: id,
mode: match mode.parse::<u8>().unwrap_or_default() {
2 => WordOpenMode::Hard,
+18 -22
View File
@@ -7,10 +7,10 @@ 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/";
pub async fn send_data(id: String) {
pub async fn send_data(id: String) -> Result<(), ()> {
let path = app_data_dir();
let db_file = path.join("data.db");
let data = tokio::fs::read(db_file).await.unwrap();
let data = tokio::fs::read(db_file).await.map_err(|_| ())?;
let data = compress(data);
let api_url = API_URL.to_string();
@@ -21,12 +21,11 @@ pub async fn send_data(id: String) {
.post(&id_url)
.body(data)
.send()
.await
.unwrap()
.await.map_err(|_| ())?
.text()
.await
.unwrap();
.await.map_err(|_| ())?;
set_local_version(new_version.parse::<u32>().unwrap()).await;
Ok(())
}
fn compress(data: Vec<u8>) -> Vec<u8> {
@@ -35,18 +34,16 @@ fn compress(data: Vec<u8>) -> Vec<u8> {
encoder.finish().unwrap()
}
pub async fn load_data(id: String, temp: bool) {
pub async fn load_data(id: String, temp: bool) -> Result<(), ()> {
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
.unwrap()
.await.map_err(|_| ())?
.bytes()
.await
.unwrap()
.await.map_err(|_| ())?
.to_vec();
let data = decompress(data);
@@ -54,18 +51,17 @@ pub async fn load_data(id: String, temp: bool) {
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.unwrap();
tokio::fs::write(db_file, data).await.map_err(|_| ())?;
let version_url = format!("{API_URL}{id}/version");
let version = client
.get(&version_url)
.send()
.await
.unwrap()
.await.map_err(|_| ())?
.text()
.await
.unwrap();
set_local_version(version.parse::<u32>().unwrap()).await;
.await.map_err(|_| ())?;
set_local_version(version.parse::<u32>().map_err(|_| ())?).await;
Ok(())
}
pub fn decompress(data: Vec<u8>) -> Vec<u8> {
@@ -78,7 +74,7 @@ pub fn decompress(data: Vec<u8>) -> Vec<u8> {
decompressed
}
pub async fn first_sync() -> String {
pub async fn first_sync() -> Result<String, ()> {
let id_url = API_URL.to_string() + "generate";
let client = reqwest::Client::new();
@@ -86,12 +82,12 @@ pub async fn first_sync() -> String {
.get(&id_url)
.send()
.await
.unwrap()
.map_err(|_| ())?
.text()
.await
.unwrap();
.map_err(|_| ())?;
println!("id: {}", id);
id
Ok(id)
}
pub async fn get_web_version(key: &str) -> Result<u32, reqwest::Error> {
@@ -112,7 +108,7 @@ pub async fn get_local_version() -> u32 {
.read_to_string(&mut data)
.await
.unwrap();
return data.parse::<u32>().unwrap();
return data.parse::<u32>().unwrap_or_default();
}
let mut file = OpenOptions::new()