fn build()

in core/src/services/upyun/backend.rs [135:226]


    fn build(self) -> Result<impl Access> {
        debug!("backend build started: {:?}", &self);

        let root = normalize_root(&self.config.root.clone().unwrap_or_default());
        debug!("backend use root {}", &root);

        // Handle bucket.
        if self.config.bucket.is_empty() {
            return Err(Error::new(ErrorKind::ConfigInvalid, "bucket is empty")
                .with_operation("Builder::build")
                .with_context("service", Scheme::Upyun));
        }

        debug!("backend use bucket {}", &self.config.bucket);

        let operator = match &self.config.operator {
            Some(operator) => Ok(operator.clone()),
            None => Err(Error::new(ErrorKind::ConfigInvalid, "operator is empty")
                .with_operation("Builder::build")
                .with_context("service", Scheme::Upyun)),
        }?;

        let password = match &self.config.password {
            Some(password) => Ok(password.clone()),
            None => Err(Error::new(ErrorKind::ConfigInvalid, "password is empty")
                .with_operation("Builder::build")
                .with_context("service", Scheme::Upyun)),
        }?;

        let signer = UpyunSigner {
            operator: operator.clone(),
            password: password.clone(),
        };

        Ok(UpyunBackend {
            core: Arc::new(UpyunCore {
                info: {
                    let am = AccessorInfo::default();
                    am.set_scheme(Scheme::Upyun)
                        .set_root(&root)
                        .set_native_capability(Capability {
                            stat: true,
                            stat_has_content_length: true,
                            stat_has_content_type: true,
                            stat_has_content_md5: true,
                            stat_has_cache_control: true,
                            stat_has_content_disposition: true,

                            create_dir: true,

                            read: true,

                            write: true,
                            write_can_empty: true,
                            write_can_multi: true,
                            write_with_cache_control: true,
                            write_with_content_type: true,

                            // https://help.upyun.com/knowledge-base/rest_api/#e5b9b6e8a18ce5bc8fe696ade782b9e7bbade4bca0
                            write_multi_min_size: Some(1024 * 1024),
                            write_multi_max_size: Some(50 * 1024 * 1024),

                            delete: true,
                            rename: true,
                            copy: true,

                            list: true,
                            list_with_limit: true,
                            list_has_content_length: true,
                            list_has_content_type: true,
                            list_has_last_modified: true,

                            shared: true,

                            ..Default::default()
                        });

                    // allow deprecated api here for compatibility
                    #[allow(deprecated)]
                    if let Some(client) = self.http_client {
                        am.update_http_client(|_| client);
                    }

                    am.into()
                },
                root,
                operator,
                bucket: self.config.bucket.clone(),
                signer,
            }),
        })
    }