relay_server/endpoints/
attachments.rs1use axum::extract::Path;
2use axum::http::StatusCode;
3use axum::response::IntoResponse;
4use relay_config::Config;
5use relay_event_schema::protocol::EventId;
6use serde::Deserialize;
7
8use crate::endpoints::common::{self, BadStoreRequest};
9use crate::envelope::{AttachmentType, Envelope};
10use crate::extractors::RequestMeta;
11use crate::service::ServiceState;
12use crate::utils::ConstrainedMultipart;
13
14#[derive(Debug, Deserialize)]
15pub struct AttachmentPath {
16 event_id: EventId,
17}
18
19async fn extract_envelope(
20 meta: RequestMeta,
21 path: AttachmentPath,
22 multipart: ConstrainedMultipart,
23 config: &Config,
24) -> Result<Box<Envelope>, BadStoreRequest> {
25 let items = multipart
26 .items(|_, _| AttachmentType::default(), config)
27 .await?;
28
29 let mut envelope = Envelope::from_request(Some(path.event_id), meta);
30 for item in items {
31 envelope.add_item(item);
32 }
33
34 Ok(envelope)
35}
36
37pub async fn handle(
38 state: ServiceState,
39 meta: RequestMeta,
40 Path(path): Path<AttachmentPath>,
41 multipart: ConstrainedMultipart,
42) -> Result<impl IntoResponse, BadStoreRequest> {
43 let envelope = extract_envelope(meta, path, multipart, state.config()).await?;
44 common::handle_envelope(&state, envelope).await?;
45 Ok(StatusCode::CREATED)
46}