Skip to content

Commit

Permalink
Add function which gets a list of course items that are attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
b-paul committed Aug 26, 2023
1 parent f53d779 commit 54b2820
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib-bb/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub trait BBClient {

fn get_directory_contents(&self, url: String) -> Result<Vec<CourseItem>, Errno>;

fn get_attachment_directory(&self, item: &CourseItem) -> Result<Vec<CourseItem>, Errno>;

fn get_item_size(&self, item: &CourseItem) -> Result<usize, Errno>;
fn get_item_contents(&mut self, item: &CourseItem) -> Result<&[u8], Errno>;
}
Expand Down Expand Up @@ -140,10 +142,26 @@ impl BBClient for BBAPIClient {
.get_folder_contents(&html)
.map_err(|_| Errno::EIO)?
.into_iter()
.map(|entry| entry.into())
.map(|entry| {
entry.into()
})
.collect())
}

fn get_attachment_directory(&self, item: &CourseItem) -> Result<Vec<CourseItem>, Errno> {
item.attachments.iter().map(|url| {
let name = self.get_download_file_name(url).map_err(|_| Errno::ENETUNREACH)?;

Ok(CourseItem {
name: name.clone(),
file_name: Some(name),
content: Some(CourseItemContent::FileUrl(url.to_string())),
description: None,
attachments: vec![],
})
}).collect()
}

fn get_item_size(&self, item: &CourseItem) -> Result<usize, Errno> {
Ok(match &item.content {
Some(content) => match content {
Expand Down

0 comments on commit 54b2820

Please sign in to comment.