Can get media thumbnail
This commit is contained in:
parent
d68e3eca3b
commit
95ca1f0ba6
@ -62,7 +62,10 @@ async fn main() -> std::io::Result<()> {
|
|||||||
"/api/media/{server_name}/{media_id}/download",
|
"/api/media/{server_name}/{media_id}/download",
|
||||||
web::get().to(api::media::download),
|
web::get().to(api::media::download),
|
||||||
)
|
)
|
||||||
// TODO : handle media thumbnail
|
.route(
|
||||||
|
"/api/media/{server_name}/{media_id}/thumbnail",
|
||||||
|
web::get().to(api::media::thumbnail),
|
||||||
|
)
|
||||||
// TODO : handle space
|
// TODO : handle space
|
||||||
.route(
|
.route(
|
||||||
"/api/profile/{user_id}",
|
"/api/profile/{user_id}",
|
||||||
|
@ -2,7 +2,7 @@ use crate::extractors::client_auth::APIClientAuth;
|
|||||||
use crate::server::HttpResult;
|
use crate::server::HttpResult;
|
||||||
use actix_web::{web, HttpResponse};
|
use actix_web::{web, HttpResponse};
|
||||||
use ruma::api::client::media;
|
use ruma::api::client::media;
|
||||||
use ruma::OwnedServerName;
|
use ruma::{OwnedServerName, UInt};
|
||||||
|
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
pub struct MediaInfoInPath {
|
pub struct MediaInfoInPath {
|
||||||
@ -26,3 +26,32 @@ pub async fn download(auth: APIClientAuth, path: web::Path<MediaInfoInPath>) ->
|
|||||||
|
|
||||||
Ok(http_res.body(res.file))
|
Ok(http_res.body(res.file))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
pub struct MediaThumbnailQuery {
|
||||||
|
width: Option<UInt>,
|
||||||
|
height: Option<UInt>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a media thumbnail
|
||||||
|
pub async fn thumbnail(
|
||||||
|
auth: APIClientAuth,
|
||||||
|
path: web::Path<MediaInfoInPath>,
|
||||||
|
query: web::Query<MediaThumbnailQuery>,
|
||||||
|
) -> HttpResult {
|
||||||
|
let res = auth
|
||||||
|
.send_request(media::get_content_thumbnail::v3::Request::new(
|
||||||
|
path.media_id.clone(),
|
||||||
|
path.server_name.clone(),
|
||||||
|
query.width.unwrap_or(UInt::new(500).unwrap()),
|
||||||
|
query.height.unwrap_or(UInt::new(500).unwrap()),
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut http_res = HttpResponse::Ok();
|
||||||
|
if let Some(content_type) = res.content_type {
|
||||||
|
http_res.content_type(content_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(http_res.body(res.file))
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user