diff --git a/src/client_server/media.rs b/src/client_server/media.rs index af7880cd..6d72107e 100644 --- a/src/client_server/media.rs +++ b/src/client_server/media.rs @@ -39,7 +39,7 @@ pub async fn create_content_route( db.media.create( mxc.clone(), &body.filename.as_deref(), - body.content_type.as_deref().unwrap_or("img"), // TODO this is now optional handle + &body.content_type.as_deref(), // TODO this is now optional handle &body.file, )?; @@ -85,10 +85,7 @@ pub async fn get_content_route( db.media.create( mxc, &get_content_response.content_disposition.as_deref(), - get_content_response // TODO this is now optional handle - .content_type - .as_deref() - .unwrap_or("img"), + &get_content_response.content_type.as_deref(), &get_content_response.file, )?; @@ -142,10 +139,7 @@ pub async fn get_content_thumbnail_route( db.media.upload_thumbnail( mxc, &None, - get_thumbnail_response - .content_type - .as_deref() - .unwrap_or("img"), // TODO now optional, deal with it somehow + &get_thumbnail_response.content_type, body.width.try_into().expect("all UInts are valid u32s"), body.height.try_into().expect("all UInts are valid u32s"), &get_thumbnail_response.file, diff --git a/src/database/media.rs b/src/database/media.rs index 8c59aa4d..bfc62078 100644 --- a/src/database/media.rs +++ b/src/database/media.rs @@ -20,7 +20,7 @@ impl Media { &self, mxc: String, filename: &Option<&str>, - content_type: &str, + content_type: &Option<&str>, file: &[u8], ) -> Result<()> { let mut key = mxc.as_bytes().to_vec(); @@ -30,7 +30,12 @@ impl Media { key.push(0xff); key.extend_from_slice(filename.as_ref().map(|f| f.as_bytes()).unwrap_or_default()); key.push(0xff); - key.extend_from_slice(content_type.as_bytes()); + key.extend_from_slice( + content_type + .as_ref() + .map(|c| c.as_bytes()) + .unwrap_or_default(), + ); self.mediaid_file.insert(key, file)?; @@ -42,7 +47,7 @@ impl Media { &self, mxc: String, filename: &Option, - content_type: &str, + content_type: &Option, width: u32, height: u32, file: &[u8], @@ -54,7 +59,12 @@ impl Media { key.push(0xff); key.extend_from_slice(filename.as_ref().map(|f| f.as_bytes()).unwrap_or_default()); key.push(0xff); - key.extend_from_slice(content_type.as_bytes()); + key.extend_from_slice( + content_type + .as_ref() + .map(|c| c.as_bytes()) + .unwrap_or_default(), + ); self.mediaid_file.insert(key, file)?; diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 08734b1b..d8e61316 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -647,6 +647,7 @@ impl Rooms { } /// Creates a new persisted data unit and adds it to a room. + #[allow(clippy::too_many_arguments)] pub fn build_and_append_pdu( &self, pdu_builder: PduBuilder, diff --git a/src/pdu.rs b/src/pdu.rs index 7118bfc8..a213d2cf 100644 --- a/src/pdu.rs +++ b/src/pdu.rs @@ -225,7 +225,7 @@ impl PduEvent { impl From<&state_res::StateEvent> for PduEvent { fn from(pdu: &state_res::StateEvent) -> Self { Self { - event_id: pdu.event_id().clone(), + event_id: pdu.event_id(), room_id: pdu.room_id().unwrap().clone(), sender: pdu.sender().clone(), origin_server_ts: (pdu @@ -260,17 +260,9 @@ impl PduEvent { "type": self.kind, "content": self.content, "state_key": self.state_key, - "prev_events": self.prev_events - .iter() - // TODO How do we create one of these - .map(|id| (id, EventHash { sha256: "hello".into() })) - .collect::>(), + "prev_events": self.prev_events, "depth": self.depth, - "auth_events": self.auth_events - .iter() - // TODO How do we create one of these - .map(|id| (id, EventHash { sha256: "hello".into() })) - .collect::>(), + "auth_events": self.auth_events, "redacts": self.redacts, "unsigned": self.unsigned, "hashes": self.hashes, diff --git a/src/server_server.rs b/src/server_server.rs index c865b028..19a73f9a 100644 --- a/src/server_server.rs +++ b/src/server_server.rs @@ -419,7 +419,7 @@ pub async fn send_transaction_message_route<'a>( } } - // TODO: For RoomVersion6 we must check that Raw<..> is canonical do we? + // TODO: For RoomVersion6 we must check that Raw<..> is canonical do we anywhere? // SPEC: // Servers MUST strictly enforce the JSON format specified in the appendices. // This translates to a 400 M_BAD_JSON error on most endpoints, or discarding of @@ -554,7 +554,7 @@ pub async fn send_transaction_message_route<'a>( // TODO we may not want the auth events chained in here for resolution? their_current_state .iter() - .map(|(_id, v)| ((v.kind(), v.state_key()), v.event_id().clone())) + .map(|(_id, v)| ((v.kind(), v.state_key()), v.event_id())) .collect::>(), ], Some(