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 }
|
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
|
# Used for matrix spec type definitions and helpers
|
||||||
[dependencies.ruma]
|
[dependencies.ruma]
|
||||||
|
@ -188,7 +188,6 @@ conduit_bin = ["axum"]
|
||||||
jemalloc = ["tikv-jemallocator"]
|
jemalloc = ["tikv-jemallocator"]
|
||||||
sqlite = ["parking_lot", "rusqlite", "tokio/signal"]
|
sqlite = ["parking_lot", "rusqlite", "tokio/signal"]
|
||||||
systemd = ["sd-notify"]
|
systemd = ["sd-notify"]
|
||||||
url_preview = ["webpage"]
|
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "conduit"
|
name = "conduit"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::time::Duration;
|
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::{
|
use ruma::api::client::{
|
||||||
error::{ErrorKind, RetryAfter},
|
error::{ErrorKind, RetryAfter},
|
||||||
media::{
|
media::{
|
||||||
|
@ -9,9 +9,7 @@ use ruma::api::client::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
use {
|
use {
|
||||||
crate::service::media::UrlPreviewData,
|
|
||||||
webpage::HTML,
|
webpage::HTML,
|
||||||
reqwest::Url,
|
reqwest::Url,
|
||||||
std::{io::Cursor, net::IpAddr, sync::Arc},
|
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(
|
async fn download_image(
|
||||||
client: &reqwest::Client,
|
client: &reqwest::Client,
|
||||||
url: &str,
|
url: &str,
|
||||||
|
@ -64,7 +61,6 @@ async fn download_image(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
async fn download_html(
|
async fn download_html(
|
||||||
client: &reqwest::Client,
|
client: &reqwest::Client,
|
||||||
url: &str,
|
url: &str,
|
||||||
|
@ -103,7 +99,6 @@ async fn download_html(
|
||||||
Ok(data)
|
Ok(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
fn url_request_allowed(addr: &IpAddr) -> bool {
|
fn url_request_allowed(addr: &IpAddr) -> bool {
|
||||||
// could be implemented with reqwest when it supports IP filtering:
|
// could be implemented with reqwest when it supports IP filtering:
|
||||||
// https://github.com/seanmonstar/reqwest/issues/1515
|
// 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> {
|
async fn request_url_preview(url: &str) -> Result<UrlPreviewData> {
|
||||||
let client = services().globals.default_client();
|
let client = services().globals.default_client();
|
||||||
let response = client.head(url).send().await?;
|
let response = client.head(url).send().await?;
|
||||||
|
@ -167,7 +161,6 @@ async fn request_url_preview(url: &str) -> Result<UrlPreviewData> {
|
||||||
Ok(data)
|
Ok(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
async fn get_url_preview(url: &str) -> Result<UrlPreviewData> {
|
async fn get_url_preview(url: &str) -> Result<UrlPreviewData> {
|
||||||
if let Some(preview) = services().media.get_url_preview(url).await {
|
if let Some(preview) = services().media.get_url_preview(url).await {
|
||||||
return Ok(preview);
|
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 {
|
fn url_preview_allowed(url_str: &str) -> bool {
|
||||||
const DEFAULT_ALLOWLIST: &[&str] = &[
|
const DEFAULT_ALLOWLIST: &[&str] = &[
|
||||||
"matrix.org",
|
"matrix.org",
|
||||||
|
@ -263,7 +255,6 @@ fn url_preview_allowed(url_str: &str) -> bool {
|
||||||
/// # `GET /_matrix/media/r0/preview_url`
|
/// # `GET /_matrix/media/r0/preview_url`
|
||||||
///
|
///
|
||||||
/// Returns URL preview.
|
/// Returns URL preview.
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
pub async fn get_media_preview_route(
|
pub async fn get_media_preview_route(
|
||||||
body: Ruma<get_media_preview::v3::Request>,
|
body: Ruma<get_media_preview::v3::Request>,
|
||||||
) -> Result<get_media_preview::v3::Response> {
|
) -> 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`
|
/// # `POST /_matrix/media/r0/upload`
|
||||||
///
|
///
|
||||||
/// Permanently save media in the server.
|
/// Permanently save media in the server.
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
use ruma::api::client::error::ErrorKind;
|
use ruma::api::client::error::ErrorKind;
|
||||||
|
|
||||||
use crate::{database::KeyValueDatabase, service, utils, Error, Result};
|
use crate::{database::KeyValueDatabase, service::{self, media::UrlPreviewData}, utils, Error, Result};
|
||||||
|
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
use crate::service::media::UrlPreviewData;
|
|
||||||
|
|
||||||
impl service::media::Data for KeyValueDatabase {
|
impl service::media::Data for KeyValueDatabase {
|
||||||
fn create_file_metadata(
|
fn create_file_metadata(
|
||||||
|
@ -83,12 +80,10 @@ impl service::media::Data for KeyValueDatabase {
|
||||||
Ok((content_disposition, content_type, key))
|
Ok((content_disposition, content_type, key))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
fn remove_url_preview(&self, url: &str) -> Result<()> {
|
fn remove_url_preview(&self, url: &str) -> Result<()> {
|
||||||
self.url_previews.remove(url.as_bytes())
|
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<()> {
|
fn set_url_preview(&self, url: &str, data: &UrlPreviewData, timestamp: std::time::Duration) -> Result<()> {
|
||||||
let mut value = Vec::<u8>::new();
|
let mut value = Vec::<u8>::new();
|
||||||
value.extend_from_slice(×tamp.as_secs().to_be_bytes());
|
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)
|
self.url_previews.insert(url.as_bytes(), &value)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
fn get_url_preview(&self, url: &str) -> Option<UrlPreviewData> {
|
fn get_url_preview(&self, url: &str) -> Option<UrlPreviewData> {
|
||||||
let values = self.url_previews.get(url.as_bytes()).ok()??;
|
let values = self.url_previews.get(url.as_bytes()).ok()??;
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,6 @@ pub struct KeyValueDatabase {
|
||||||
|
|
||||||
//pub media: media::Media,
|
//pub media: media::Media,
|
||||||
pub(super) mediaid_file: Arc<dyn KvTree>, // MediaId = MXC + WidthHeight + ContentDisposition + ContentType
|
pub(super) mediaid_file: Arc<dyn KvTree>, // MediaId = MXC + WidthHeight + ContentDisposition + ContentType
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
pub(super) url_previews: Arc<dyn KvTree>,
|
pub(super) url_previews: Arc<dyn KvTree>,
|
||||||
//pub key_backups: key_backups::KeyBackups,
|
//pub key_backups: key_backups::KeyBackups,
|
||||||
pub(super) backupid_algorithm: Arc<dyn KvTree>, // BackupId = UserId + Version(Count)
|
pub(super) backupid_algorithm: Arc<dyn KvTree>, // BackupId = UserId + Version(Count)
|
||||||
|
@ -364,7 +363,6 @@ impl KeyValueDatabase {
|
||||||
roomuserdataid_accountdata: builder.open_tree("roomuserdataid_accountdata")?,
|
roomuserdataid_accountdata: builder.open_tree("roomuserdataid_accountdata")?,
|
||||||
roomusertype_roomuserdataid: builder.open_tree("roomusertype_roomuserdataid")?,
|
roomusertype_roomuserdataid: builder.open_tree("roomusertype_roomuserdataid")?,
|
||||||
mediaid_file: builder.open_tree("mediaid_file")?,
|
mediaid_file: builder.open_tree("mediaid_file")?,
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
url_previews: builder.open_tree("url_previews")?,
|
url_previews: builder.open_tree("url_previews")?,
|
||||||
backupid_algorithm: builder.open_tree("backupid_algorithm")?,
|
backupid_algorithm: builder.open_tree("backupid_algorithm")?,
|
||||||
backupid_etag: builder.open_tree("backupid_etag")?,
|
backupid_etag: builder.open_tree("backupid_etag")?,
|
||||||
|
|
|
@ -18,13 +18,11 @@ pub trait Data: Send + Sync {
|
||||||
height: u32,
|
height: u32,
|
||||||
) -> Result<(Option<String>, Option<String>, Vec<u8>)>;
|
) -> Result<(Option<String>, Option<String>, Vec<u8>)>;
|
||||||
|
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
fn remove_url_preview(
|
fn remove_url_preview(
|
||||||
&self,
|
&self,
|
||||||
url: &str
|
url: &str
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
|
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
fn set_url_preview(
|
fn set_url_preview(
|
||||||
&self,
|
&self,
|
||||||
url: &str,
|
url: &str,
|
||||||
|
@ -32,7 +30,6 @@ pub trait Data: Send + Sync {
|
||||||
timestamp: std::time::Duration,
|
timestamp: std::time::Duration,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
|
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
fn get_url_preview(
|
fn get_url_preview(
|
||||||
&self,
|
&self,
|
||||||
url: &str
|
url: &str
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
mod data;
|
mod data;
|
||||||
use std::io::Cursor;
|
use std::{
|
||||||
|
io::Cursor,
|
||||||
|
collections::HashMap,
|
||||||
|
sync::{Arc, RwLock},
|
||||||
|
time::SystemTime,
|
||||||
|
};
|
||||||
|
|
||||||
pub use data::Data;
|
pub use data::Data;
|
||||||
|
|
||||||
|
@ -9,18 +14,9 @@ use image::imageops::FilterType;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{AsyncReadExt, AsyncWriteExt, BufReader},
|
io::{AsyncReadExt, AsyncWriteExt, BufReader},
|
||||||
|
sync::Notify,
|
||||||
};
|
};
|
||||||
|
use serde::Serialize;
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
use {
|
|
||||||
std::{
|
|
||||||
collections::HashMap,
|
|
||||||
sync::{Arc, RwLock},
|
|
||||||
},
|
|
||||||
serde::Serialize,
|
|
||||||
std::time::SystemTime,
|
|
||||||
tokio::sync::Notify,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct FileMeta {
|
pub struct FileMeta {
|
||||||
pub content_disposition: Option<String>,
|
pub content_disposition: Option<String>,
|
||||||
|
@ -28,7 +24,6 @@ pub struct FileMeta {
|
||||||
pub file: Vec<u8>,
|
pub file: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
#[derive(Serialize, Default)]
|
#[derive(Serialize, Default)]
|
||||||
pub struct UrlPreviewData {
|
pub struct UrlPreviewData {
|
||||||
#[serde(
|
#[serde(
|
||||||
|
@ -65,7 +60,6 @@ pub struct UrlPreviewData {
|
||||||
|
|
||||||
pub struct Service {
|
pub struct Service {
|
||||||
pub db: &'static dyn Data,
|
pub db: &'static dyn Data,
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
pub url_preview_requests: RwLock<HashMap<String, Arc<Notify>>>,
|
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> {
|
pub async fn get_url_preview(&self, url: &str) -> Option<UrlPreviewData> {
|
||||||
self.db.get_url_preview(url)
|
self.db.get_url_preview(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
pub async fn remove_url_preview(&self, url: &str) -> Result<()> {
|
pub async fn remove_url_preview(&self, url: &str) -> Result<()> {
|
||||||
// TODO: also remove the downloaded image
|
// TODO: also remove the downloaded image
|
||||||
self.db.remove_url_preview(url)
|
self.db.remove_url_preview(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "url_preview")]
|
|
||||||
pub async fn set_url_preview(&self, url: &str, data: &UrlPreviewData) -> Result<()> {
|
pub async fn set_url_preview(&self, url: &str, data: &UrlPreviewData) -> Result<()> {
|
||||||
let now = SystemTime::now()
|
let now = SystemTime::now()
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, HashMap},
|
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 lru_cache::LruCache;
|
||||||
use tokio::sync::{broadcast, Mutex};
|
use tokio::sync::{broadcast, Mutex};
|
||||||
|
|
||||||
|
@ -123,8 +120,7 @@ impl Services {
|
||||||
key_backups: key_backups::Service { db },
|
key_backups: key_backups::Service { db },
|
||||||
media: media::Service {
|
media: media::Service {
|
||||||
db,
|
db,
|
||||||
#[cfg(feature = "url_preview")]
|
url_preview_requests: StdRwLock::new(HashMap::new())
|
||||||
url_preview_requests: RwLock::new(HashMap::new())
|
|
||||||
},
|
},
|
||||||
sending: sending::Service::build(db, &config),
|
sending: sending::Service::build(db, &config),
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue