fn build()

in core/src/services/aliyun_drive/backend.rs [136:228]


    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);

        let sign = match self.config.access_token.clone() {
            Some(access_token) if !access_token.is_empty() => {
                AliyunDriveSign::Access(access_token)
            }
            _ => match (
                self.config.client_id.clone(),
                self.config.client_secret.clone(),
                self.config.refresh_token.clone(),
            ) {
                (Some(client_id), Some(client_secret), Some(refresh_token)) if
                !client_id.is_empty() && !client_secret.is_empty() && !refresh_token.is_empty() => {
                    AliyunDriveSign::Refresh(client_id, client_secret, refresh_token, None, 0)
                }
                _ => return Err(Error::new(
                    ErrorKind::ConfigInvalid,
                    "access_token and a set of client_id, client_secret, and refresh_token are both missing.")
                    .with_operation("Builder::build")
                    .with_context("service", Scheme::AliyunDrive)),
            },
        };

        let drive_type = match self.config.drive_type.as_str() {
            "" | "default" => DriveType::Default,
            "resource" => DriveType::Resource,
            "backup" => DriveType::Backup,
            _ => {
                return Err(Error::new(
                    ErrorKind::ConfigInvalid,
                    "drive_type is invalid.",
                ))
            }
        };
        debug!("backend use drive_type {:?}", drive_type);

        Ok(AliyunDriveBackend {
            core: Arc::new(AliyunDriveCore {
                info: {
                    let am = AccessorInfo::default();
                    am.set_scheme(Scheme::AliyunDrive)
                        .set_root(&root)
                        .set_native_capability(Capability {
                            stat: true,
                            create_dir: true,
                            read: true,
                            write: true,
                            write_can_multi: true,
                            // The min multipart size of AliyunDrive is 100 KiB.
                            write_multi_min_size: Some(100 * 1024),
                            // The max multipart size of AliyunDrive is 5 GiB.
                            write_multi_max_size: if cfg!(target_pointer_width = "64") {
                                Some(5 * 1024 * 1024 * 1024)
                            } else {
                                Some(usize::MAX)
                            },
                            delete: true,
                            copy: true,
                            rename: true,
                            list: true,
                            list_with_limit: true,
                            shared: true,
                            stat_has_content_length: true,
                            stat_has_content_type: true,
                            list_has_last_modified: true,
                            list_has_content_length: true,
                            list_has_content_type: 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()
                },
                endpoint: "https://openapi.alipan.com".to_string(),
                root,
                drive_type,
                signer: Arc::new(Mutex::new(AliyunDriveSigner {
                    drive_id: None,
                    sign,
                })),
                dir_lock: Arc::new(Mutex::new(())),
            }),
        })
    }