Browse Source

Fixed a problem with the API

master
Julio Biason 4 years ago
parent
commit
6d52dd7c81
  1. 6
      src/main.rs
  2. 38
      src/storage/joplin.rs

6
src/main.rs

@ -34,12 +34,6 @@ fn main() {
let config = dbg!(config::Config::get()); let config = dbg!(config::Config::get());
let client = dbg!(get_mastodon_connection()); let client = dbg!(get_mastodon_connection());
let top = dbg!(config.last_favorite.to_string()); 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<dyn Storage> = if let Some(joplin) = &config.joplin { let storage: Box<dyn Storage> = if let Some(joplin) = &config.joplin {
Box::new(Joplin::new_from_config(&joplin)) Box::new(Joplin::new_from_config(&joplin))
} else { } else {

38
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 /// 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 /// unjson the data (there are more fields, but these are the only ones we need
/// right now). /// right now).
#[allow(dead_code)]
#[derive(Deserialize, Debug)]
struct FolderList {
items: Vec<Folder>,
has_more: bool,
}
#[allow(dead_code)] #[allow(dead_code)]
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
struct Folder { struct Folder {
@ -95,12 +102,31 @@ impl Joplin {
} }
fn get_folder_list(config: &JoplinConfig) -> Result<Vec<Folder>, Error> { fn get_folder_list(config: &JoplinConfig) -> Result<Vec<Folder>, Error> {
let base_url = format!( let mut page = 1;
"http://localhost:{port}/folders?token={token}", let mut has_more = true;
port = config.port, let mut folders: Vec<Folder> = Vec::new();
token = config.token
); while has_more {
let folders: Vec<Folder> = reqwest::get(&base_url)?.json()?; 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) Ok(folders)
} }

Loading…
Cancel
Save