mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
fix(config): carry the public port into derived endpoints (#2329)
This commit is contained in:
@@ -39,7 +39,9 @@ impl MediaProxyUrlBuilder {
|
||||
anyhow::bail!("gifs shard requires FLUXER_MEDIA_PROXY_SECRET_KEY");
|
||||
}
|
||||
|
||||
let endpoint = endpoint.trim_end_matches('/').to_owned();
|
||||
let endpoint = fluxer_common::config::normalize_public_endpoint_from_env(
|
||||
endpoint.trim_end_matches('/'),
|
||||
);
|
||||
let endpoint_host = Url::parse(&endpoint)
|
||||
.ok()
|
||||
.and_then(|parsed| parsed.host_str().map(ToOwned::to_owned));
|
||||
@@ -86,6 +88,8 @@ mod tests {
|
||||
"FLUXER_MEDIA_ENDPOINT",
|
||||
"FLUXER_MEDIA_PROXY_ENDPOINT",
|
||||
"FLUXER_MEDIA_PROXY_SECRET_KEY",
|
||||
"FLUXER_BASE_DOMAIN",
|
||||
"FLUXER_PUBLIC_PORT",
|
||||
];
|
||||
let saved = keys
|
||||
.iter()
|
||||
@@ -187,6 +191,55 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_env_inserts_a_non_default_public_port() -> anyhow::Result<()> {
|
||||
with_media_proxy_env(
|
||||
&[
|
||||
(
|
||||
"FLUXER_MEDIA_PROXY_PUBLIC_ENDPOINT",
|
||||
Some("http://fluxer.example/media"),
|
||||
),
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", Some("secret")),
|
||||
("FLUXER_BASE_DOMAIN", Some("fluxer.example")),
|
||||
("FLUXER_PUBLIC_PORT", Some("19080")),
|
||||
],
|
||||
|| {
|
||||
let builder = MediaProxyUrlBuilder::from_env()?;
|
||||
|
||||
assert_eq!(builder.endpoint, "http://fluxer.example:19080/media");
|
||||
assert_eq!(builder.endpoint_host.as_deref(), Some("fluxer.example"));
|
||||
assert!(
|
||||
builder
|
||||
.external_proxy_url("https://img.example.net/a.webp")
|
||||
.expect("proxy url")
|
||||
.starts_with("http://fluxer.example:19080/media/external/")
|
||||
);
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_env_leaves_a_default_public_port_alone() -> anyhow::Result<()> {
|
||||
with_media_proxy_env(
|
||||
&[
|
||||
(
|
||||
"FLUXER_MEDIA_PROXY_PUBLIC_ENDPOINT",
|
||||
Some("https://fluxer.example/media"),
|
||||
),
|
||||
("FLUXER_MEDIA_PROXY_SECRET_KEY", Some("secret")),
|
||||
("FLUXER_BASE_DOMAIN", Some("fluxer.example")),
|
||||
("FLUXER_PUBLIC_PORT", Some("443")),
|
||||
],
|
||||
|| {
|
||||
let builder = MediaProxyUrlBuilder::from_env()?;
|
||||
|
||||
assert_eq!(builder.endpoint, "https://fluxer.example/media");
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_env_rejects_internal_proxy_endpoint_without_public_endpoint() -> anyhow::Result<()> {
|
||||
with_media_proxy_env(
|
||||
|
||||
Reference in New Issue
Block a user