diff --git a/deltachat-jsonrpc/src/api.rs b/deltachat-jsonrpc/src/api.rs index fae0196fa..c777763a0 100644 --- a/deltachat-jsonrpc/src/api.rs +++ b/deltachat-jsonrpc/src/api.rs @@ -1,5 +1,5 @@ use std::collections::BTreeMap; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::str; use std::sync::Arc; use std::time::Duration; @@ -7,6 +7,7 @@ use std::{collections::HashMap, str::FromStr}; use anyhow::{anyhow, bail, ensure, Context, Result}; pub use deltachat::accounts::Accounts; +use deltachat::blob::BlobObject; use deltachat::chat::{ self, add_contact_to_chat, forward_msgs, get_chat_media, get_chat_msgs, get_chat_msgs_ex, marknoticed_chat, remove_contact_from_chat, Chat, ChatId, ChatItem, MessageListOptions, @@ -341,11 +342,19 @@ impl CommandApi { ctx.get_info().await } + /// Get the blob dir. async fn get_blob_dir(&self, account_id: u32) -> Result> { let ctx = self.get_context(account_id).await?; Ok(ctx.get_blobdir().to_str().map(|s| s.to_owned())) } + /// Copy file to blobdir. + async fn copy_to_blobdir(&self, account_id: u32, path: String) -> Result { + let ctx = self.get_context(account_id).await?; + let file = Path::new(&path); + Ok(BlobObject::create_and_deduplicate(&ctx, file, file)?.to_abs_path()) + } + async fn draft_self_report(&self, account_id: u32) -> Result { let ctx = self.get_context(account_id).await?; Ok(ctx.draft_self_report().await?.to_u32()) diff --git a/src/blob.rs b/src/blob.rs index 6b3ec5846..f2622420a 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -193,6 +193,7 @@ impl<'a> BlobObject<'a> { /// Note that this is NOT the user-visible filename, /// which is only stored in Param::Filename on the message. /// + #[allow(rustdoc::private_intra_doc_links)] /// [Params]: crate::param::Params pub fn as_name(&self) -> &str { &self.name @@ -251,6 +252,7 @@ impl<'a> BlobObject<'a> { Ok(blob.as_name().to_string()) } + /// Recode image to avatar size. pub async fn recode_to_avatar_size(&mut self, context: &Context) -> Result<()> { let (img_wh, max_bytes) = match MediaQuality::from_i32(context.get_config_int(Config::MediaQuality).await?) diff --git a/src/lib.rs b/src/lib.rs index f63a20baa..803bb8fe1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,7 +52,7 @@ pub(crate) mod events; pub use events::*; mod aheader; -mod blob; +pub mod blob; pub mod chat; pub mod chatlist; pub mod config;