From 6d52dd7c817701faf67ecb8cbd6188e472c9d158 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Sat, 12 Dec 2020 17:17:54 -0300 Subject: [PATCH] Fixed a problem with the API --- src/main.rs | 6 ------ src/storage/joplin.rs | 38 ++++++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7b74521..e3b292b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,12 +34,6 @@ fn main() { let config = dbg!(config::Config::get()); let client = dbg!(get_mastodon_connection()); let top = dbg!(config.last_favorite.to_string()); - // let joplin_storage = if let Some(joplin_config) = &config.joplin { - // Some(Joplin::new_from_config(&joplin_config)) - // } else { - // None - // }; - // let fs_storage = Filesystem::new(); let storage: Box = if let Some(joplin) = &config.joplin { Box::new(Joplin::new_from_config(&joplin)) } else { diff --git a/src/storage/joplin.rs b/src/storage/joplin.rs index 54c6c86..5ca2b64 100644 --- a/src/storage/joplin.rs +++ b/src/storage/joplin.rs @@ -33,6 +33,13 @@ static INLINABLE: [&'static str; 4] = ["jpeg", "jpg", "png", "gif"]; /// This is the folder structured returned by Joplin. It is here so Reqwests can /// unjson the data (there are more fields, but these are the only ones we need /// right now). +#[allow(dead_code)] +#[derive(Deserialize, Debug)] +struct FolderList { + items: Vec, + has_more: bool, +} + #[allow(dead_code)] #[derive(Deserialize, Debug)] struct Folder { @@ -95,12 +102,31 @@ impl Joplin { } fn get_folder_list(config: &JoplinConfig) -> Result, Error> { - let base_url = format!( - "http://localhost:{port}/folders?token={token}", - port = config.port, - token = config.token - ); - let folders: Vec = reqwest::get(&base_url)?.json()?; + let mut page = 1; + let mut has_more = true; + let mut folders: Vec = Vec::new(); + + while has_more { + let base_url = dbg!(format!( + "http://localhost:{port}/folders?token={token}&page={page}", + port = config.port, + token = config.token, + page = page + )); + let folder_list: FolderList = reqwest::get(&base_url)?.json()?; + + folder_list.items.iter().for_each(|folder| { + folders.push(Folder { + // XXX this is silly and I should change this to use an + // iterator over the results + id: folder.id.to_string(), + title: folder.title.to_string(), + }) + }); + page += 1; + has_more = folder_list.has_more; + } + Ok(folders) }