Skip to content

Commit 3d061d1

Browse files
authored
feat(jsonrpc): add copy_to_blobdir api (#6660)
Add a new API to jsonrpc to copy a file over to blobdir. This enables desktop tauri to not give global file permission.
1 parent 156f964 commit 3d061d1

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

deltachat-jsonrpc/src/api.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use std::collections::BTreeMap;
2-
use std::path::Path;
2+
use std::path::{Path, PathBuf};
33
use std::str;
44
use std::sync::Arc;
55
use std::time::Duration;
66
use std::{collections::HashMap, str::FromStr};
77

88
use anyhow::{anyhow, bail, ensure, Context, Result};
99
pub use deltachat::accounts::Accounts;
10+
use deltachat::blob::BlobObject;
1011
use deltachat::chat::{
1112
self, add_contact_to_chat, forward_msgs, get_chat_media, get_chat_msgs, get_chat_msgs_ex,
1213
marknoticed_chat, remove_contact_from_chat, Chat, ChatId, ChatItem, MessageListOptions,
@@ -341,11 +342,19 @@ impl CommandApi {
341342
ctx.get_info().await
342343
}
343344

345+
/// Get the blob dir.
344346
async fn get_blob_dir(&self, account_id: u32) -> Result<Option<String>> {
345347
let ctx = self.get_context(account_id).await?;
346348
Ok(ctx.get_blobdir().to_str().map(|s| s.to_owned()))
347349
}
348350

351+
/// Copy file to blobdir.
352+
async fn copy_to_blobdir(&self, account_id: u32, path: String) -> Result<PathBuf> {
353+
let ctx = self.get_context(account_id).await?;
354+
let file = Path::new(&path);
355+
Ok(BlobObject::create_and_deduplicate(&ctx, file, file)?.to_abs_path())
356+
}
357+
349358
async fn draft_self_report(&self, account_id: u32) -> Result<u32> {
350359
let ctx = self.get_context(account_id).await?;
351360
Ok(ctx.draft_self_report().await?.to_u32())

src/blob.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ impl<'a> BlobObject<'a> {
193193
/// Note that this is NOT the user-visible filename,
194194
/// which is only stored in Param::Filename on the message.
195195
///
196+
#[allow(rustdoc::private_intra_doc_links)]
196197
/// [Params]: crate::param::Params
197198
pub fn as_name(&self) -> &str {
198199
&self.name
@@ -251,6 +252,7 @@ impl<'a> BlobObject<'a> {
251252
Ok(blob.as_name().to_string())
252253
}
253254

255+
/// Recode image to avatar size.
254256
pub async fn recode_to_avatar_size(&mut self, context: &Context) -> Result<()> {
255257
let (img_wh, max_bytes) =
256258
match MediaQuality::from_i32(context.get_config_int(Config::MediaQuality).await?)

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub(crate) mod events;
5252
pub use events::*;
5353

5454
mod aheader;
55-
mod blob;
55+
pub mod blob;
5656
pub mod chat;
5757
pub mod chatlist;
5858
pub mod config;

0 commit comments

Comments
 (0)