feat(bridge,ui): preserve file names and use system opener
- Add mattermost-download-dir custom (default ~/Downloads) - Pass file_name and download_dir in download_file request - Save files with original names in user-configured directory - Open downloaded files via xdg-open (system default application)
This commit is contained in:
@@ -294,6 +294,25 @@ impl MattermostClient {
|
||||
let post: Post = response.json().await.map_err(ClientError::Http)?;
|
||||
Ok(post)
|
||||
}
|
||||
|
||||
/// Download a file by its ID. Returns the file bytes.
|
||||
pub async fn download_file(&self, token: &str, file_id: &str) -> Result<Vec<u8>, ClientError> {
|
||||
let url = format!("{}/api/v4/files/{}", self.base_url, file_id);
|
||||
let response = self
|
||||
.client
|
||||
.get(&url)
|
||||
.header(AUTHORIZATION, format!("Bearer {}", token))
|
||||
.send()
|
||||
.await
|
||||
.map_err(ClientError::Http)?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
return Err(api_error(response).await);
|
||||
}
|
||||
|
||||
let bytes = response.bytes().await.map_err(ClientError::Http)?;
|
||||
Ok(bytes.to_vec())
|
||||
}
|
||||
}
|
||||
|
||||
/// Accept `[fileinfo, ...]`, `{file_infos: [...]}`, or
|
||||
|
||||
Reference in New Issue
Block a user