Formatting
This commit is contained in:
1 parent
dddac01bdf
commit
10cf7f0d2e
29 files changed
+138
-138
No files matched your search
@@ -1,10 +1,10 @@
|
||||
use crate::helpers::into_result;
|
||||
use crate::notification::NotificationData;
|
||||
use crate::notification::NotificationData::IncorrectAnkiFile;
|
||||
use hashbrown::HashMap;
|
||||
use log::info;
|
||||
use rusqlite::Connection;
|
||||
use serde_json::Value;
|
||||
use crate::helpers::into_result;
|
||||
use crate::notification::NotificationData::IncorrectAnkiFile;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ImportData(pub(crate) Vec<ImportGroup>);
|
||||
@@ -29,8 +29,7 @@ pub fn load_groups(connection: &Connection) -> Result<ImportData, NotificationDa
|
||||
let json_models: String = connection
|
||||
.query_one("select models from col", (), |row| row.get(0))
|
||||
.map_err(|_| IncorrectAnkiFile)?;
|
||||
let raw: Value = serde_json::from_str(json_models.as_str())
|
||||
.map_err(|_| IncorrectAnkiFile)?;
|
||||
let raw: Value = serde_json::from_str(json_models.as_str()).map_err(|_| IncorrectAnkiFile)?;
|
||||
let sets = raw.as_object();
|
||||
if let Some(sets) = sets {
|
||||
let mut total_data = ImportData(vec![]);
|
||||
@@ -48,14 +47,13 @@ pub fn load_groups(connection: &Connection) -> Result<ImportData, NotificationDa
|
||||
for (_, collection) in sets {
|
||||
let fields_property = collection.get("fields");
|
||||
if let Some(fields_property) = fields_property {
|
||||
let fields = into_result(fields_property
|
||||
.as_array(), IncorrectAnkiFile)?
|
||||
let fields = into_result(fields_property.as_array(), IncorrectAnkiFile)?
|
||||
.iter()
|
||||
.filter_map(|x| x.get("name"))
|
||||
.map(|x| x.as_str().unwrap().to_string())
|
||||
.collect();
|
||||
let id = collection.get("id");
|
||||
if id.is_none() || id.unwrap().as_u64().is_none(){
|
||||
if id.is_none() || id.unwrap().as_u64().is_none() {
|
||||
return Err(IncorrectAnkiFile);
|
||||
}
|
||||
let id = id.unwrap().as_u64().unwrap();
|
||||
@@ -80,12 +78,15 @@ pub fn load_groups(connection: &Connection) -> Result<ImportData, NotificationDa
|
||||
total_data.0.push(group);
|
||||
}
|
||||
}
|
||||
return Ok(total_data)
|
||||
return Ok(total_data);
|
||||
}
|
||||
Err(IncorrectAnkiFile)
|
||||
}
|
||||
|
||||
pub fn get_words_of_group(connection: &Connection, group_id: u64) -> Result<Vec<ImportNote>, NotificationData> {
|
||||
pub fn get_words_of_group(
|
||||
connection: &Connection,
|
||||
group_id: u64,
|
||||
) -> Result<Vec<ImportNote>, NotificationData> {
|
||||
let mut count_stmt = connection
|
||||
.prepare("select tags, flds from notes where mid == ?1;")
|
||||
.map_err(|_| IncorrectAnkiFile)?;
|
||||
|
||||
Reference in new issue
Block a user