Skip to content

Commit

Permalink
feat: change env names
Browse files Browse the repository at this point in the history
  • Loading branch information
delbertbeta committed Feb 6, 2025
1 parent 9beb67e commit 510c775
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
24 changes: 11 additions & 13 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ pub struct Envs {
pub prod: bool,
pub redis_url: String,
pub rust_log: String,
pub cos_bucket_region: String,
pub cos_bucket_name: String,
pub qcloud_secret_id: String,
pub qcloud_secret_key: String,
pub bucket_region: String,
pub bucket_name: String,
pub bucket_secret_id: String,
pub bucket_secret_key: String,
pub cdn_base_url: String,
}

Expand Down Expand Up @@ -49,18 +49,16 @@ lazy_static! {
redis_url: env::var("REDIS_URL").expect("REDIS_URL is not set in .env file"),
rust_log: std::env::var("RUST_LOG")
.unwrap_or_else(|_| "sso_rs=debug,tower_http=trace".into()),
cos_bucket_region: env::var("COS_BUCKET_REGION")
.expect("COS_BUCKET_REGION is not set in .env file"),
cos_bucket_name: env::var("COS_BUCKET_NAME")
.expect("COS_BUCKET_NAME is not set in .env file"),
qcloud_secret_id: env::var("QCLOUD_SECRET_ID")
.expect("QCLOUD_SECRET_ID is not set in .env file"),
qcloud_secret_key: env::var("QCLOUD_SECRET_KEY")
.expect("QCLOUD_SECRET_KEY is not set in .env file"),
bucket_region: env::var("BUCKET_REGION").expect("BUCKET_REGION is not set in .env file"),
bucket_name: env::var("BUCKET_NAME").expect("BUCKET_NAME is not set in .env file"),
bucket_secret_id: env::var("BUCKET_SECRET_ID")
.expect("BUCKET_SECRET_ID is not set in .env file"),
bucket_secret_key: env::var("BUCKET_SECRET_KEY")
.expect("BUCKET_SECRET_KEY is not set in .env file"),
cdn_base_url: env::var("CDN_BASE_URL").expect("CDN_BASE_URL is not set in .env file"),
};
pub static ref SECRETS: Secrets<'static> =
Secrets::new(&ENVS.qcloud_secret_id, &ENVS.qcloud_secret_key);
Secrets::new(&ENVS.bucket_secret_id, &ENVS.bucket_secret_key);
pub static ref SUPPORT_IMAGE_TYPE: HashSet<&'static str> =
HashSet::from(["gif", "bmp", "jpg", "jpeg", "png", "webp"]);
}
4 changes: 2 additions & 2 deletions src/route/api/image/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub async fn handler(

let res = qcloud::cos::object::head(
&SECRETS,
&ENVS.cos_bucket_name,
&ENVS.cos_bucket_region,
&ENVS.bucket_name,
&ENVS.bucket_region,
&image_model.path,
)
.await?;
Expand Down
10 changes: 5 additions & 5 deletions src/route/api/image/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ pub async fn handler<'a>(

let policy = get_policy(vec![(
"name/cos:PutObject",
ENVS.cos_bucket_name.as_str(),
ENVS.cos_bucket_region.as_str(),
ENVS.bucket_name.as_str(),
ENVS.bucket_region.as_str(),
path.as_str(),
)
.into()]);

let credential = get_credential(&SECRETS, &policy, &ENVS.cos_bucket_region, 600).await?;
let credential = get_credential(&SECRETS, &policy, &ENVS.bucket_region, 600).await?;

let credential = match credential.response {
StsResponse::Success(res) => res,
Expand All @@ -85,8 +85,8 @@ pub async fn handler<'a>(
Ok(OkResponse::new(SuccessResponse {
image_id: id,
image_path: path,
bucket: &ENVS.cos_bucket_name,
region: &ENVS.cos_bucket_region,
bucket: &ENVS.bucket_name,
region: &ENVS.bucket_region,
token: TokenResponse {
tmp_secret_id: credential.credentials.tmp_secret_id,
tmp_secret_key: credential.credentials.tmp_secret_key,
Expand Down

0 comments on commit 510c775

Please sign in to comment.