Skip to main content

FileEventsApi

Trait FileEventsApi 

Source
pub trait FileEventsApi {
    // Required method
    fn subscribe_file_events<'life0, 'life1, 'async_trait>(
        &'life0 self,
        uri: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = ApiResult<FileEventSubscription>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

File events SSE API methods

Required Methods§

Source

fn subscribe_file_events<'life0, 'life1, 'async_trait>( &'life0 self, uri: &'life1 str, ) -> Pin<Box<dyn Future<Output = ApiResult<FileEventSubscription>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Subscribe to file events for a given URI.

This connects to the SSE endpoint at /v4/file/events with the provided URI. Returns a subscription handle that can be used to receive events.

§Arguments
  • uri - The filesystem URI to watch for events (e.g., “cloudreve://my-drive/”)
§Returns
  • Ok(FileEventSubscription) - A handle to receive events from
  • Err(ApiError::SseNotUpgraded) - If the server returned an error instead of SSE stream
  • Err(ApiError::RequestError) - If the HTTP request failed
§Example
use cloudreve_sdk_api::{Client, ClientConfig};
use cloudreve_sdk_api::api::explorer::FileEventsApi;

async fn watch_events(client: &Client) -> Result<(), Box<dyn std::error::Error>> {
    let mut subscription = client.subscribe_file_events("cloudreve://my-drive/").await?;

    while let Some(event) = subscription.next_event().await? {
        match event {
            cloudreve_sdk_api::models::explorer::FileEvent::Event(events) => {
                for data in events {
                    println!("File event: {:?} on {}", data.event_type, data.from);
                }
            }
            _ => {}
        }
    }

    Ok(())
}

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§