feat: seperate internal and external cdn urls
Some checks failed
Some checks failed
This commit is contained in:
parent
b42e35da45
commit
916f1b4a45
4 changed files with 17 additions and 10 deletions
|
@ -62,7 +62,7 @@ async fn users(Extension(service): Extension<JMService>) -> Result<impl IntoResp
|
||||||
let users = sql::get_users(&service.db_pool).await?;
|
let users = sql::get_users(&service.db_pool).await?;
|
||||||
Ok(HtmlTemplate(DirTemplate {
|
Ok(HtmlTemplate(DirTemplate {
|
||||||
entries: users,
|
entries: users,
|
||||||
prefix: service.cdn_url(),
|
prefix: service.int_cdn_url(),
|
||||||
suffix: "/".to_string(),
|
suffix: "/".to_string(),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,8 @@ use crate::{error::JMError, JMService, JMServiceInner};
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub addr: SocketAddr,
|
pub addr: SocketAddr,
|
||||||
pub database: String,
|
pub database: String,
|
||||||
pub cdn: String,
|
pub int_cdn: String,
|
||||||
|
pub ext_cdn: String,
|
||||||
pub ipfs_api: Url,
|
pub ipfs_api: Url,
|
||||||
pub matrix_url: Url,
|
pub matrix_url: Url,
|
||||||
pub matrix_token: String,
|
pub matrix_token: String,
|
||||||
|
@ -23,7 +24,8 @@ impl Config {
|
||||||
client,
|
client,
|
||||||
db_pool,
|
db_pool,
|
||||||
ipfs_url: self.ipfs_api.clone(),
|
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_url: self.matrix_url.clone(),
|
||||||
matrix_token: self.matrix_token.clone(),
|
matrix_token: self.matrix_token.clone(),
|
||||||
matrix_domain: self.matrix_domain.clone(),
|
matrix_domain: self.matrix_domain.clone(),
|
||||||
|
@ -32,7 +34,11 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JMServiceInner {
|
impl JMServiceInner {
|
||||||
pub fn cdn_url(&self) -> String {
|
pub fn int_cdn_url(&self) -> String {
|
||||||
self.cdn_url.clone()
|
self.int_cdn.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ext_cdn_url(&self) -> String {
|
||||||
|
self.ext_cdn.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,8 @@ pub struct JMServiceInner {
|
||||||
client: Client,
|
client: Client,
|
||||||
db_pool: PgPool,
|
db_pool: PgPool,
|
||||||
ipfs_url: Url,
|
ipfs_url: Url,
|
||||||
cdn_url: String,
|
int_cdn: String,
|
||||||
|
ext_cdn: String,
|
||||||
matrix_url: Url,
|
matrix_url: Url,
|
||||||
matrix_token: String,
|
matrix_token: String,
|
||||||
matrix_domain: String,
|
matrix_domain: String,
|
||||||
|
|
|
@ -22,7 +22,7 @@ async fn meme(
|
||||||
.get_meme(params.id)
|
.get_meme(params.id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| APIError::NotFound("Meme not found".to_string()))?,
|
.ok_or_else(|| APIError::NotFound("Meme not found".to_string()))?,
|
||||||
service.cdn_url(),
|
service.ext_cdn_url(),
|
||||||
);
|
);
|
||||||
Ok(Json(MemeResponse {
|
Ok(Json(MemeResponse {
|
||||||
status: 200,
|
status: 200,
|
||||||
|
@ -39,7 +39,7 @@ async fn memes(
|
||||||
.get_memes(params.into())
|
.get_memes(params.into())
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|meme| V1Meme::new(meme, service.cdn_url()))
|
.map(|meme| V1Meme::new(meme, service.ext_cdn_url()))
|
||||||
.collect();
|
.collect();
|
||||||
Ok(Json(MemesResponse {
|
Ok(Json(MemesResponse {
|
||||||
status: 200,
|
status: 200,
|
||||||
|
@ -104,7 +104,7 @@ async fn random(
|
||||||
) -> Result<impl IntoResponse, APIError> {
|
) -> Result<impl IntoResponse, APIError> {
|
||||||
let random = V1Meme::new(
|
let random = V1Meme::new(
|
||||||
service.get_random_meme(params.into()).await?,
|
service.get_random_meme(params.into()).await?,
|
||||||
service.cdn_url(),
|
service.ext_cdn_url(),
|
||||||
);
|
);
|
||||||
Ok(Json(MemeResponse {
|
Ok(Json(MemeResponse {
|
||||||
status: 200,
|
status: 200,
|
||||||
|
@ -181,7 +181,7 @@ async fn upload(
|
||||||
service.ipfs_pin(f.hash).await?;
|
service.ipfs_pin(f.hash).await?;
|
||||||
links.push(format!(
|
links.push(format!(
|
||||||
"{}/{}/{}",
|
"{}/{}/{}",
|
||||||
service.cdn_url(),
|
service.ext_cdn_url(),
|
||||||
user.id.clone(),
|
user.id.clone(),
|
||||||
f.name.clone()
|
f.name.clone()
|
||||||
));
|
));
|
||||||
|
|
Loading…
Reference in a new issue