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 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<dyn Storage> = if let Some(joplin) = &config.joplin {
Box::new(Joplin::new_from_config(&joplin))
} 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
/// 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<Folder>,
has_more: bool,
}
#[allow(dead_code)]
#[derive(Deserialize, Debug)]
struct Folder {
@ -95,12 +102,31 @@ impl Joplin {
}
fn get_folder_list(config: &JoplinConfig) -> Result<Vec<Folder>, Error> {
let base_url = format!(
"http://localhost:{port}/folders?token={token}",
port = config.port,
token = config.token
);
let folders: Vec<Folder> = reqwest::get(&base_url)?.json()?;
let mut page = 1;
let mut has_more = true;
let mut folders: Vec<Folder> = 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)
}

Loading…
Cancel
Save