feat: seperate internal and external cdn urls
continuous-integration/drone/push Build is failing Details
continuous-integration/drone/tag Build is failing Details
continuous-integration/drone Build is passing Details
ci/woodpecker/manual/central-override Pipeline was successful Details
ci/woodpecker/tag/central-override Pipeline failed Details

This commit is contained in:
Timo Ley 2024-03-15 13:14:29 +01:00
parent b42e35da45
commit 916f1b4a45
4 changed files with 17 additions and 10 deletions

View File

@ -62,7 +62,7 @@ async fn users(Extension(service): Extension<JMService>) -> Result<impl IntoResp
let users = sql::get_users(&service.db_pool).await?;
Ok(HtmlTemplate(DirTemplate {
entries: users,
prefix: service.cdn_url(),
prefix: service.int_cdn_url(),
suffix: "/".to_string(),
}))
}

View File

@ -9,7 +9,8 @@ use crate::{error::JMError, JMService, JMServiceInner};
pub struct Config {
pub addr: SocketAddr,
pub database: String,
pub cdn: String,
pub int_cdn: String,
pub ext_cdn: String,
pub ipfs_api: Url,
pub matrix_url: Url,
pub matrix_token: String,
@ -23,7 +24,8 @@ impl Config {
client,
db_pool,
ipfs_url: self.ipfs_api.clone(),
cdn_url: self.cdn.clone(),
int_cdn: self.int_cdn.clone(),
ext_cdn: self.ext_cdn.clone(),
matrix_url: self.matrix_url.clone(),
matrix_token: self.matrix_token.clone(),
matrix_domain: self.matrix_domain.clone(),
@ -32,7 +34,11 @@ impl Config {
}
impl JMServiceInner {
pub fn cdn_url(&self) -> String {
self.cdn_url.clone()
pub fn int_cdn_url(&self) -> String {
self.int_cdn.clone()
}
pub fn ext_cdn_url(&self) -> String {
self.ext_cdn.clone()
}
}

View File

@ -37,7 +37,8 @@ pub struct JMServiceInner {
client: Client,
db_pool: PgPool,
ipfs_url: Url,
cdn_url: String,
int_cdn: String,
ext_cdn: String,
matrix_url: Url,
matrix_token: String,
matrix_domain: String,

View File

@ -22,7 +22,7 @@ async fn meme(
.get_meme(params.id)
.await?
.ok_or_else(|| APIError::NotFound("Meme not found".to_string()))?,
service.cdn_url(),
service.ext_cdn_url(),
);
Ok(Json(MemeResponse {
status: 200,
@ -39,7 +39,7 @@ async fn memes(
.get_memes(params.into())
.await?
.into_iter()
.map(|meme| V1Meme::new(meme, service.cdn_url()))
.map(|meme| V1Meme::new(meme, service.ext_cdn_url()))
.collect();
Ok(Json(MemesResponse {
status: 200,
@ -104,7 +104,7 @@ async fn random(
) -> Result<impl IntoResponse, APIError> {
let random = V1Meme::new(
service.get_random_meme(params.into()).await?,
service.cdn_url(),
service.ext_cdn_url(),
);
Ok(Json(MemeResponse {
status: 200,
@ -181,7 +181,7 @@ async fn upload(
service.ipfs_pin(f.hash).await?;
links.push(format!(
"{}/{}/{}",
service.cdn_url(),
service.ext_cdn_url(),
user.id.clone(),
f.name.clone()
));