object_storage/oss/util/
host.rs

1use anyhow::{Ok, Result};
2
3pub async fn create_host(bucket_name: Option<&str>, endpoint: &str) -> Result<String> {
4    let base_url = format!("{}.{}", endpoint, "aliyuncs.com");
5    let host = match bucket_name {
6        Some(bucket_name) => format!("{}.{}", bucket_name, base_url),
7        None => base_url,
8    };
9    Ok(host)
10}
11
12pub async fn create_url(host: &str, file_name: Option<&str>) -> Result<String> {
13    let base_url = format!("https://{}", host);
14    let url = match file_name {
15        Some(file_name) => format!("{}/{}", base_url, file_name),
16        None => base_url,
17    };
18    Ok(url)
19}
20
21pub async fn create_resource(bucket_name: &str, object_name: &str) -> Result<String> {
22    Ok(format!("/{}/{}", bucket_name, object_name))
23}