Can request any media file
This commit is contained in:
@@ -55,3 +55,13 @@ pub async fn serve_media(req: HttpRequest, media: OwnedMxcUri) -> HttpResult {
|
|||||||
.insert_header(("cache-control", "max-age=360000"))
|
.insert_header(("cache-control", "max-age=360000"))
|
||||||
.body(media))
|
.body(media))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
pub struct MediaMXCInPath {
|
||||||
|
mxc: OwnedMxcUri,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Save media resource handler
|
||||||
|
pub async fn serve_media_res(req: HttpRequest, media: web::Path<MediaMXCInPath>) -> HttpResult {
|
||||||
|
serve_media(req, media.into_inner().mxc).await
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::controllers::HttpResult;
|
use crate::controllers::HttpResult;
|
||||||
use crate::controllers::matrix::media_controller;
|
use crate::controllers::matrix::matrix_media_controller;
|
||||||
use crate::extractors::matrix_client_extractor::MatrixClientExtractor;
|
use crate::extractors::matrix_client_extractor::MatrixClientExtractor;
|
||||||
use actix_web::{HttpRequest, HttpResponse, web};
|
use actix_web::{HttpRequest, HttpResponse, web};
|
||||||
use futures_util::{StreamExt, stream};
|
use futures_util::{StreamExt, stream};
|
||||||
@@ -72,5 +72,5 @@ pub async fn room_avatar(
|
|||||||
return Ok(HttpResponse::NotFound().json("Room has no avatar"));
|
return Ok(HttpResponse::NotFound().json("Room has no avatar"));
|
||||||
};
|
};
|
||||||
|
|
||||||
media_controller::serve_media(req, uri).await
|
matrix_media_controller::serve_media(req, uri).await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
|
pub mod matrix_media_controller;
|
||||||
pub mod matrix_profile_controller;
|
pub mod matrix_profile_controller;
|
||||||
pub mod matrix_room_controller;
|
pub mod matrix_room_controller;
|
||||||
pub mod media_controller;
|
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ use actix_web::{App, HttpServer, web};
|
|||||||
use matrixgw_backend::app_config::AppConfig;
|
use matrixgw_backend::app_config::AppConfig;
|
||||||
use matrixgw_backend::broadcast_messages::BroadcastMessage;
|
use matrixgw_backend::broadcast_messages::BroadcastMessage;
|
||||||
use matrixgw_backend::constants;
|
use matrixgw_backend::constants;
|
||||||
use matrixgw_backend::controllers::matrix::{matrix_profile_controller, matrix_room_controller};
|
use matrixgw_backend::controllers::matrix::{
|
||||||
|
matrix_media_controller, matrix_profile_controller, matrix_room_controller,
|
||||||
|
};
|
||||||
use matrixgw_backend::controllers::{
|
use matrixgw_backend::controllers::{
|
||||||
auth_controller, matrix_link_controller, matrix_sync_thread_controller, server_controller,
|
auth_controller, matrix_link_controller, matrix_sync_thread_controller, server_controller,
|
||||||
tokens_controller, ws_controller,
|
tokens_controller, ws_controller,
|
||||||
@@ -157,6 +159,11 @@ async fn main() -> std::io::Result<()> {
|
|||||||
"/api/matrix/profile/get_multiple",
|
"/api/matrix/profile/get_multiple",
|
||||||
web::post().to(matrix_profile_controller::get_multiple),
|
web::post().to(matrix_profile_controller::get_multiple),
|
||||||
)
|
)
|
||||||
|
// Matrix media controller
|
||||||
|
.route(
|
||||||
|
"/api/matrix/media/{mxc}",
|
||||||
|
web::get().to(matrix_media_controller::serve_media_res),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.workers(4)
|
.workers(4)
|
||||||
.bind(&AppConfig::get().listen_address)?
|
.bind(&AppConfig::get().listen_address)?
|
||||||
|
|||||||
Reference in New Issue
Block a user