mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-07-02 16:38:36 +00:00
Drop feature flag, as it's no longer required
This commit is contained in:
parent
8f147379ea
commit
d6e3d9aa8a
8 changed files with 533 additions and 133 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use crate::{service::media::FileMeta, services, utils, Error, Result, Ruma};
|
||||
use crate::{service::media::{FileMeta, UrlPreviewData}, services, utils, Error, Result, Ruma};
|
||||
use ruma::api::client::{
|
||||
error::{ErrorKind, RetryAfter},
|
||||
media::{
|
||||
|
@ -9,9 +9,7 @@ use ruma::api::client::{
|
|||
},
|
||||
};
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
use {
|
||||
crate::service::media::UrlPreviewData,
|
||||
webpage::HTML,
|
||||
reqwest::Url,
|
||||
std::{io::Cursor, net::IpAddr, sync::Arc},
|
||||
|
@ -32,7 +30,6 @@ pub async fn get_media_config_route(
|
|||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
async fn download_image(
|
||||
client: &reqwest::Client,
|
||||
url: &str,
|
||||
|
@ -64,7 +61,6 @@ async fn download_image(
|
|||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
async fn download_html(
|
||||
client: &reqwest::Client,
|
||||
url: &str,
|
||||
|
@ -103,7 +99,6 @@ async fn download_html(
|
|||
Ok(data)
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
fn url_request_allowed(addr: &IpAddr) -> bool {
|
||||
// could be implemented with reqwest when it supports IP filtering:
|
||||
// https://github.com/seanmonstar/reqwest/issues/1515
|
||||
|
@ -123,7 +118,6 @@ fn url_request_allowed(addr: &IpAddr) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
async fn request_url_preview(url: &str) -> Result<UrlPreviewData> {
|
||||
let client = services().globals.default_client();
|
||||
let response = client.head(url).send().await?;
|
||||
|
@ -167,7 +161,6 @@ async fn request_url_preview(url: &str) -> Result<UrlPreviewData> {
|
|||
Ok(data)
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
async fn get_url_preview(url: &str) -> Result<UrlPreviewData> {
|
||||
if let Some(preview) = services().media.get_url_preview(url).await {
|
||||
return Ok(preview);
|
||||
|
@ -219,7 +212,6 @@ async fn get_url_preview(url: &str) -> Result<UrlPreviewData> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
fn url_preview_allowed(url_str: &str) -> bool {
|
||||
const DEFAULT_ALLOWLIST: &[&str] = &[
|
||||
"matrix.org",
|
||||
|
@ -263,7 +255,6 @@ fn url_preview_allowed(url_str: &str) -> bool {
|
|||
/// # `GET /_matrix/media/r0/preview_url`
|
||||
///
|
||||
/// Returns URL preview.
|
||||
#[cfg(feature = "url_preview")]
|
||||
pub async fn get_media_preview_route(
|
||||
body: Ruma<get_media_preview::v3::Request>,
|
||||
) -> Result<get_media_preview::v3::Response> {
|
||||
|
@ -288,16 +279,6 @@ pub async fn get_media_preview_route(
|
|||
))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "url_preview"))]
|
||||
pub async fn get_media_preview_route(
|
||||
_body: Ruma<get_media_preview::v3::Request>,
|
||||
) -> Result<get_media_preview::v3::Response> {
|
||||
Err(Error::BadRequest(
|
||||
ErrorKind::Forbidden,
|
||||
"URL preview not implemented",
|
||||
))
|
||||
}
|
||||
|
||||
/// # `POST /_matrix/media/r0/upload`
|
||||
///
|
||||
/// Permanently save media in the server.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue