client-api: Stabilize async media uploads

This commit is contained in:
Kévin Commaille 2023-05-25 21:40:16 +02:00 committed by Kévin Commaille
parent 2d697fcc95
commit 854d8076ef
11 changed files with 18 additions and 55 deletions

View File

@ -11,6 +11,7 @@ Improvements:
- Add convenience constructors for enabling lazy-loading in filters - Add convenience constructors for enabling lazy-loading in filters
- Add support for using an existing session to log in another (MSC3882 / Matrix 1.7) - Add support for using an existing session to log in another (MSC3882 / Matrix 1.7)
- Add support for media download redirects (MSC3860 / Matrix 1.7) - Add support for media download redirects (MSC3860 / Matrix 1.7)
- Stabilize support for asynchronous media uploads (MSC2246 / Matrix 1.7)
# 0.16.2 # 0.16.2

View File

@ -34,7 +34,6 @@ compat-unset-avatar = []
compat-get-3pids = [] compat-get-3pids = []
unstable-exhaustive-types = ["ruma-common/unstable-exhaustive-types"] unstable-exhaustive-types = ["ruma-common/unstable-exhaustive-types"]
unstable-msc2246 = []
unstable-msc2666 = [] unstable-msc2666 = []
unstable-msc2448 = [] unstable-msc2448 = []
unstable-msc2654 = [] unstable-msc2654 = []

View File

