BlueGit

ict rusty-teams

Files

rusty-teams / crates / core / src / library.rs

library.rs

library.rs 1.7 KiB Download Raw
1use graph::{DriveEntry, DriveFolder, UploadDestination, UploadedFile};
2
3use crate::engine::{Conversation, SyncEngine};
4use crate::error::{Error, Result};
5use crate::remote::Remote;
6
7impl<R: Remote> SyncEngine<R> {
8 pub async fn channel_library_root(&self, channel_id: &str) -> Result<DriveEntry> {
9 let Conversation::Channel { team_id } = self.resolve(channel_id).await? else {
10 return Err(Error::Unsupported("a library for a chat"));
11 };
12 self.remote.channel_files_root(&team_id, channel_id).await
13 }
14
15 pub async fn channel_tab_web_url(
16 &self,
17 channel_id: &str,
18 tab_id: &str,
19 ) -> Result<Option<String>> {
20 let Conversation::Channel { team_id } = self.resolve(channel_id).await? else {
21 return Err(Error::Unsupported("a tab link for a chat"));
22 };
23 self.remote
24 .channel_tab_web_url(&team_id, channel_id, tab_id)
25 .await
26 }
27
28 pub async fn library_children(&self, folder: &DriveFolder) -> Result<Vec<DriveEntry>> {
29 self.remote.list_children(folder).await
30 }
31
32 pub async fn create_library_folder(
33 &self,
34 parent: &DriveFolder,
35 name: &str,
36 ) -> Result<DriveEntry> {
37 self.remote.create_folder(parent, name).await
38 }
39
40 pub async fn upload_to_library(
41 &self,
42 folder: &DriveFolder,
43 file_name: &str,
44 bytes: &[u8],
45 progress: impl Fn(u8) + Send + Sync,
46 ) -> Result<UploadedFile> {
47 self.remote
48 .upload_file(
49 &UploadDestination::Folder(folder.clone()),
50 file_name,
51 bytes,
52 &progress,
53 )
54 .await
55 }
56}