1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-07-28 10:48:30 +00:00
continuwuity/src/api/client/media.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1.3 KiB
Rust
Raw Normal View History

use axum::extract::State;
use axum_client_ip::InsecureClientIp;
use conduit::{
utils::{self, content_disposition::make_content_disposition},
Result,
2020-07-30 18:14:47 +02:00
};
use conduit_service::media::MXC_LENGTH;
use ruma::{api::client::media::create_content, Mxc};
use crate::Ruma;
/// # `POST /_matrix/media/v3/upload`
2021-08-31 19:14:37 +02:00
///
/// Permanently save media in the server.
///
/// - Some metadata will be saved in the database
/// - Media will be saved in the media/ directory
#[tracing::instrument(skip_all, fields(%client), name = "media_upload")]
pub(crate) async fn create_content_route(
State(services): State<crate::State>, InsecureClientIp(client): InsecureClientIp,
body: Ruma<create_content::v3::Request>,
) -> Result<create_content::v3::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let content_disposition = make_content_disposition(None, body.content_type.as_deref(), body.filename.as_deref());
let mxc = Mxc {
server_name: services.globals.server_name(),
media_id: &utils::random_string(MXC_LENGTH),
};
services
2022-10-05 20:34:31 +02:00
.media
2021-06-06 16:58:32 +04:30
.create(
&mxc,
Some(sender_user),
Some(&content_disposition),
body.content_type.as_deref(),
2021-06-06 16:58:32 +04:30
&body.file,
)
.await?;
2022-02-18 15:33:14 +01:00
Ok(create_content::v3::Response {
content_uri: mxc.to_string().into(),
2020-12-19 16:00:11 +01:00
blurhash: None,
})
2020-07-30 18:14:47 +02:00
}