Use ruma-api-macros for the media endpoints.
This commit is contained in:
parent
fb90929aa1
commit
e0bb81ad67
@ -19,11 +19,13 @@ ruma-signatures = "0.4.0"
|
|||||||
serde = "1.0.2"
|
serde = "1.0.2"
|
||||||
serde_derive = "1.0.2"
|
serde_derive = "1.0.2"
|
||||||
serde_json = "1.0.1"
|
serde_json = "1.0.1"
|
||||||
|
serde_urlencoded = "0.5.1"
|
||||||
|
url = "1.5.1"
|
||||||
|
|
||||||
[dependencies.ruma-api]
|
[dependencies.ruma-api]
|
||||||
git = "https://github.com/ruma/ruma-api"
|
git = "https://github.com/ruma/ruma-api"
|
||||||
rev = "211cf5e3531cd1862136129d5f73caaac7b4eb43"
|
rev = "4893be93f86543f9a9e3c5d7205afba769b84aa6"
|
||||||
|
|
||||||
[dependencies.ruma-api-macros]
|
[dependencies.ruma-api-macros]
|
||||||
git = "https://github.com/ruma/ruma-api-macros"
|
git = "https://github.com/ruma/ruma-api-macros"
|
||||||
rev = "f5a935384e36134daf86a13190318a5c50cf2c17"
|
rev = "84562c426044eef6b1c2f0e964e85ff9d100aa27"
|
||||||
|
@ -16,6 +16,8 @@ extern crate ruma_signatures;
|
|||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
#[macro_use] extern crate serde_derive;
|
#[macro_use] extern crate serde_derive;
|
||||||
|
extern crate serde_urlencoded;
|
||||||
|
extern crate url;
|
||||||
|
|
||||||
/// Endpoints for the r0.x.x versions of the client API specification.
|
/// Endpoints for the r0.x.x versions of the client API specification.
|
||||||
pub mod r0 {
|
pub mod r0 {
|
||||||
@ -26,7 +28,7 @@ pub mod r0 {
|
|||||||
pub mod context;
|
pub mod context;
|
||||||
pub mod directory;
|
pub mod directory;
|
||||||
pub mod filter;
|
pub mod filter;
|
||||||
// pub mod media;
|
pub mod media;
|
||||||
// pub mod membership;
|
// pub mod membership;
|
||||||
// pub mod presence;
|
// pub mod presence;
|
||||||
// pub mod profile;
|
// pub mod profile;
|
||||||
|
227
src/r0/media.rs
227
src/r0/media.rs
@ -2,117 +2,73 @@
|
|||||||
|
|
||||||
/// [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-download-servername-mediaid)
|
/// [GET /_matrix/media/r0/download/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-download-servername-mediaid)
|
||||||
pub mod get_content {
|
pub mod get_content {
|
||||||
/// Details about this API endpoint.
|
use hyper::header::{ContentDisposition, ContentType};
|
||||||
#[derive(Clone, Copy, Debug)]
|
use ruma_api_macros::ruma_api;
|
||||||
pub struct Endpoint;
|
|
||||||
|
|
||||||
/// This API endpoint's path parameters.
|
ruma_api! {
|
||||||
#[derive(Clone, Debug)]
|
metadata {
|
||||||
pub struct PathParams {
|
description: "Retrieve content from the media store.",
|
||||||
/// The media ID from the mxc:// URI (the path component).
|
method: Method::Get,
|
||||||
pub media_id: String,
|
name: "get_media_content",
|
||||||
/// The server name from the mxc:// URI (the authoritory component).
|
path: "/_matrix/media/r0/download/:server_name/:media_id",
|
||||||
pub server_name: String,
|
rate_limited: false,
|
||||||
}
|
requires_authentication: false,
|
||||||
|
|
||||||
impl ::Endpoint for Endpoint {
|
|
||||||
type BodyParams = ();
|
|
||||||
type PathParams = PathParams;
|
|
||||||
type QueryParams = ();
|
|
||||||
type Response = (); // TODO: How should a file be represented as a response?
|
|
||||||
// must include HTTP headers Content-Type and Content-Disposition (filename)
|
|
||||||
|
|
||||||
fn method() -> ::Method {
|
|
||||||
::Method::Get
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_path(params: Self::PathParams) -> String {
|
request {
|
||||||
format!(
|
/// The media ID from the mxc:// URI (the path component).
|
||||||
"/_matrix/media/r0/download/{}/{}",
|
#[ruma_api(path)]
|
||||||
params.server_name,
|
pub media_id: String,
|
||||||
params.media_id
|
/// The server name from the mxc:// URI (the authoritory component).
|
||||||
)
|
#[ruma_api(path)]
|
||||||
|
pub server_name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn router_path() -> &'static str {
|
response {
|
||||||
"/_matrix/media/r0/download/:server_name/:media_id"
|
/// The content that was previously uploaded.
|
||||||
}
|
#[ruma_api(body)]
|
||||||
|
pub file: Vec<u8>,
|
||||||
fn name() -> &'static str {
|
/// The content type of the file that was previously uploaded.
|
||||||
"get_media_content"
|
#[ruma_api(header)]
|
||||||
}
|
pub content_type: ContentType,
|
||||||
|
/// The name of the file that was previously uploaded, if set.
|
||||||
fn description() -> &'static str {
|
#[ruma_api(header)]
|
||||||
"Retrieve content from the media store."
|
pub content_disposition: ContentDisposition,
|
||||||
}
|
|
||||||
|
|
||||||
fn requires_authentication() -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rate_limited() -> bool {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [POST /_matrix/media/r0/upload](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload)
|
/// [POST /_matrix/media/r0/upload](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-media-r0-upload)
|
||||||
pub mod create_content {
|
pub mod create_content {
|
||||||
/// Details about this API endpoint.
|
use hyper::header::ContentType;
|
||||||
#[derive(Clone, Copy, Debug)]
|
use ruma_api_macros::ruma_api;
|
||||||
pub struct Endpoint;
|
|
||||||
|
|
||||||
/// This API endpoint's response.
|
ruma_api! {
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
metadata {
|
||||||
pub struct Response {
|
description: "Upload content to the media store.",
|
||||||
/// The MXC URI for the uploaded content.
|
method: Method::Post,
|
||||||
pub content_uri: String,
|
name: "create_media_content",
|
||||||
}
|
path: "/_matrix/media/r0/upload",
|
||||||
|
rate_limited: false,
|
||||||
impl ::Endpoint for Endpoint {
|
requires_authentication: false,
|
||||||
type BodyParams = (); // TODO: How should a file be represented as the request body?
|
|
||||||
type PathParams = ();
|
|
||||||
type QueryParams = ();
|
|
||||||
type Response = Response;
|
|
||||||
|
|
||||||
fn method() -> ::Method {
|
|
||||||
::Method::Post
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_path(_params: Self::PathParams) -> String {
|
request {
|
||||||
Self::router_path().to_string()
|
/// The content type of the file being uploaded.
|
||||||
|
#[ruma_api(header)]
|
||||||
|
pub content_type: ContentType,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn router_path() -> &'static str {
|
response {
|
||||||
"/_matrix/media/r0/upload"
|
/// The MXC URI for the uploaded content.
|
||||||
}
|
pub content_uri: String,
|
||||||
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"create_media_content"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn description() -> &'static str {
|
|
||||||
"Upload content to the media store."
|
|
||||||
}
|
|
||||||
|
|
||||||
fn requires_authentication() -> bool {
|
|
||||||
// TODO: How comes this does not require authentication?
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rate_limited() -> bool {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-thumbnail-servername-mediaid)
|
/// [GET /_matrix/media/r0/thumbnail/{serverName}/{mediaId}](https://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-media-r0-thumbnail-servername-mediaid)
|
||||||
pub mod get_content_thumbnail {
|
pub mod get_content_thumbnail {
|
||||||
use std::fmt::{Display, Error as FmtError, Formatter};
|
use ruma_api_macros::ruma_api;
|
||||||
|
|
||||||
/// Details about this API endpoint.
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub struct Endpoint;
|
|
||||||
|
|
||||||
/// The desired resizing method.
|
/// The desired resizing method.
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||||
@ -125,73 +81,40 @@ pub mod get_content_thumbnail {
|
|||||||
Scale,
|
Scale,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This API endpoint's path parameters.
|
ruma_api! {
|
||||||
#[derive(Clone, Debug)]
|
metadata {
|
||||||
pub struct PathParams {
|
description: "Get a thumbnail of content from the media store.",
|
||||||
/// The media ID from the mxc:// URI (the path component).
|
method: Method::Get,
|
||||||
pub media_id: String,
|
name: "get_content_thumbnail",
|
||||||
/// The server name from the mxc:// URI (the authoritory component).
|
path: "/_matrix/media/r0/thumbnail/:server_name/:media_id",
|
||||||
pub server_name: String,
|
rate_limited: false,
|
||||||
}
|
requires_authentication: false,
|
||||||
|
|
||||||
/// This API endpoint's query string parameters.
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct QueryParams {
|
|
||||||
/// The *desired* height of the thumbnail. The actual thumbnail may not match the size
|
|
||||||
/// specified.
|
|
||||||
pub height: Option<u64>,
|
|
||||||
/// The desired resizing method.
|
|
||||||
pub method: Option<Method>,
|
|
||||||
/// The *desired* width of the thumbnail. The actual thumbnail may not match the size
|
|
||||||
/// specified.
|
|
||||||
pub width: Option<u64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ::Endpoint for Endpoint {
|
|
||||||
type BodyParams = ();
|
|
||||||
type PathParams = PathParams;
|
|
||||||
type QueryParams = QueryParams;
|
|
||||||
type Response = (); // TODO: How should a file be represented as a response?
|
|
||||||
|
|
||||||
fn method() -> ::Method {
|
|
||||||
::Method::Post
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_path(params: Self::PathParams) -> String {
|
request {
|
||||||
format!(
|
/// The media ID from the mxc:// URI (the path component).
|
||||||
"/_matrix/media/r0/thumbnail/{}/{}",
|
#[ruma_api(path)]
|
||||||
params.server_name,
|
pub media_id: String,
|
||||||
params.media_id
|
/// The server name from the mxc:// URI (the authoritory component).
|
||||||
)
|
#[ruma_api(path)]
|
||||||
|
pub server_name: String,
|
||||||
|
/// The *desired* height of the thumbnail. The actual thumbnail may not match the size
|
||||||
|
/// specified.
|
||||||
|
#[ruma_api(query)]
|
||||||
|
pub height: Option<u64>,
|
||||||
|
/// The desired resizing method.
|
||||||
|
#[ruma_api(query)]
|
||||||
|
pub method: Option<Method>,
|
||||||
|
/// The *desired* width of the thumbnail. The actual thumbnail may not match the size
|
||||||
|
/// specified.
|
||||||
|
#[ruma_api(query)]
|
||||||
|
pub width: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn router_path() -> &'static str {
|
response {
|
||||||
"/_matrix/media/r0/thumbnail/:server_name/:media_id"
|
/// A thumbnail of the requested content.
|
||||||
}
|
#[ruma_api(body)]
|
||||||
|
pub file: Vec<u8>,
|
||||||
fn name() -> &'static str {
|
|
||||||
"get_content_thumbnail"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn description() -> &'static str {
|
|
||||||
"Get a thumbnail of content from the media store."
|
|
||||||
}
|
|
||||||
|
|
||||||
fn requires_authentication() -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rate_limited() -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for Method {
|
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
|
|
||||||
match *self {
|
|
||||||
Method::Crop => write!(f, "crop"),
|
|
||||||
Method::Scale => write!(f, "scale"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user