Can request any media file

This commit is contained in:
2025-11-21 17:55:09 +01:00
parent 934e6a4cc1
commit 35b53fee5c
4 changed files with 21 additions and 4 deletions

View File

@@ -55,3 +55,13 @@ pub async fn serve_media(req: HttpRequest, media: OwnedMxcUri) -> HttpResult {
.insert_header(("cache-control", "max-age=360000"))
.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
}

View File

@@ -1,5 +1,5 @@
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 actix_web::{HttpRequest, HttpResponse, web};
use futures_util::{StreamExt, stream};
@@ -72,5 +72,5 @@ pub async fn room_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
}

View File

@@ -1,3 +1,3 @@
pub mod matrix_media_controller;
pub mod matrix_profile_controller;
pub mod matrix_room_controller;
pub mod media_controller;

View File

@@ -9,7 +9,9 @@ use actix_web::{App, HttpServer, web};
use matrixgw_backend::app_config::AppConfig;
use matrixgw_backend::broadcast_messages::BroadcastMessage;
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::{
auth_controller, matrix_link_controller, matrix_sync_thread_controller, server_controller,
tokens_controller, ws_controller,
@@ -157,6 +159,11 @@ async fn main() -> std::io::Result<()> {
"/api/matrix/profile/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)
.bind(&AppConfig::get().listen_address)?