fix: share URL respects scheme in OXICLOUD_SERVER_HOST (#103)

When OXICLOUD_SERVER_HOST contains a full URL with scheme (e.g.
https://oxi.example.com), the share link no longer prepends
http:// or appends :port, avoiding malformed URLs like
http://https://host:8085/s/token.

- Add AppConfig::base_url() helper with smart URL construction
- Replace all 6 inline format!() calls in share_service.rs
- Replace inline construction in di.rs (admin settings base URL)
- Priority: OXICLOUD_BASE_URL > full-URL host > http://host:port
This commit is contained in:
Dionisio
2026-02-14 00:18:59 +01:00
parent 82dd7a5c56
commit 099d1d1c55
3 changed files with 29 additions and 9 deletions
+6 -6
View File
@@ -158,7 +158,7 @@ impl ShareUseCase for ShareService {
.map_err(|e| ShareServiceError::Repository(e.to_string()))?;
// Convert the entity to DTO for the response
Ok(ShareDto::from_entity(&saved_share, &format!("http://{}:{}", self.config.server_host, self.config.server_port)))
Ok(ShareDto::from_entity(&saved_share, &self.config.base_url()))
}
async fn get_shared_link(&self, id: &str) -> Result<ShareDto, DomainError> {
@@ -175,7 +175,7 @@ impl ShareUseCase for ShareService {
}
// Convert the entity to DTO for the response
Ok(ShareDto::from_entity(&share, &format!("http://{}:{}", self.config.server_host, self.config.server_port)))
Ok(ShareDto::from_entity(&share, &self.config.base_url()))
}
async fn get_shared_link_by_token(&self, token: &str) -> Result<ShareDto, DomainError> {
@@ -192,7 +192,7 @@ impl ShareUseCase for ShareService {
}
// Convert the entity to DTO for the response
Ok(ShareDto::from_entity(&share, &format!("http://{}:{}", self.config.server_host, self.config.server_port)))
Ok(ShareDto::from_entity(&share, &self.config.base_url()))
}
async fn get_shared_links_for_item(
@@ -213,7 +213,7 @@ impl ShareUseCase for ShareService {
// Convert the entities to DTOs for the response
let share_dtos = active_shares
.iter()
.map(|s| ShareDto::from_entity(s, &format!("http://{}:{}", self.config.server_host, self.config.server_port)))
.map(|s| ShareDto::from_entity(s, &self.config.base_url()))
.collect();
Ok(share_dtos)
@@ -264,7 +264,7 @@ impl ShareUseCase for ShareService {
.map_err(|e| ShareServiceError::Repository(e.to_string()))?;
// Convert the entity to DTO for the response
Ok(ShareDto::from_entity(&updated_share, &format!("http://{}:{}", self.config.server_host, self.config.server_port)))
Ok(ShareDto::from_entity(&updated_share, &self.config.base_url()))
}
async fn delete_shared_link(&self, id: &str) -> Result<(), DomainError> {
@@ -296,7 +296,7 @@ impl ShareUseCase for ShareService {
// Convert the entities to DTOs
let share_dtos: Vec<ShareDto> = shares
.iter()
.map(|s| ShareDto::from_entity(s, &format!("http://{}:{}", self.config.server_host, self.config.server_port)))
.map(|s| ShareDto::from_entity(s, &self.config.base_url()))
.collect();
// Create the paginated result