mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-06-27 16:35:59 +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
596
Cargo.lock
generated
596
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -147,7 +147,7 @@ tikv-jemallocator = { version = "0.5.0", features = [
|
|||
|
||||
sd-notify = { version = "0.4.1", optional = true }
|
||||
|
||||
webpage = { version = "1.6", default-features = false, optional = true }
|
||||
webpage = { version = "1.6", default-features = false }
|
||||
|
||||
# Used for matrix spec type definitions and helpers
|
||||
[dependencies.ruma]
|
||||
|
@ -188,7 +188,6 @@ conduit_bin = ["axum"]
|
|||
jemalloc = ["tikv-jemallocator"]
|
||||
sqlite = ["parking_lot", "rusqlite", "tokio/signal"]
|
||||
systemd = ["sd-notify"]
|
||||
url_preview = ["webpage"]
|
||||
|
||||
[[bin]]
|
||||
name = "conduit"
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
use ruma::api::client::error::ErrorKind;
|
||||
|
||||
use crate::{database::KeyValueDatabase, service, utils, Error, Result};
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
use crate::service::media::UrlPreviewData;
|
||||
use crate::{database::KeyValueDatabase, service::{self, media::UrlPreviewData}, utils, Error, Result};
|
||||
|
||||
impl service::media::Data for KeyValueDatabase {
|
||||
fn create_file_metadata(
|
||||
|
@ -83,12 +80,10 @@ impl service::media::Data for KeyValueDatabase {
|
|||
Ok((content_disposition, content_type, key))
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
fn remove_url_preview(&self, url: &str) -> Result<()> {
|
||||
self.url_previews.remove(url.as_bytes())
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
fn set_url_preview(&self, url: &str, data: &UrlPreviewData, timestamp: std::time::Duration) -> Result<()> {
|
||||
let mut value = Vec::<u8>::new();
|
||||
value.extend_from_slice(×tamp.as_secs().to_be_bytes());
|
||||
|
@ -123,7 +118,6 @@ impl service::media::Data for KeyValueDatabase {
|
|||
self.url_previews.insert(url.as_bytes(), &value)
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
fn get_url_preview(&self, url: &str) -> Option<UrlPreviewData> {
|
||||
let values = self.url_previews.get(url.as_bytes()).ok()??;
|
||||
|
||||
|
|
|
@ -146,7 +146,6 @@ pub struct KeyValueDatabase {
|
|||
|
||||
//pub media: media::Media,
|
||||
pub(super) mediaid_file: Arc<dyn KvTree>, // MediaId = MXC + WidthHeight + ContentDisposition + ContentType
|
||||
#[cfg(feature = "url_preview")]
|
||||
pub(super) url_previews: Arc<dyn KvTree>,
|
||||
//pub key_backups: key_backups::KeyBackups,
|
||||
pub(super) backupid_algorithm: Arc<dyn KvTree>, // BackupId = UserId + Version(Count)
|
||||
|
@ -364,7 +363,6 @@ impl KeyValueDatabase {
|
|||
roomuserdataid_accountdata: builder.open_tree("roomuserdataid_accountdata")?,
|
||||
roomusertype_roomuserdataid: builder.open_tree("roomusertype_roomuserdataid")?,
|
||||
mediaid_file: builder.open_tree("mediaid_file")?,
|
||||
#[cfg(feature = "url_preview")]
|
||||
url_previews: builder.open_tree("url_previews")?,
|
||||
backupid_algorithm: builder.open_tree("backupid_algorithm")?,
|
||||
backupid_etag: builder.open_tree("backupid_etag")?,
|
||||
|
|
|
@ -18,13 +18,11 @@ pub trait Data: Send + Sync {
|
|||
height: u32,
|
||||
) -> Result<(Option<String>, Option<String>, Vec<u8>)>;
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
fn remove_url_preview(
|
||||
&self,
|
||||
url: &str
|
||||
) -> Result<()>;
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
fn set_url_preview(
|
||||
&self,
|
||||
url: &str,
|
||||
|
@ -32,7 +30,6 @@ pub trait Data: Send + Sync {
|
|||
timestamp: std::time::Duration,
|
||||
) -> Result<()>;
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
fn get_url_preview(
|
||||
&self,
|
||||
url: &str
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
mod data;
|
||||
use std::io::Cursor;
|
||||
use std::{
|
||||
io::Cursor,
|
||||
collections::HashMap,
|
||||
sync::{Arc, RwLock},
|
||||
time::SystemTime,
|
||||
};
|
||||
|
||||
pub use data::Data;
|
||||
|
||||
|
@ -9,18 +14,9 @@ use image::imageops::FilterType;
|
|||
use tokio::{
|
||||
fs::File,
|
||||
io::{AsyncReadExt, AsyncWriteExt, BufReader},
|
||||
sync::Notify,
|
||||
};
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
use {
|
||||
std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, RwLock},
|
||||
},
|
||||
serde::Serialize,
|
||||
std::time::SystemTime,
|
||||
tokio::sync::Notify,
|
||||
};
|
||||
use serde::Serialize;
|
||||
|
||||
pub struct FileMeta {
|
||||
pub content_disposition: Option<String>,
|
||||
|
@ -28,7 +24,6 @@ pub struct FileMeta {
|
|||
pub file: Vec<u8>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
#[derive(Serialize, Default)]
|
||||
pub struct UrlPreviewData {
|
||||
#[serde(
|
||||
|
@ -65,7 +60,6 @@ pub struct UrlPreviewData {
|
|||
|
||||
pub struct Service {
|
||||
pub db: &'static dyn Data,
|
||||
#[cfg(feature = "url_preview")]
|
||||
pub url_preview_requests: RwLock<HashMap<String, Arc<Notify>>>,
|
||||
}
|
||||
|
||||
|
@ -274,18 +268,15 @@ impl Service {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
pub async fn get_url_preview(&self, url: &str) -> Option<UrlPreviewData> {
|
||||
self.db.get_url_preview(url)
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
pub async fn remove_url_preview(&self, url: &str) -> Result<()> {
|
||||
// TODO: also remove the downloaded image
|
||||
self.db.remove_url_preview(url)
|
||||
}
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
pub async fn set_url_preview(&self, url: &str, data: &UrlPreviewData) -> Result<()> {
|
||||
let now = SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
sync::{Arc, Mutex as StdMutex},
|
||||
sync::{Arc, Mutex as StdMutex, RwLock as StdRwLock},
|
||||
};
|
||||
|
||||
#[cfg(feature = "url_preview")]
|
||||
use std::sync::RwLock;
|
||||
|
||||
use lru_cache::LruCache;
|
||||
use tokio::sync::{broadcast, Mutex};
|
||||
|
||||
|
@ -123,8 +120,7 @@ impl Services {
|
|||
key_backups: key_backups::Service { db },
|
||||
media: media::Service {
|
||||
db,
|
||||
#[cfg(feature = "url_preview")]
|
||||
url_preview_requests: RwLock::new(HashMap::new())
|
||||
url_preview_requests: StdRwLock::new(HashMap::new())
|
||||
},
|
||||
sending: sending::Service::build(db, &config),
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue