Skip to main content

adk_gemini/files/
handle.rs

1use snafu::ResultExt;
2use std::sync::Arc;
3
4use super::*;
5use crate::client::GeminiClient;
6
7/// A handle to a file on the Gemini API.
8pub struct FileHandle {
9    inner: super::model::File,
10    client: Arc<GeminiClient>,
11}
12
13impl FileHandle {
14    pub(crate) fn new(client: Arc<GeminiClient>, inner: super::model::File) -> Self {
15        Self { inner, client }
16    }
17
18    pub fn name(&self) -> &str {
19        &self.inner.name
20    }
21
22    /// Get the file metadata.
23    pub fn get_file_meta(&self) -> &super::model::File {
24        &self.inner
25    }
26
27    /// Delete the file.
28    pub async fn delete(self) -> Result<(), (Self, Error)> {
29        match self.client.delete_file(&self.inner.name).await.context(ClientSnafu) {
30            Ok(_) => Ok(()),
31            Err(e) => Err((self, e)),
32        }
33    }
34
35    /// Download the file.
36    ///
37    /// Work only for files that was generated by Gemini.
38    pub async fn download(&self) -> Result<Vec<u8>, Error> {
39        self.client.download_file(self.name()).await.context(ClientSnafu)
40    }
41}