client-api: Move some media types and helpers to ruma-common
Without breaking changes.
This commit is contained in:
parent
f9ae582b27
commit
586668806e
@ -44,8 +44,8 @@ pub mod v1 {
|
||||
#[ruma_api(query)]
|
||||
#[serde(
|
||||
with = "ruma_common::serde::duration::ms",
|
||||
default = "crate::media::default_download_timeout",
|
||||
skip_serializing_if = "crate::media::is_default_download_timeout"
|
||||
default = "ruma_common::media::default_download_timeout",
|
||||
skip_serializing_if = "ruma_common::media::is_default_download_timeout"
|
||||
)]
|
||||
pub timeout_ms: Duration,
|
||||
}
|
||||
@ -70,7 +70,11 @@ pub mod v1 {
|
||||
impl Request {
|
||||
/// Creates a new `Request` with the given media ID and server name.
|
||||
pub fn new(media_id: String, server_name: OwnedServerName) -> Self {
|
||||
Self { media_id, server_name, timeout_ms: crate::media::default_download_timeout() }
|
||||
Self {
|
||||
media_id,
|
||||
server_name,
|
||||
timeout_ms: ruma_common::media::default_download_timeout(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new `Request` with the given URI.
|
||||
|
@ -48,8 +48,8 @@ pub mod v1 {
|
||||
#[ruma_api(query)]
|
||||
#[serde(
|
||||
with = "ruma_common::serde::duration::ms",
|
||||
default = "crate::media::default_download_timeout",
|
||||
skip_serializing_if = "crate::media::is_default_download_timeout"
|
||||
default = "ruma_common::media::default_download_timeout",
|
||||
skip_serializing_if = "ruma_common::media::is_default_download_timeout"
|
||||
)]
|
||||
pub timeout_ms: Duration,
|
||||
}
|
||||
@ -78,7 +78,7 @@ pub mod v1 {
|
||||
media_id,
|
||||
server_name,
|
||||
filename,
|
||||
timeout_ms: crate::media::default_download_timeout(),
|
||||
timeout_ms: ruma_common::media::default_download_timeout(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,11 +13,10 @@ pub mod v1 {
|
||||
use js_int::UInt;
|
||||
use ruma_common::{
|
||||
api::{request, response, Metadata},
|
||||
media::Method,
|
||||
metadata, IdParseError, MxcUri, OwnedServerName,
|
||||
};
|
||||
|
||||
use crate::media::get_content_thumbnail::v3::Method;
|
||||
|
||||
const METADATA: Metadata = metadata! {
|
||||
method: GET,
|
||||
rate_limited: true,
|
||||
@ -63,8 +62,8 @@ pub mod v1 {
|
||||
#[ruma_api(query)]
|
||||
#[serde(
|
||||
with = "ruma_common::serde::duration::ms",
|
||||
default = "crate::media::default_download_timeout",
|
||||
skip_serializing_if = "crate::media::is_default_download_timeout"
|
||||
default = "ruma_common::media::default_download_timeout",
|
||||
skip_serializing_if = "ruma_common::media::is_default_download_timeout"
|
||||
)]
|
||||
pub timeout_ms: Duration,
|
||||
|
||||
@ -105,7 +104,7 @@ pub mod v1 {
|
||||
method: None,
|
||||
width,
|
||||
height,
|
||||
timeout_ms: crate::media::default_download_timeout(),
|
||||
timeout_ms: ruma_common::media::default_download_timeout(),
|
||||
animated: None,
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
//! Endpoints for the media repository.
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
pub mod create_content;
|
||||
pub mod create_content_async;
|
||||
pub mod create_mxc_uri;
|
||||
@ -10,14 +8,3 @@ 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.
|
||||
pub(crate) 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.
|
||||
pub(crate) fn is_default_download_timeout(timeout: &Duration) -> bool {
|
||||
timeout.as_secs() == 20
|
||||
}
|
||||
|
@ -61,8 +61,8 @@ pub mod v3 {
|
||||
#[ruma_api(query)]
|
||||
#[serde(
|
||||
with = "ruma_common::serde::duration::ms",
|
||||
default = "crate::media::default_download_timeout",
|
||||
skip_serializing_if = "crate::media::is_default_download_timeout"
|
||||
default = "ruma_common::media::default_download_timeout",
|
||||
skip_serializing_if = "ruma_common::media::is_default_download_timeout"
|
||||
)]
|
||||
pub timeout_ms: Duration,
|
||||
|
||||
@ -108,7 +108,7 @@ pub mod v3 {
|
||||
media_id,
|
||||
server_name,
|
||||
allow_remote: true,
|
||||
timeout_ms: crate::media::default_download_timeout(),
|
||||
timeout_ms: ruma_common::media::default_download_timeout(),
|
||||
allow_redirect: false,
|
||||
}
|
||||
}
|
||||
|
@ -65,8 +65,8 @@ pub mod v3 {
|
||||
#[ruma_api(query)]
|
||||
#[serde(
|
||||
with = "ruma_common::serde::duration::ms",
|
||||
default = "crate::media::default_download_timeout",
|
||||
skip_serializing_if = "crate::media::is_default_download_timeout"
|
||||
default = "ruma_common::media::default_download_timeout",
|
||||
skip_serializing_if = "ruma_common::media::is_default_download_timeout"
|
||||
)]
|
||||
pub timeout_ms: Duration,
|
||||
|
||||
@ -113,7 +113,7 @@ pub mod v3 {
|
||||
server_name,
|
||||
filename,
|
||||
allow_remote: true,
|
||||
timeout_ms: crate::media::default_download_timeout(),
|
||||
timeout_ms: ruma_common::media::default_download_timeout(),
|
||||
allow_redirect: false,
|
||||
}
|
||||
}
|
||||
|
@ -11,14 +11,13 @@ pub mod v3 {
|
||||
|
||||
use http::header::CONTENT_TYPE;
|
||||
use js_int::UInt;
|
||||
pub use ruma_common::media::Method;
|
||||
use ruma_common::{
|
||||
api::{request, response, Metadata},
|
||||
metadata,
|
||||
serde::StringEnum,
|
||||
IdParseError, MxcUri, OwnedServerName,
|
||||
metadata, IdParseError, MxcUri, OwnedServerName,
|
||||
};
|
||||
|
||||
use crate::{http_headers::CROSS_ORIGIN_RESOURCE_POLICY, PrivOwnedStr};
|
||||
use crate::http_headers::CROSS_ORIGIN_RESOURCE_POLICY;
|
||||
|
||||
const METADATA: Metadata = metadata! {
|
||||
method: GET,
|
||||
@ -80,8 +79,8 @@ pub mod v3 {
|
||||
#[ruma_api(query)]
|
||||
#[serde(
|
||||
with = "ruma_common::serde::duration::ms",
|
||||
default = "crate::media::default_download_timeout",
|
||||
skip_serializing_if = "crate::media::is_default_download_timeout"
|
||||
default = "ruma_common::media::default_download_timeout",
|
||||
skip_serializing_if = "ruma_common::media::is_default_download_timeout"
|
||||
)]
|
||||
pub timeout_ms: Duration,
|
||||
|
||||
@ -140,7 +139,7 @@ pub mod v3 {
|
||||
width,
|
||||
height,
|
||||
allow_remote: true,
|
||||
timeout_ms: crate::media::default_download_timeout(),
|
||||
timeout_ms: ruma_common::media::default_download_timeout(),
|
||||
allow_redirect: false,
|
||||
animated: None,
|
||||
}
|
||||
@ -167,20 +166,4 @@ pub mod v3 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The desired resizing method.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
#[non_exhaustive]
|
||||
pub enum Method {
|
||||
/// Crop the original to produce the requested image dimensions.
|
||||
Crop,
|
||||
|
||||
/// Maintain the original aspect ratio of the source image.
|
||||
Scale,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ pub mod directory;
|
||||
pub mod encryption;
|
||||
pub mod http_headers;
|
||||
mod identifiers;
|
||||
pub mod media;
|
||||
mod percent_encode;
|
||||
pub mod power_levels;
|
||||
pub mod presence;
|
||||
|
34
crates/ruma-common/src/media.rs
Normal file
34
crates/ruma-common/src/media.rs
Normal file
@ -0,0 +1,34 @@
|
||||
//! Common types and functions for the [content repository].
|
||||
//!
|
||||
//! [content repository]: https://spec.matrix.org/latest/client-server-api/#content-repository
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::{serde::StringEnum, PrivOwnedStr};
|
||||
|
||||
/// The desired resizing method for a thumbnail.
|
||||
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
|
||||
#[derive(Clone, StringEnum)]
|
||||
#[ruma_enum(rename_all = "snake_case")]
|
||||
#[non_exhaustive]
|
||||
pub enum Method {
|
||||
/// Crop the original to produce the requested image dimensions.
|
||||
Crop,
|
||||
|
||||
/// Maintain the original aspect ratio of the source image.
|
||||
Scale,
|
||||
|
||||
#[doc(hidden)]
|
||||
_Custom(PrivOwnedStr),
|
||||
}
|
||||
|
||||
/// The default duration that the client should be willing to wait to start receiving data.
|
||||
pub 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.
|
||||
pub fn is_default_download_timeout(timeout: &Duration) -> bool {
|
||||
timeout.as_secs() == 20
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user