pub struct ChannelManager { /* private fields */ }Expand description
Channel manager - handles channel-specific file operations
Provides logical isolation and tracking for files across different channels. The actual file storage is global and shared via SHA256 deduplication.
Implementations§
Source§impl ChannelManager
impl ChannelManager
Sourcepub async fn new(
file_manager: Arc<FileManager>,
db_path: PathBuf,
) -> Result<Self>
pub async fn new( file_manager: Arc<FileManager>, db_path: PathBuf, ) -> Result<Self>
Create a new channel manager
§Arguments
file_manager- Shared FileManager for file storagedb_path- Path to the channel metadata database
§Example
use agent_diva_files::FileManager;
use agent_diva_files::channel::ChannelManager;
let file_manager = FileManager::new(config).await?;
let channel_manager = ChannelManager::new(
Arc::new(file_manager),
PathBuf::from("channels.db"),
).await?;Sourcepub async fn upload_to_channel(
&self,
channel_id: &str,
data: &[u8],
metadata: FileMetadata,
uploaded_by: Option<&str>,
message_id: Option<&str>,
) -> Result<FileHandle>
pub async fn upload_to_channel( &self, channel_id: &str, data: &[u8], metadata: FileMetadata, uploaded_by: Option<&str>, message_id: Option<&str>, ) -> Result<FileHandle>
Upload a file to a specific channel
If the file content already exists (same SHA256 hash), it will be deduplicated and associated with the new channel instead of storing duplicate data.
§Arguments
channel_id- The channel identifier (e.g., “telegram:chat_123”)data- File content bytesmetadata- File metadata (name, size, mime_type, etc.)uploaded_by- Optional uploader identifiermessage_id- Optional associated message ID
§Returns
A FileHandle for the stored file
§Example
let handle = channel_manager
.upload_to_channel(
"telegram:chat_123",
b"file content",
FileMetadata { name: "document.pdf", .. },
Some("user_456"),
Some("msg_789"),
)
.await?;Sourcepub async fn add_file_to_channel(
&self,
channel_id: &str,
file_id: &str,
uploaded_by: Option<&str>,
message_id: Option<&str>,
) -> Result<bool>
pub async fn add_file_to_channel( &self, channel_id: &str, file_id: &str, uploaded_by: Option<&str>, message_id: Option<&str>, ) -> Result<bool>
Add an existing file to a channel
Use this when a file has already been uploaded and you just want to associate it with a channel.
§Returns
Ok(true) if a new association was created, Ok(false) if it already existed
Sourcepub async fn list_channel_files(
&self,
channel_id: &str,
) -> Result<Vec<ChannelFileInfo>>
pub async fn list_channel_files( &self, channel_id: &str, ) -> Result<Vec<ChannelFileInfo>>
List all files in a channel
Returns files with their channel-specific metadata (uploader, upload time, etc.)
§Arguments
channel_id- The channel to list files for
§Returns
List of files in the channel, newest first
§Example
let files = channel_manager.list_channel_files("telegram:chat_123").await?;
for info in files {
println!("{} - uploaded by {:?} at {}",
info.file.id, info.uploaded_by, info.uploaded_at);
}Sourcepub async fn get_channel_file(
&self,
channel_id: &str,
file_id: &str,
) -> Result<FileHandle>
pub async fn get_channel_file( &self, channel_id: &str, file_id: &str, ) -> Result<FileHandle>
Sourcepub async fn remove_from_channel(
&self,
channel_id: &str,
file_id: &str,
) -> Result<bool>
pub async fn remove_from_channel( &self, channel_id: &str, file_id: &str, ) -> Result<bool>
Remove a file from a channel (but don’t delete the actual file)
This only removes the channel association, not the physical file. The file will continue to exist if other channels reference it.
§Arguments
channel_id- The channel to remove fromfile_id- The file to remove
§Returns
Ok(true) if association was removed, Ok(false) if it didn’t exist
Sourcepub async fn delete_channel(
&self,
channel_id: &str,
cleanup: bool,
) -> Result<usize>
pub async fn delete_channel( &self, channel_id: &str, cleanup: bool, ) -> Result<usize>
Delete an entire channel
§Arguments
channel_id- The channel to deletecleanup- Iftrue, also delete files that are only in this channel Iffalse, only remove the channel associations
§Behavior
With cleanup = false:
- Only removes channel_file associations
- Physical files remain and can still be accessed via other channels
With cleanup = true:
- Removes channel_file associations
- For files unique to this channel, also soft-deletes them
- Files shared with other channels are NOT deleted
§Example
// Delete channel but keep shared files
channel_manager.delete_channel("temp_channel", false).await?;
// Delete channel and cleanup unique files
channel_manager.delete_channel("archive_channel", true).await?;Sourcepub async fn channel_stats(&self, channel_id: &str) -> Result<ChannelStats>
pub async fn channel_stats(&self, channel_id: &str) -> Result<ChannelStats>
Get statistics for a channel
§Returns
ChannelStats with total files, total size, and unique files count
Sourcepub async fn list_channels(&self) -> Result<Vec<String>>
pub async fn list_channels(&self) -> Result<Vec<String>>
Auto Trait Implementations§
impl Freeze for ChannelManager
impl !RefUnwindSafe for ChannelManager
impl Send for ChannelManager
impl Sync for ChannelManager
impl Unpin for ChannelManager
impl UnsafeUnpin for ChannelManager
impl !UnwindSafe for ChannelManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more