Skip to main content

openai_interface/containers/files/
delete.rs

1//! Delete a container file via
2//! `DELETE /containers/{container_id}/files/{file_id}`.
3//!
4//! > ![warn] This module is untested!
5//! > If you encounter any issues, please report them on the repository.
6
7use url::Url;
8
9use crate::{
10    errors::OapiError,
11    rest::delete::{Delete, DeleteNoStream},
12};
13
14/// Deletes a file from a container.
15#[derive(Debug, Clone)]
16pub struct DeleteContainerFileRequest<'a> {
17    /// The ID of the container, e.g. `cntr_...`.
18    pub container_id: &'a str,
19    /// The ID of the container file, e.g. `cfile_...`.
20    pub file_id: &'a str,
21}
22
23impl Delete for DeleteContainerFileRequest<'_> {
24    /// Builds the URL for the request.
25    ///
26    /// `base_url` should be like <https://api.openai.com/v1>
27    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
28        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
29        url.path_segments_mut()
30            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
31            .push("containers")
32            .push(self.container_id)
33            .push("files")
34            .push(self.file_id);
35        Ok(url.to_string())
36    }
37}
38
39impl DeleteNoStream for DeleteContainerFileRequest<'_> {
40    type Response = DeleteContainerFileResponse;
41}
42
43/// The response of a container file deletion.
44#[derive(Debug, Clone, serde::Deserialize)]
45pub struct DeleteContainerFileResponse {
46    /// The ID of the container file that was deleted.
47    pub id: String,
48    /// Whether the file was deleted successfully.
49    pub deleted: bool,
50    /// The object type (`container.file.deleted`), if the provider
51    /// sends it.
52    #[serde(default)]
53    pub object: Option<String>,
54}
55
56crate::impl_from_str!(DeleteContainerFileResponse);