mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
feat: Add local media self-redaction
This commit is contained in:
Generated
+14
-14
@@ -1311,7 +1311,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "continuwuity-admin-api"
|
name = "continuwuity-admin-api"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=85d00fb5746cba23904234b4fd3c838dcf141541#85d00fb5746cba23904234b4fd3c838dcf141541"
|
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=db86e37d602cc4935853bf14d5aace47d22358ed#db86e37d602cc4935853bf14d5aace47d22358ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ruma-common",
|
"ruma-common",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -1691,7 +1691,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "draupnir-antispam"
|
name = "draupnir-antispam"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=85d00fb5746cba23904234b4fd3c838dcf141541#85d00fb5746cba23904234b4fd3c838dcf141541"
|
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=db86e37d602cc4935853bf14d5aace47d22358ed#db86e37d602cc4935853bf14d5aace47d22358ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ruma-common",
|
"ruma-common",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -3039,7 +3039,7 @@ checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "meowlnir-antispam"
|
name = "meowlnir-antispam"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=85d00fb5746cba23904234b4fd3c838dcf141541#85d00fb5746cba23904234b4fd3c838dcf141541"
|
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=db86e37d602cc4935853bf14d5aace47d22358ed#db86e37d602cc4935853bf14d5aace47d22358ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ruma-common",
|
"ruma-common",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -4254,7 +4254,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ruma"
|
name = "ruma"
|
||||||
version = "0.10.1"
|
version = "0.10.1"
|
||||||
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=85d00fb5746cba23904234b4fd3c838dcf141541#85d00fb5746cba23904234b4fd3c838dcf141541"
|
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=db86e37d602cc4935853bf14d5aace47d22358ed#db86e37d602cc4935853bf14d5aace47d22358ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assign",
|
"assign",
|
||||||
"continuwuity-admin-api",
|
"continuwuity-admin-api",
|
||||||
@@ -4277,7 +4277,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ruma-appservice-api"
|
name = "ruma-appservice-api"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=85d00fb5746cba23904234b4fd3c838dcf141541#85d00fb5746cba23904234b4fd3c838dcf141541"
|
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=db86e37d602cc4935853bf14d5aace47d22358ed#db86e37d602cc4935853bf14d5aace47d22358ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"js_int",
|
"js_int",
|
||||||
"ruma-common",
|
"ruma-common",
|
||||||
@@ -4289,7 +4289,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ruma-client-api"
|
name = "ruma-client-api"
|
||||||
version = "0.18.0"
|
version = "0.18.0"
|
||||||
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=85d00fb5746cba23904234b4fd3c838dcf141541#85d00fb5746cba23904234b4fd3c838dcf141541"
|
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=db86e37d602cc4935853bf14d5aace47d22358ed#db86e37d602cc4935853bf14d5aace47d22358ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"as_variant",
|
"as_variant",
|
||||||
"assign",
|
"assign",
|
||||||
@@ -4312,7 +4312,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ruma-common"
|
name = "ruma-common"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=85d00fb5746cba23904234b4fd3c838dcf141541#85d00fb5746cba23904234b4fd3c838dcf141541"
|
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=db86e37d602cc4935853bf14d5aace47d22358ed#db86e37d602cc4935853bf14d5aace47d22358ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"as_variant",
|
"as_variant",
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
@@ -4344,7 +4344,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ruma-events"
|
name = "ruma-events"
|
||||||
version = "0.28.1"
|
version = "0.28.1"
|
||||||
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=85d00fb5746cba23904234b4fd3c838dcf141541#85d00fb5746cba23904234b4fd3c838dcf141541"
|
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=db86e37d602cc4935853bf14d5aace47d22358ed#db86e37d602cc4935853bf14d5aace47d22358ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"as_variant",
|
"as_variant",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
@@ -4369,7 +4369,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ruma-federation-api"
|
name = "ruma-federation-api"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=85d00fb5746cba23904234b4fd3c838dcf141541#85d00fb5746cba23904234b4fd3c838dcf141541"
|
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=db86e37d602cc4935853bf14d5aace47d22358ed#db86e37d602cc4935853bf14d5aace47d22358ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"headers",
|
"headers",
|
||||||
@@ -4391,7 +4391,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ruma-identifiers-validation"
|
name = "ruma-identifiers-validation"
|
||||||
version = "0.9.5"
|
version = "0.9.5"
|
||||||
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=85d00fb5746cba23904234b4fd3c838dcf141541#85d00fb5746cba23904234b4fd3c838dcf141541"
|
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=db86e37d602cc4935853bf14d5aace47d22358ed#db86e37d602cc4935853bf14d5aace47d22358ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"js_int",
|
"js_int",
|
||||||
"thiserror 2.0.17",
|
"thiserror 2.0.17",
|
||||||
@@ -4400,7 +4400,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ruma-identity-service-api"
|
name = "ruma-identity-service-api"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=85d00fb5746cba23904234b4fd3c838dcf141541#85d00fb5746cba23904234b4fd3c838dcf141541"
|
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=db86e37d602cc4935853bf14d5aace47d22358ed#db86e37d602cc4935853bf14d5aace47d22358ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"js_int",
|
"js_int",
|
||||||
"ruma-common",
|
"ruma-common",
|
||||||
@@ -4410,7 +4410,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ruma-macros"
|
name = "ruma-macros"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=85d00fb5746cba23904234b4fd3c838dcf141541#85d00fb5746cba23904234b4fd3c838dcf141541"
|
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=db86e37d602cc4935853bf14d5aace47d22358ed#db86e37d602cc4935853bf14d5aace47d22358ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"proc-macro-crate",
|
"proc-macro-crate",
|
||||||
@@ -4425,7 +4425,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ruma-push-gateway-api"
|
name = "ruma-push-gateway-api"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=85d00fb5746cba23904234b4fd3c838dcf141541#85d00fb5746cba23904234b4fd3c838dcf141541"
|
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=db86e37d602cc4935853bf14d5aace47d22358ed#db86e37d602cc4935853bf14d5aace47d22358ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"js_int",
|
"js_int",
|
||||||
"ruma-common",
|
"ruma-common",
|
||||||
@@ -4437,7 +4437,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ruma-signatures"
|
name = "ruma-signatures"
|
||||||
version = "0.15.0"
|
version = "0.15.0"
|
||||||
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=85d00fb5746cba23904234b4fd3c838dcf141541#85d00fb5746cba23904234b4fd3c838dcf141541"
|
source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=db86e37d602cc4935853bf14d5aace47d22358ed#db86e37d602cc4935853bf14d5aace47d22358ed"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
"ed25519-dalek",
|
"ed25519-dalek",
|
||||||
|
|||||||
+1
-1
@@ -342,7 +342,7 @@ version = "0.1.2"
|
|||||||
# Used for matrix spec type definitions and helpers
|
# Used for matrix spec type definitions and helpers
|
||||||
[workspace.dependencies.ruma]
|
[workspace.dependencies.ruma]
|
||||||
git = "https://forgejo.ellis.link/continuwuation/ruwuma"
|
git = "https://forgejo.ellis.link/continuwuation/ruwuma"
|
||||||
rev = "85d00fb5746cba23904234b4fd3c838dcf141541"
|
rev = "db86e37d602cc4935853bf14d5aace47d22358ed"
|
||||||
features = [
|
features = [
|
||||||
"compat",
|
"compat",
|
||||||
"rand",
|
"rand",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use reqwest::Url;
|
|||||||
use ruma::{
|
use ruma::{
|
||||||
Mxc, UserId,
|
Mxc, UserId,
|
||||||
api::client::{
|
api::client::{
|
||||||
|
authenticated_media,
|
||||||
authenticated_media::{
|
authenticated_media::{
|
||||||
get_content, get_content_as_filename, get_content_thumbnail, get_media_config,
|
get_content, get_content_as_filename, get_content_thumbnail, get_media_config,
|
||||||
get_media_preview,
|
get_media_preview,
|
||||||
@@ -244,6 +245,33 @@ pub(crate) async fn get_media_preview_route(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(
|
||||||
|
name = "media_redact",
|
||||||
|
level = "debug",
|
||||||
|
skip_all,
|
||||||
|
fields(%_client),
|
||||||
|
)]
|
||||||
|
pub(crate) async fn redact_media_route(
|
||||||
|
State(services): State<crate::State>,
|
||||||
|
InsecureClientIp(_client): InsecureClientIp,
|
||||||
|
body: Ruma<authenticated_media::redact::unstable::Request>,
|
||||||
|
) -> Result<authenticated_media::redact::unstable::Response> {
|
||||||
|
let user = body.sender_user();
|
||||||
|
|
||||||
|
let mxc = Mxc {
|
||||||
|
server_name: &body.server_name,
|
||||||
|
media_id: &body.media_id,
|
||||||
|
};
|
||||||
|
|
||||||
|
if !services.media.user_owns(&user, &mxc).await {
|
||||||
|
return Err!(Request(Forbidden("You do not have permission to redact this attachment.")));
|
||||||
|
}
|
||||||
|
|
||||||
|
services.media.delete(&mxc).await?; // TODO: Only delete file and mark as redacted
|
||||||
|
|
||||||
|
Ok(authenticated_media::redact::unstable::Response {})
|
||||||
|
}
|
||||||
|
|
||||||
async fn fetch_thumbnail(
|
async fn fetch_thumbnail(
|
||||||
services: &Services,
|
services: &Services,
|
||||||
mxc: &Mxc<'_>,
|
mxc: &Mxc<'_>,
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ pub fn build(router: Router<State>, server: &Server) -> Router<State> {
|
|||||||
.ruma_route(&client::get_content_route)
|
.ruma_route(&client::get_content_route)
|
||||||
.ruma_route(&client::get_content_as_filename_route)
|
.ruma_route(&client::get_content_as_filename_route)
|
||||||
.ruma_route(&client::get_media_preview_route)
|
.ruma_route(&client::get_media_preview_route)
|
||||||
|
.ruma_route(&client::redact_media_route)
|
||||||
.ruma_route(&client::get_media_config_route)
|
.ruma_route(&client::get_media_config_route)
|
||||||
.ruma_route(&client::get_devices_route)
|
.ruma_route(&client::get_devices_route)
|
||||||
.ruma_route(&client::get_device_route)
|
.ruma_route(&client::get_device_route)
|
||||||
|
|||||||
@@ -229,6 +229,18 @@ impl Service {
|
|||||||
Ok(mxcs)
|
Ok(mxcs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Checks if a user owns a given MXC URI
|
||||||
|
pub async fn user_owns(&self, user: &UserId, mxc: &Mxc<'_>) -> bool {
|
||||||
|
self
|
||||||
|
.db
|
||||||
|
.get_all_user_mxcs(user) // TODO: this can be more efficient.
|
||||||
|
.await
|
||||||
|
.iter()
|
||||||
|
.any(|v| {
|
||||||
|
v.parts().map(|x|(x.server_name, x.media_id)) == Ok((mxc.server_name, mxc.media_id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Deletes all media files in the given time frame.
|
/// Deletes all media files in the given time frame.
|
||||||
/// Returns a usize with the amount of media files deleted.
|
/// Returns a usize with the amount of media files deleted.
|
||||||
pub async fn delete_all_media_within_timeframe(
|
pub async fn delete_all_media_within_timeframe(
|
||||||
|
|||||||
Reference in New Issue
Block a user