diff --git a/src/core/error/response.rs b/src/core/error/response.rs index c41d542c..41cfa72d 100644 --- a/src/core/error/response.rs +++ b/src/core/error/response.rs @@ -60,6 +60,9 @@ pub(super) fn bad_request_code(kind: &ErrorKind) -> StatusCode { // 429 | LimitExceeded { .. } => StatusCode::TOO_MANY_REQUESTS, + // 409 + | CannotOverwriteMedia => StatusCode::CONFLICT, + // 413 | TooLarge => StatusCode::PAYLOAD_TOO_LARGE, @@ -69,6 +72,9 @@ pub(super) fn bad_request_code(kind: &ErrorKind) -> StatusCode { // 404 | NotFound | NotImplemented | FeatureDisabled => StatusCode::NOT_FOUND, + // 504 + | NotYetUploaded => StatusCode::GATEWAY_TIMEOUT, + // 403 | GuestAccessForbidden | ThreepidAuthFailed diff --git a/src/service/media/mod.rs b/src/service/media/mod.rs index 81cd2987..9a84a29c 100644 --- a/src/service/media/mod.rs +++ b/src/service/media/mod.rs @@ -159,6 +159,10 @@ impl Service { ) -> Result<()> { let pending = self.db.search_pending_mxc(mxc).await; let Some((owner_id, expires_at)) = pending else { + if self.get_metadata(mxc).await.is_some() { + return Err!(Request(CannotOverwriteMedia("Media ID already has content"))); + } + return Err!(Request(NotFound("Media not found"))); }; diff --git a/tests/complement/results.jsonl b/tests/complement/results.jsonl index 810bb021..8b6bb70b 100644 --- a/tests/complement/results.jsonl +++ b/tests/complement/results.jsonl @@ -9,13 +9,13 @@ {"Action":"pass","Test":"TestArchivedRoomsHistory/timeline_is_empty"} {"Action":"skip","Test":"TestArchivedRoomsHistory/timeline_is_empty/incremental_sync"} {"Action":"pass","Test":"TestArchivedRoomsHistory/timeline_is_empty/initial_sync"} -{"Action":"fail","Test":"TestAsyncUpload"} -{"Action":"fail","Test":"TestAsyncUpload/Cannot_upload_to_a_media_ID_that_has_already_been_uploaded_to"} -{"Action":"fail","Test":"TestAsyncUpload/Create_media"} -{"Action":"fail","Test":"TestAsyncUpload/Download_media"} -{"Action":"fail","Test":"TestAsyncUpload/Download_media_over__matrix/client/v1/media/download"} -{"Action":"fail","Test":"TestAsyncUpload/Not_yet_uploaded"} -{"Action":"fail","Test":"TestAsyncUpload/Upload_media"} +{"Action":"pass","Test":"TestAsyncUpload"} +{"Action":"pass","Test":"TestAsyncUpload/Cannot_upload_to_a_media_ID_that_has_already_been_uploaded_to"} +{"Action":"pass","Test":"TestAsyncUpload/Create_media"} +{"Action":"pass","Test":"TestAsyncUpload/Download_media"} +{"Action":"pass","Test":"TestAsyncUpload/Download_media_over__matrix/client/v1/media/download"} +{"Action":"pass","Test":"TestAsyncUpload/Not_yet_uploaded"} +{"Action":"pass","Test":"TestAsyncUpload/Upload_media"} {"Action":"pass","Test":"TestAvatarUrlUpdate"} {"Action":"pass","Test":"TestBannedUserCannotSendJoin"} {"Action":"skip","Test":"TestCanRegisterAdmin"}