client-api: Fix timeout field in media download endpoint requests

According to the stabilization spec PR.
This commit is contained in:
Kévin Commaille 2023-05-04 12:02:24 +02:00 committed by Kévin Commaille
parent b27e54c7ed
commit 10d70c6055
4 changed files with 70 additions and 15 deletions

View File

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

View File

@ -7,9 +7,10 @@ pub mod v3 {
//!
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3downloadservernamemediaid
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
#[cfg(feature = "unstable-msc2246")]
use js_int::UInt;
use std::time::Duration;
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
use ruma_common::{
api::{request, response, Metadata},
metadata, IdParseError, MxcUri, OwnedServerName,
@ -48,18 +49,22 @@ pub mod v3 {
)]
pub allow_remote: bool,
/// How long to wait for the media to be uploaded
/// The maximum duration that the client is willing to wait to start receiving data, in the
/// case that the content has not yet been uploaded.
///
/// The default value is 20 seconds.
///
/// This uses the unstable prefix in
/// [MSC2246](https://github.com/matrix-org/matrix-spec-proposals/pull/2246)
/// [MSC2246](https://github.com/matrix-org/matrix-spec-proposals/pull/2246).
#[ruma_api(query)]
#[cfg(feature = "unstable-msc2246")]
#[serde(
default,
skip_serializing_if = "ruma_common::serde::is_default",
with = "ruma_common::serde::duration::ms",
default = "crate::media::default_download_timeout",
skip_serializing_if = "crate::media::is_default_download_timeout",
rename = "fi.mau.msc2246.max_stall_ms"
)]
pub max_stall_ms: Option<UInt>,
pub timeout_ms: Duration,
}
/// Response type for the `get_media_content` endpoint.
@ -99,7 +104,7 @@ pub mod v3 {
server_name,
allow_remote: true,
#[cfg(feature = "unstable-msc2246")]
max_stall_ms: None,
timeout_ms: crate::media::default_download_timeout(),
}
}

View File

@ -7,6 +7,9 @@ pub mod v3 {
//!
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3downloadservernamemediaidfilename
#[cfg(feature = "unstable-msc2246")]
use std::time::Duration;
use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
use ruma_common::{
api::{request, response, Metadata},
@ -49,6 +52,23 @@ pub mod v3 {
skip_serializing_if = "ruma_common::serde::is_true"
)]
pub allow_remote: bool,
/// The maximum duration that the client is willing to wait to start receiving data, in the
/// case that the content has not yet been uploaded.
///
/// 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)]
#[cfg(feature = "unstable-msc2246")]
#[serde(
with = "ruma_common::serde::duration::ms",
default = "crate::media::default_download_timeout",
skip_serializing_if = "crate::media::is_default_download_timeout",
rename = "fi.mau.msc2246.max_stall_ms"
)]
pub timeout_ms: Duration,
}
/// Response type for the `get_media_content_as_filename` endpoint.
@ -83,7 +103,14 @@ pub mod v3 {
impl Request {
/// Creates a new `Request` with the given media ID, server name and filename.
pub fn new(media_id: String, server_name: OwnedServerName, filename: String) -> Self {
Self { media_id, server_name, filename, allow_remote: true }
Self {
media_id,
server_name,
filename,
allow_remote: true,
#[cfg(feature = "unstable-msc2246")]
timeout_ms: crate::media::default_download_timeout(),
}
}
/// Creates a new `Request` with the given url and filename.

View File

@ -7,6 +7,9 @@ pub mod v3 {
//!
//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixmediav3thumbnailservernamemediaid
#[cfg(feature = "unstable-msc2246")]
use std::time::Duration;
use http::header::CONTENT_TYPE;
use js_int::UInt;
use ruma_common::{
@ -66,18 +69,22 @@ pub mod v3 {
)]
pub allow_remote: bool,
/// How long to wait for the media to be uploaded
/// The maximum duration that the client is willing to wait to start receiving data, in the
/// case that the content has not yet been uploaded.
///
/// The default value is 20 seconds.
///
/// This uses the unstable prefix in
/// [MSC2246](https://github.com/matrix-org/matrix-spec-proposals/pull/2246)
/// [MSC2246](https://github.com/matrix-org/matrix-spec-proposals/pull/2246).
#[ruma_api(query)]
#[cfg(feature = "unstable-msc2246")]
#[serde(
default,
skip_serializing_if = "ruma_common::serde::is_default",
with = "ruma_common::serde::duration::ms",
default = "crate::media::default_download_timeout",
skip_serializing_if = "crate::media::is_default_download_timeout",
rename = "fi.mau.msc2246.max_stall_ms"
)]
pub max_stall_ms: Option<UInt>,
pub timeout_ms: Duration,
}
/// Response type for the `get_content_thumbnail` endpoint.
@ -117,7 +124,7 @@ pub mod v3 {
height,
allow_remote: true,
#[cfg(feature = "unstable-msc2246")]
max_stall_ms: None,
timeout_ms: crate::media::default_download_timeout(),
}
}