image_thumbs/
gcs.rs

1use crate::model::Params;
2use crate::{ImageThumbs, ThumbsResult};
3use object_store::gcp::{GoogleCloudStorage, GoogleCloudStorageBuilder};
4use std::sync::Arc;
5use tokio::sync::RwLock;
6
7impl ImageThumbs<GoogleCloudStorage> {
8    /// Creates new ImageThumbs instance connected to Google Cloud Storage using the environment
9    /// variables `GOOGLE_BUCKET` and `GOOGLE_SERVICE_ACCOUNT_KEY` to connect to GCS.
10    /// The later should be in the JSON format.
11    ///
12    /// Reads the config YAML file to know which thumbnails to create
13    ///
14    /// The config file must look like the example in `examples/image_thumbs.yaml`:
15    /// ```yaml
16    #[doc = include_str!("../examples/image_thumbs.yaml")]
17    /// ```
18    ///
19    /// # Arguments
20    /// * `config` - Path to the config file from the crate root (`.yaml` may be omitted)
21    pub fn new(config: &str) -> ThumbsResult<Self> {
22        let client = GoogleCloudStorageBuilder::from_env()
23            .with_client_options(Self::client_options())
24            .build()?;
25
26        Ok(Self {
27            client: Arc::new(RwLock::new(client)),
28            settings: Arc::new(Self::settings(config)?),
29        })
30    }
31
32    pub fn new_with_settings(settings: Vec<Params>) -> ThumbsResult<Self> {
33        let client = GoogleCloudStorageBuilder::from_env()
34            .with_client_options(Self::client_options())
35            .build()?;
36
37        Ok(Self {
38            client: Arc::new(RwLock::new(client)),
39            settings: Arc::new(settings),
40        })
41    }
42}