use snafu::ResultExt;
use std::sync::Arc;
use super::*;
use crate::client::GeminiClient;
#[derive(Clone)]
pub struct FileHandle {
inner: super::model::File,
client: Arc<GeminiClient>,
}
impl FileHandle {
pub(crate) fn new(client: Arc<GeminiClient>, inner: super::model::File) -> Self {
Self { inner, client }
}
pub fn name(&self) -> &str {
&self.inner.name
}
pub fn get_file_meta(&self) -> &super::model::File {
&self.inner
}
pub async fn delete(self) -> Result<(), (Self, Error)> {
match self
.client
.delete_file(&self.inner.name)
.await
.context(ClientSnafu)
{
Ok(_) => Ok(()),
Err(e) => Err((self, e)),
}
}
pub async fn download(&self) -> Result<Vec<u8>, Error> {
self.client
.download_file(self.name())
.await
.context(ClientSnafu)
}
}