@ -153,12 +153,10 @@ pub enum ErrorKind {
/// M_DUPLICATE_ANNOTATION /// M_DUPLICATE_ANNOTATION
DuplicateAnnotation, DuplicateAnnotation,
/// FI.MAU.MSC2246_NOT_YET_UPLOADED /// M_NOT_YET_UPLOADED
#[cfg(feature = "unstable-msc2246")]
NotYetUploaded, NotYetUploaded,
/// FI.MAU.MSC2246_CANNOT_OVERWRITE_MEDIA /// M_CANNOT_OVERWRITE_MEDIA
#[cfg(feature = "unstable-msc2246")]
CannotOverwriteMedia, CannotOverwriteMedia,
/// M_UNKNOWN_POS for sliding sync /// M_UNKNOWN_POS for sliding sync
@ -213,10 +211,8 @@ impl AsRef<str> for ErrorKind {
Self::UnableToGrantJoin => "M_UNABLE_TO_GRANT_JOIN", Self::UnableToGrantJoin => "M_UNABLE_TO_GRANT_JOIN",
Self::BadAlias => "M_BAD_ALIAS", Self::BadAlias => "M_BAD_ALIAS",
Self::DuplicateAnnotation => "M_DUPLICATE_ANNOTATION", Self::DuplicateAnnotation => "M_DUPLICATE_ANNOTATION",
#[cfg(feature = "unstable-msc2246")] Self::NotYetUploaded => "M_NOT_YET_UPLOADED",
Self::NotYetUploaded => "FI.MAU.MSC2246_NOT_YET_UPLOADED", Self::CannotOverwriteMedia => "M_CANNOT_OVERWRITE_MEDIA",
#[cfg(feature = "unstable-msc2246")]
Self::CannotOverwriteMedia => "FI.MAU.MSC2246_CANNOT_OVERWRITE_MEDIA",
#[cfg(feature = "unstable-msc3575")] #[cfg(feature = "unstable-msc3575")]
Self::UnknownPos => "M_UNKNOWN_POS", Self::UnknownPos => "M_UNKNOWN_POS",
Self::_Custom { errcode, .. } => &errcode.0, Self::_Custom { errcode, .. } => &errcode.0,

View File

@ -207,9 +207,7 @@ impl<'de> Visitor<'de> for ErrorKindVisitor {
ErrCode::CannotLeaveServerNoticeRoom => ErrorKind::CannotLeaveServerNoticeRoom, ErrCode::CannotLeaveServerNoticeRoom => ErrorKind::CannotLeaveServerNoticeRoom,
ErrCode::WeakPassword => ErrorKind::WeakPassword, ErrCode::WeakPassword => ErrorKind::WeakPassword,
ErrCode::DuplicateAnnotation => ErrorKind::DuplicateAnnotation, ErrCode::DuplicateAnnotation => ErrorKind::DuplicateAnnotation,
#[cfg(feature = "unstable-msc2246")]
ErrCode::NotYetUploaded => ErrorKind::NotYetUploaded, ErrCode::NotYetUploaded => ErrorKind::NotYetUploaded,
#[cfg(feature = "unstable-msc2246")]
ErrCode::CannotOverwriteMedia => ErrorKind::CannotOverwriteMedia, ErrCode::CannotOverwriteMedia => ErrorKind::CannotOverwriteMedia,
#[cfg(feature = "unstable-msc3575")] #[cfg(feature = "unstable-msc3575")]
ErrCode::UnknownPos => ErrorKind::UnknownPos, ErrCode::UnknownPos => ErrorKind::UnknownPos,
@ -255,14 +253,9 @@ enum ErrCode {
CannotLeaveServerNoticeRoom, CannotLeaveServerNoticeRoom,
WeakPassword, WeakPassword,
DuplicateAnnotation, DuplicateAnnotation,
#[cfg(feature = "unstable-msc2246")] #[ruma_enum(alias = "FI.MAU.MSC2246_NOT_YET_UPLOADED")]
#[ruma_enum(rename = "FI.MAU.MSC2246_NOT_YET_UPLOADED", alias = "M_NOT_YET_UPLOADED")]
NotYetUploaded, NotYetUploaded,
#[cfg(feature = "unstable-msc2246")] #[ruma_enum(alias = "FI.MAU.MSC2246_CANNOT_OVERWRITE_MEDIA")]
#[ruma_enum(
rename = "FI.MAU.MSC2246_CANNOT_OVERWRITE_MEDIA",
alias = "M_CANNOT_OVERWRITE_MEDIA"
)]
CannotOverwriteMedia, CannotOverwriteMedia,
#[cfg(feature = "unstable-msc3575")] #[cfg(feature = "unstable-msc3575")]
UnknownPos, UnknownPos,

View File

@ -1,12 +1,9 @@
//! Endpoints for the media repository. //! Endpoints for the media repository.
#[cfg(feature = "unstable-msc2246")]
use std::time::Duration; use std::time::Duration;
pub mod create_content; pub mod create_content;
#[cfg(feature = "unstable-msc2246")]
pub mod create_content_async; pub mod create_content_async;
#[cfg(feature = "unstable-msc2246")]
pub mod create_mxc_uri; pub mod create_mxc_uri;
pub mod get_content; pub mod get_content;
pub mod get_content_as_filename; pub mod get_content_as_filename;
@ -15,14 +12,12 @@ pub mod get_media_config;
pub mod get_media_preview; pub mod get_media_preview;
/// The default duration that the client should be willing to wait to start receiving data. /// The default duration that the client should be willing to wait to start receiving data.
#[cfg(feature = "unstable-msc2246")]
fn default_download_timeout() -> Duration { fn default_download_timeout() -> Duration {
Duration::from_secs(20) Duration::from_secs(20)
} }
/// Whether the given duration is the default duration that the client should be willing to wait to /// Whether the given duration is the default duration that the client should be willing to wait to
/// start receiving data. /// start receiving data.
#[cfg(feature = "unstable-msc2246")]
fn is_default_download_timeout(timeout: &Duration) -> bool { fn is_default_download_timeout(timeout: &Duration) -> bool {
timeout.as_secs() == 20 timeout.as_secs() == 20
} }

View File

@ -2,10 +2,10 @@
//! //!
//! Upload media to an MXC URI that was created with create_mxc_uri. //! Upload media to an MXC URI that was created with create_mxc_uri.
pub mod unstable { pub mod v3 {
//! `/unstable/` ([spec]) //! `/v3/` ([spec])
//! //!
//! [spec]: https://github.com/tulir/matrix-doc/blob/asynchronous_uploads/proposals/2246-asynchronous-uploads.md //! [spec]: https://spec.matrix.org/latest/client-server-api/#put_matrixmediav3uploadservernamemediaid
use http::header::CONTENT_TYPE; use http::header::CONTENT_TYPE;
use ruma_common::{ use ruma_common::{
@ -19,6 +19,7 @@ pub mod unstable {
authentication: AccessToken, authentication: AccessToken,
history: { history: {
unstable => "/_matrix/media/unstable/fi.mau.msc2246/upload/:server_name/:media_id", unstable => "/_matrix/media/unstable/fi.mau.msc2246/upload/:server_name/:media_id",
1.7 => "/_matrix/media/v3/upload/:server_name/:media_id",
} }
}; };

View File

@ -2,10 +2,10 @@
//! //!
//! Create an MXC URI without content. //! Create an MXC URI without content.
pub mod unstable { pub mod v1 {
//! `/unstable/` ([spec]) //! `/v1/` ([spec])
//! //!
//! [spec]: https://github.com/tulir/matrix-doc/blob/asynchronous_uploads/proposals/2246-asynchronous-uploads.md //! [spec]: https://spec.matrix.org/latest/client-server-api/#post_matrixmediav1create
use ruma_common::{ use ruma_common::{
api::{request, response, Metadata}, api::{request, response, Metadata},
@ -18,6 +18,7 @@ pub mod unstable {
authentication: AccessToken, authentication: AccessToken,
history: { history: {
unstable => "/_matrix/media/unstable/fi.mau.msc2246/create", unstable => "/_matrix/media/unstable/fi.mau.msc2246/create",
1.7 => "/_matrix/media/v1/create",
} }
}; };

View File

@ -7,7 +7,6 @@ pub mod v3 {
//! //!
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3downloadservernamemediaid //! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3downloadservernamemediaid
#[cfg(feature = "unstable-msc2246")]
use std::time::Duration; use std::time::Duration;
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE}; use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
@ -53,16 +52,11 @@ pub mod v3 {
/// case that the content has not yet been uploaded. /// case that the content has not yet been uploaded.
/// ///
/// The default value is 20 seconds. /// The default value is 20 seconds.
///
/// This uses the unstable prefix in
/// [MSC2246](https://github.com/matrix-org/matrix-spec-proposals/pull/2246).
#[ruma_api(query)] #[ruma_api(query)]
#[cfg(feature = "unstable-msc2246")]
#[serde( #[serde(
with = "ruma_common::serde::duration::ms", with = "ruma_common::serde::duration::ms",
default = "crate::media::default_download_timeout", default = "crate::media::default_download_timeout",
skip_serializing_if = "crate::media::is_default_download_timeout", skip_serializing_if = "crate::media::is_default_download_timeout"
rename = "fi.mau.msc2246.max_stall_ms"
)] )]
pub timeout_ms: Duration, pub timeout_ms: Duration,
@ -111,7 +105,6 @@ pub mod v3 {
media_id, media_id,
server_name, server_name,
allow_remote: true, allow_remote: true,
#[cfg(feature = "unstable-msc2246")]
timeout_ms: crate::media::default_download_timeout(), timeout_ms: crate::media::default_download_timeout(),
allow_redirect: false, allow_redirect: false,
} }

View File

@ -7,7 +7,6 @@ pub mod v3 {
//! //!
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3downloadservernamemediaidfilename //! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3downloadservernamemediaidfilename
#[cfg(feature = "unstable-msc2246")]
use std::time::Duration; use std::time::Duration;
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE}; use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
@ -57,16 +56,11 @@ pub mod v3 {
/// case that the content has not yet been uploaded. /// case that the content has not yet been uploaded.
/// ///
/// The default value is 20 seconds. /// The default value is 20 seconds.
///
/// This uses the unstable prefix in
/// [MSC2246](https://github.com/matrix-org/matrix-spec-proposals/pull/2246).
#[ruma_api(query)] #[ruma_api(query)]
#[cfg(feature = "unstable-msc2246")]
#[serde( #[serde(
with = "ruma_common::serde::duration::ms", with = "ruma_common::serde::duration::ms",
default = "crate::media::default_download_timeout", default = "crate::media::default_download_timeout",
skip_serializing_if = "crate::media::is_default_download_timeout", skip_serializing_if = "crate::media::is_default_download_timeout"
rename = "fi.mau.msc2246.max_stall_ms"
)] )]
pub timeout_ms: Duration, pub timeout_ms: Duration,
@ -116,7 +110,6 @@ pub mod v3 {
server_name, server_name,
filename, filename,
allow_remote: true, allow_remote: true,
#[cfg(feature = "unstable-msc2246")]
timeout_ms: crate::media::default_download_timeout(), timeout_ms: crate::media::default_download_timeout(),
allow_redirect: false, allow_redirect: false,
} }

