Repetitions remake #1
No files matched your search
@@ -93,7 +93,7 @@ pub fn delete_stats(stat: &[CardStatistics], connection: &Connection) {
|
|||||||
.join(", ");
|
.join(", ");
|
||||||
connection
|
connection
|
||||||
.execute(
|
.execute(
|
||||||
format!("DELETE FROM card_stats WHERE id in {ids}").as_str(),
|
format!("DELETE FROM card_stats WHERE id in ({ids})").as_str(),
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ fn parse_history_items(strings: Vec<String>) -> Vec<HistoryItem> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
items.push(HistoryItem {
|
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,
|
word_id: id,
|
||||||
mode: match mode.parse::<u8>().unwrap_or_default() {
|
mode: match mode.parse::<u8>().unwrap_or_default() {
|
||||||
2 => WordOpenMode::Hard,
|
2 => WordOpenMode::Hard,
|
||||||
|
|||||||
@@ -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 = "http://127.0.0.1:8089/";
|
||||||
const API_URL: &str = "https://learning.micialware.ru/";
|
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 path = app_data_dir();
|
||||||
let db_file = path.join("data.db");
|
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 data = compress(data);
|
||||||
|
|
||||||
let api_url = API_URL.to_string();
|
let api_url = API_URL.to_string();
|
||||||
@@ -21,12 +21,11 @@ pub async fn send_data(id: String) {
|
|||||||
.post(&id_url)
|
.post(&id_url)
|
||||||
.body(data)
|
.body(data)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await.map_err(|_| ())?
|
||||||
.unwrap()
|
|
||||||
.text()
|
.text()
|
||||||
.await
|
.await.map_err(|_| ())?;
|
||||||
.unwrap();
|
|
||||||
set_local_version(new_version.parse::<u32>().unwrap()).await;
|
set_local_version(new_version.parse::<u32>().unwrap()).await;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compress(data: Vec<u8>) -> Vec<u8> {
|
fn compress(data: Vec<u8>) -> Vec<u8> {
|
||||||
@@ -35,18 +34,16 @@ fn compress(data: Vec<u8>) -> Vec<u8> {
|
|||||||
encoder.finish().unwrap()
|
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 api_url = API_URL.to_string();
|
||||||
let id_url = format!("{api_url}download/{id}");
|
let id_url = format!("{api_url}download/{id}");
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let data = client
|
let data = client
|
||||||
.get(&id_url)
|
.get(&id_url)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await.map_err(|_| ())?
|
||||||
.unwrap()
|
|
||||||
.bytes()
|
.bytes()
|
||||||
.await
|
.await.map_err(|_| ())?
|
||||||
.unwrap()
|
|
||||||
.to_vec();
|
.to_vec();
|
||||||
let data = decompress(data);
|
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 file_name = if temp { "data.db.tmp" } else { "data.db" };
|
||||||
let db_file = path.join(file_name);
|
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_url = format!("{API_URL}{id}/version");
|
||||||
let version = client
|
let version = client
|
||||||
.get(&version_url)
|
.get(&version_url)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await.map_err(|_| ())?
|
||||||
.unwrap()
|
|
||||||
.text()
|
.text()
|
||||||
.await
|
.await.map_err(|_| ())?;
|
||||||
.unwrap();
|
set_local_version(version.parse::<u32>().map_err(|_| ())?).await;
|
||||||
set_local_version(version.parse::<u32>().unwrap()).await;
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decompress(data: Vec<u8>) -> Vec<u8> {
|
pub fn decompress(data: Vec<u8>) -> Vec<u8> {
|
||||||
@@ -78,7 +74,7 @@ pub fn decompress(data: Vec<u8>) -> Vec<u8> {
|
|||||||
decompressed
|
decompressed
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn first_sync() -> String {
|
pub async fn first_sync() -> Result<String, ()> {
|
||||||
let id_url = API_URL.to_string() + "generate";
|
let id_url = API_URL.to_string() + "generate";
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
@@ -86,12 +82,12 @@ pub async fn first_sync() -> String {
|
|||||||
.get(&id_url)
|
.get(&id_url)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.map_err(|_| ())?
|
||||||
.text()
|
.text()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.map_err(|_| ())?;
|
||||||
println!("id: {}", id);
|
println!("id: {}", id);
|
||||||
id
|
Ok(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_web_version(key: &str) -> Result<u32, reqwest::Error> {
|
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)
|
.read_to_string(&mut data)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
return data.parse::<u32>().unwrap();
|
return data.parse::<u32>().unwrap_or_default();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut file = OpenOptions::new()
|
let mut file = OpenOptions::new()
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
use crate::data_provider::words::{delete_group, delete_word, update_group, update_word};
|
use crate::data_provider::words::{delete_group, delete_word, update_group, update_word};
|
||||||
use crate::dictionary::DictionaryMessage::*;
|
use crate::dictionary::DictionaryMessage::*;
|
||||||
use crate::dictionary_test::DictionaryQuizState;
|
use crate::dictionary_quiz::DictionaryQuizState;
|
||||||
use crate::import::ImportState;
|
use crate::import::ImportState;
|
||||||
use crate::lang::{WordData, WordGroup};
|
use crate::lang::{WordData, WordGroup};
|
||||||
use crate::navigation::Page::{Import, Word};
|
use crate::navigation::Page::{Import, Word};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::RootMessage;
|
use crate::RootMessage;
|
||||||
use crate::dictionary::split_with_coma;
|
use crate::dictionary::split_with_coma;
|
||||||
use crate::dictionary_test::DictionaryQuizMessage::*;
|
use crate::dictionary_quiz::DictionaryQuizMessage::*;
|
||||||
use crate::lang::WordData;
|
use crate::lang::WordData;
|
||||||
use crate::navigation::Page::PreviousPage;
|
use crate::navigation::Page::PreviousPage;
|
||||||
use crate::navigation::*;
|
use crate::navigation::*;
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
#![windows_subsystem = "windows"]
|
#![windows_subsystem = "windows"]
|
||||||
mod data_provider;
|
mod data_provider;
|
||||||
mod dictionary;
|
mod dictionary;
|
||||||
mod dictionary_test;
|
mod dictionary_quiz;
|
||||||
mod history;
|
mod history;
|
||||||
pub mod import;
|
pub mod import;
|
||||||
mod lang;
|
mod lang;
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ use crate::data_provider::web_api::{
|
|||||||
get_local_version, get_web_version, load_data, set_local_version,
|
get_local_version, get_web_version, load_data, set_local_version,
|
||||||
};
|
};
|
||||||
use crate::dictionary::{DictionaryMessage, DictionaryState, app_data_dir};
|
use crate::dictionary::{DictionaryMessage, DictionaryState, app_data_dir};
|
||||||
use crate::dictionary_test::{DictionaryQuizMessage, DictionaryQuizState};
|
use crate::dictionary_quiz::{DictionaryQuizMessage, DictionaryQuizState};
|
||||||
use crate::history::{HistoryMessage, HistoryState};
|
use crate::history::{HistoryMessage, HistoryState};
|
||||||
use crate::import::{ImportMessage, ImportState};
|
use crate::import::{ImportMessage, ImportState};
|
||||||
use crate::lang::Id;
|
use crate::lang::Id;
|
||||||
|
|||||||
+11
-6
@@ -4,7 +4,7 @@ use crate::navigation::Page::PreviousPage;
|
|||||||
use crate::navigation::{NavigatedPage, Page};
|
use crate::navigation::{NavigatedPage, Page};
|
||||||
use crate::styling::*;
|
use crate::styling::*;
|
||||||
use crate::sync::SyncMessage::*;
|
use crate::sync::SyncMessage::*;
|
||||||
use crate::{AppState, RootMessage, fill_state};
|
use crate::{fill_state, AppState, RootMessage};
|
||||||
use iced::widget::button::danger;
|
use iced::widget::button::danger;
|
||||||
use iced::widget::container::rounded_box;
|
use iced::widget::container::rounded_box;
|
||||||
use iced::widget::{button, column, container, progress_bar, row, space, text, toggler};
|
use iced::widget::{button, column, container, progress_bar, row, space, text, toggler};
|
||||||
@@ -59,7 +59,12 @@ impl NavigatedPage<SyncMessage> for SyncState {
|
|||||||
.map(|_val: String| RootMessage::Sync(KeyCopied));
|
.map(|_val: String| RootMessage::Sync(KeyCopied));
|
||||||
}
|
}
|
||||||
InitSync => {
|
InitSync => {
|
||||||
return Task::perform(first_sync(), |id| RootMessage::Sync(IdReceived(id)));
|
return Task::perform(first_sync(), |id| {
|
||||||
|
match id {
|
||||||
|
Ok(id) => RootMessage::Sync(IdReceived(id)),
|
||||||
|
Err(_) => RootMessage::None
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
GetKey => {
|
GetKey => {
|
||||||
return iced::clipboard::read()
|
return iced::clipboard::read()
|
||||||
@@ -218,10 +223,10 @@ impl SyncState {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.spacing(DEFAULT_SPACING)
|
.spacing(DEFAULT_SPACING)
|
||||||
.align_x(Center)
|
.align_x(Center)
|
||||||
.width(Length::Shrink)
|
.width(Length::Shrink)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fn app_updater(&self) -> Element<'_, SyncMessage> {
|
/* fn app_updater(&self) -> Element<'_, SyncMessage> {
|
||||||
|
|||||||
Reference in new issue
Block a user