BlueGit

ict rusty-teams

Files

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

library.rs

library.rs 2.0 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 channel_member_count(&self, channel_id: &str) -> Result<usize> {
29 let Conversation::Channel { team_id } = self.resolve(channel_id).await? else {
30 return Err(Error::Unsupported("a member count for a chat"));
31 };
32 self.remote.channel_member_count(&team_id, channel_id).await
33 }
34
35 pub async fn library_children(&self, folder: &DriveFolder) -> Result<Vec<DriveEntry>> {
36 self.remote.list_children(folder).await
37 }
38
39 pub async fn create_library_folder(
40 &self,
41 parent: &DriveFolder,
42 name: &str,
43 ) -> Result<DriveEntry> {
44 self.remote.create_folder(parent, name).await
45 }
46
47 pub async fn upload_to_library(
48 &self,
49 folder: &DriveFolder,
50 file_name: &str,
51 bytes: &[u8],
52 progress: impl Fn(u8) + Send + Sync,
53 ) -> Result<UploadedFile> {
54 self.remote
55 .upload_file(
56 &UploadDestination::Folder(folder.clone()),
57 file_name,
58 bytes,
59 &progress,
60 )
61 .await
62 }
63}