View File

@ -7,7 +7,6 @@ pub mod v3 {
//! //!
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3thumbnailservernamemediaid //! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3thumbnailservernamemediaid
#[cfg(feature = "unstable-msc2246")]
use std::time::Duration; use std::time::Duration;
use http::header::CONTENT_TYPE; use http::header::CONTENT_TYPE;
@ -73,16 +72,11 @@ pub mod v3 {
/// case that the content has not yet been uploaded. /// case that the content has not yet been uploaded.
/// ///
/// The default value is 20 seconds. /// The default value is 20 seconds.
///
/// This uses the unstable prefix in
/// [MSC2246](https://github.com/matrix-org/matrix-spec-proposals/pull/2246).
#[ruma_api(query)] #[ruma_api(query)]
#[cfg(feature = "unstable-msc2246")]
#[serde( #[serde(
with = "ruma_common::serde::duration::ms", with = "ruma_common::serde::duration::ms",
default = "crate::media::default_download_timeout", default = "crate::media::default_download_timeout",
skip_serializing_if = "crate::media::is_default_download_timeout", skip_serializing_if = "crate::media::is_default_download_timeout"
rename = "fi.mau.msc2246.max_stall_ms"
)] )]
pub timeout_ms: Duration, pub timeout_ms: Duration,
@ -131,7 +125,6 @@ pub mod v3 {
width, width,
height, height,
allow_remote: true, allow_remote: true,
#[cfg(feature = "unstable-msc2246")]
timeout_ms: crate::media::default_download_timeout(), timeout_ms: crate::media::default_download_timeout(),
allow_redirect: false, allow_redirect: false,
} }

View File

@ -148,7 +148,6 @@ unstable-extensible-events = [
"unstable-msc3955", "unstable-msc3955",
] ]
unstable-msc1767 = ["ruma-common/unstable-msc1767"] unstable-msc1767 = ["ruma-common/unstable-msc1767"]
unstable-msc2246 = ["ruma-client-api?/unstable-msc2246"]
unstable-msc2409 = ["ruma-appservice-api?/unstable-msc2409"] unstable-msc2409 = ["ruma-appservice-api?/unstable-msc2409"]
unstable-msc2448 = [ unstable-msc2448 = [
"ruma-client-api?/unstable-msc2448", "ruma-client-api?/unstable-msc2448",
@ -197,7 +196,6 @@ __ci = [
"unstable-unspecified", "unstable-unspecified",
"unstable-sanitize", "unstable-sanitize",
"unstable-msc1767", "unstable-msc1767",
"unstable-msc2246",
"unstable-msc2409", "unstable-msc2409",
"unstable-msc2448", "unstable-msc2448",
"unstable-msc2654", "unstable-msc2654",