mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 07:41:23 +01:00
Return 504 when a file is missing to be by-spec
The spec defines that the media endpoints should return 504 when a file is not-yet-uploaded, which has been interpreted to include when a file was deleted. Modifies the /media/v3/download/ and /media/r0/thumbnail endpoints.
This commit is contained in:
parent
bf799c1fa1
commit
c70cfd3d25
3 changed files with 14 additions and 11 deletions
|
|
@ -250,7 +250,7 @@ async fn get_content_route_ruma(
|
||||||
cross_origin_resource_policy: Some("cross-origin".to_owned()),
|
cross_origin_resource_policy: Some("cross-origin".to_owned()),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
|
Err(Error::BadRequest(ErrorKind::NotYetUploaded, "Media not found."))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -415,6 +415,6 @@ async fn get_content_thumbnail_route_ruma(
|
||||||
cross_origin_resource_policy: Some("cross-origin".to_owned()),
|
cross_origin_resource_policy: Some("cross-origin".to_owned()),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(Error::BadRequest(ErrorKind::NotFound, "Media not found."))
|
Err(Error::BadRequest(ErrorKind::NotYetUploaded, "Media not found."))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use std::io::Cursor;
|
||||||
use image::imageops::FilterType;
|
use image::imageops::FilterType;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{AsyncReadExt, AsyncWriteExt, BufReader},
|
io::{AsyncReadExt, AsyncWriteExt},
|
||||||
};
|
};
|
||||||
use tracing::{debug, warn};
|
use tracing::{debug, warn};
|
||||||
|
|
||||||
|
|
@ -88,15 +88,17 @@ impl Service {
|
||||||
self.db.search_file_metadata(mxc, 0, 0)
|
self.db.search_file_metadata(mxc, 0, 0)
|
||||||
{
|
{
|
||||||
let path = services().globals.get_media_file(&key);
|
let path = services().globals.get_media_file(&key);
|
||||||
let mut file = Vec::new();
|
let mut file_data = Vec::new();
|
||||||
BufReader::new(File::open(path).await?)
|
let Ok(mut file) = File::open(path).await else {
|
||||||
.read_to_end(&mut file)
|
return Ok(None);
|
||||||
.await?;
|
};
|
||||||
|
|
||||||
|
file.read_to_end(&mut file_data).await?;
|
||||||
|
|
||||||
Ok(Some(FileMeta {
|
Ok(Some(FileMeta {
|
||||||
content_disposition,
|
content_disposition,
|
||||||
content_type,
|
content_type,
|
||||||
file,
|
file: file_data,
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
|
|
||||||
|
|
@ -98,9 +98,9 @@ impl Error {
|
||||||
pub(crate) fn to_response(&self) -> Ra<UiaaResponse> {
|
pub(crate) fn to_response(&self) -> Ra<UiaaResponse> {
|
||||||
use ErrorKind::{
|
use ErrorKind::{
|
||||||
Forbidden, GuestAccessForbidden, LimitExceeded, MissingToken,
|
Forbidden, GuestAccessForbidden, LimitExceeded, MissingToken,
|
||||||
NotFound, ThreepidAuthFailed, ThreepidDenied, TooLarge,
|
NotFound, NotYetUploaded, ThreepidAuthFailed, ThreepidDenied,
|
||||||
Unauthorized, Unknown, UnknownToken, Unrecognized, UserDeactivated,
|
TooLarge, Unauthorized, Unknown, UnknownToken, Unrecognized,
|
||||||
WrongRoomKeysVersion,
|
UserDeactivated, WrongRoomKeysVersion,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Self::Uiaa(uiaainfo) = self {
|
if let Self::Uiaa(uiaainfo) = self {
|
||||||
|
|
@ -142,6 +142,7 @@ impl Error {
|
||||||
..
|
..
|
||||||
} => StatusCode::TOO_MANY_REQUESTS,
|
} => StatusCode::TOO_MANY_REQUESTS,
|
||||||
TooLarge => StatusCode::PAYLOAD_TOO_LARGE,
|
TooLarge => StatusCode::PAYLOAD_TOO_LARGE,
|
||||||
|
NotYetUploaded => StatusCode::GATEWAY_TIMEOUT,
|
||||||
_ => StatusCode::BAD_REQUEST,
|
_ => StatusCode::BAD_REQUEST,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue