Compare commits
No commits in common. "b88c13e5870cefa32159c4978886953020e598d3" and "3d8aca843e44dff435c8e4cfa0662e2a6b3e0a31" have entirely different histories.
b88c13e587
...
3d8aca843e
4 changed files with 9 additions and 77 deletions
|
@ -1,12 +1,11 @@
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
use sea_orm::{ActiveModelTrait, ActiveValue::{Set, Unchanged}, ColumnTrait, Condition, EntityTrait, IntoActiveModel, QueryFilter, QuerySelect, SelectColumns, TransactionTrait};
|
use sea_orm::{ActiveModelTrait, ActiveValue::{Set, Unchanged}, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter, QuerySelect, SelectColumns, TransactionTrait};
|
||||||
use upub::traits::{fetch::RequestError, Cloaker};
|
use upub::traits::{fetch::RequestError, Cloaker};
|
||||||
|
|
||||||
pub async fn cloak(ctx: upub::Context, post_contents: bool, actors: bool) -> Result<(), RequestError> {
|
pub async fn cloak(ctx: upub::Context, post_contents: bool) -> Result<(), RequestError> {
|
||||||
let local_base = format!("{}%", ctx.base()));
|
|
||||||
{
|
{
|
||||||
let mut stream = upub::model::attachment::Entity::find()
|
let mut stream = upub::model::attachment::Entity::find()
|
||||||
.filter(upub::model::attachment::Column::Url.not_like(&local_base)
|
.filter(upub::model::attachment::Column::Url.not_like(format!("{}%", ctx.base())))
|
||||||
.stream(ctx.db())
|
.stream(ctx.db())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -43,41 +42,5 @@ pub async fn cloak(ctx: upub::Context, post_contents: bool, actors: bool) -> Res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if actors {
|
|
||||||
let mut stream = upub::model::actor::Entity::find()
|
|
||||||
.filter(
|
|
||||||
Condition::any()
|
|
||||||
.add(upub::model::actor::Column::Image.not_like(&local_base))
|
|
||||||
.add(upub::model::actor::Column::Icon.not_like(&local_base))
|
|
||||||
)
|
|
||||||
.select_only()
|
|
||||||
.select_column(upub::model::actor::Column::Internal)
|
|
||||||
.select_column(upub::model::actor::Column::Image)
|
|
||||||
.select_column(upub::model::actor::Column::Icon)
|
|
||||||
.into_tuple::<(i64, Option<String>, Option<String>)>()
|
|
||||||
.stream(ctx.db())
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
while let Some((internal, image, icon)) = stream.try_next().await? {
|
|
||||||
if image.is_none() && icon.is_none() { continue }
|
|
||||||
let image = if let Some(img) = image && !img.starts_with(ctx.base()) {
|
|
||||||
Set(ctx.cloaked(&img))
|
|
||||||
} else {
|
|
||||||
NotSet
|
|
||||||
};
|
|
||||||
let icon = if let Some(icn) = icon && !icn.starts_with(ctx.base()) {
|
|
||||||
Set(ctx.cloaked(&icn))
|
|
||||||
} else {
|
|
||||||
NotSet
|
|
||||||
};
|
|
||||||
let model = upub::model::actor::ActiveModel {
|
|
||||||
internal: Unchanged(internal),
|
|
||||||
image, icon,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
model.update(ctx.db()).await?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,10 +119,6 @@ pub enum CliCommand {
|
||||||
/// also replace urls inside post contents
|
/// also replace urls inside post contents
|
||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
post_contents: bool,
|
post_contents: bool,
|
||||||
|
|
||||||
/// also cloak actor images
|
|
||||||
#[arg(long, default_value_t = false)]
|
|
||||||
actors: bool,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +141,7 @@ pub async fn run(ctx: upub::Context, command: CliCommand) -> Result<(), Box<dyn
|
||||||
Ok(nuke(ctx, for_real, delete_objects).await?),
|
Ok(nuke(ctx, for_real, delete_objects).await?),
|
||||||
CliCommand::Thread { } =>
|
CliCommand::Thread { } =>
|
||||||
Ok(thread(ctx).await?),
|
Ok(thread(ctx).await?),
|
||||||
CliCommand::Cloak { post_contents, actors } =>
|
CliCommand::Cloak { post_contents } =>
|
||||||
Ok(cloak(ctx, post_contents, actors).await?),
|
Ok(cloak(ctx, post_contents).await?),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@ use std::collections::BTreeMap;
|
||||||
|
|
||||||
use apb::{Activity, Actor, ActorMut, Base, Collection, Object};
|
use apb::{Activity, Actor, ActorMut, Base, Collection, Object};
|
||||||
use reqwest::{header::{ACCEPT, CONTENT_TYPE, USER_AGENT}, Method, Response};
|
use reqwest::{header::{ACCEPT, CONTENT_TYPE, USER_AGENT}, Method, Response};
|
||||||
use sea_orm::{ConnectionTrait, DbErr, EntityTrait, IntoActiveModel, NotSet, ActiveValue::{Set, NotSet, Unchanged}};
|
use sea_orm::{ConnectionTrait, DbErr, EntityTrait, IntoActiveModel, NotSet};
|
||||||
|
|
||||||
use crate::traits::normalize::AP;
|
use crate::traits::normalize::AP;
|
||||||
|
|
||||||
use super::{Addresser, Cloaker, Normalizer};
|
use super::{Addresser, Normalizer};
|
||||||
use httpsign::HttpSignature;
|
use httpsign::HttpSignature;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -305,20 +305,7 @@ impl Fetcher for crate::Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut user_model = AP::actor_q(&document, None)?;
|
let user_model = AP::actor_q(&document, None)?;
|
||||||
|
|
||||||
// cloak remote images
|
|
||||||
if let Set(Some(ref image)) = user_model.image {
|
|
||||||
if !image.starts_with(self.base()) {
|
|
||||||
user_model.image = Set(Some(self.cloaked(image)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Set(Some(ref icon)) = user_model.icon {
|
|
||||||
if !icon.starts_with(self.base()) {
|
|
||||||
user_model.icon = Set(Some(self.cloaked(icon)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO this may fail: while fetching, remote server may fetch our service actor.
|
// TODO this may fail: while fetching, remote server may fetch our service actor.
|
||||||
// if it does so with http signature, we will fetch that actor in background
|
// if it does so with http signature, we will fetch that actor in background
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use apb::{target::Addressed, Activity, Base, Object};
|
use apb::{target::Addressed, Activity, Base, Object};
|
||||||
use sea_orm::{sea_query::Expr, ActiveModelTrait, ActiveValue::{NotSet, Set}, ColumnTrait, Condition, DatabaseTransaction, EntityTrait, QueryFilter, QuerySelect, SelectColumns};
|
use sea_orm::{sea_query::Expr, ActiveModelTrait, ActiveValue::{NotSet, Set}, ColumnTrait, Condition, DatabaseTransaction, EntityTrait, QueryFilter, QuerySelect, SelectColumns};
|
||||||
use crate::{ext::{AnyQuery, LoggableError}, model, traits::{fetch::Pull, Addresser, Cloaker, Fetcher, Normalizer}};
|
use crate::{ext::{AnyQuery, LoggableError}, model, traits::{fetch::Pull, Addresser, Fetcher, Normalizer}};
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum ProcessorError {
|
pub enum ProcessorError {
|
||||||
|
@ -368,17 +368,6 @@ pub async fn update(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat
|
||||||
.await?
|
.await?
|
||||||
.ok_or(ProcessorError::Incomplete)?;
|
.ok_or(ProcessorError::Incomplete)?;
|
||||||
let mut actor_model = crate::AP::actor_q(object_node.as_actor()?, Some(internal_uid))?;
|
let mut actor_model = crate::AP::actor_q(object_node.as_actor()?, Some(internal_uid))?;
|
||||||
if let Set(Some(ref image)) = actor_model.image {
|
|
||||||
if !image.starts_with(ctx.base()) {
|
|
||||||
actor_model.image = Set(Some(ctx.cloaked(image)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Set(Some(ref icon)) = actor_model.icon {
|
|
||||||
if !icon.starts_with(ctx.base()) {
|
|
||||||
actor_model.icon = Set(Some(ctx.cloaked(icon)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
actor_model.updated = Set(chrono::Utc::now());
|
actor_model.updated = Set(chrono::Utc::now());
|
||||||
actor_model.update(tx).await?;
|
actor_model.update(tx).await?;
|
||||||
},
|
},
|
||||||
|
@ -387,9 +376,6 @@ pub async fn update(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat
|
||||||
.await?
|
.await?
|
||||||
.ok_or(ProcessorError::Incomplete)?;
|
.ok_or(ProcessorError::Incomplete)?;
|
||||||
let mut object_model = crate::AP::object_q(&object_node, Some(internal_oid))?;
|
let mut object_model = crate::AP::object_q(&object_node, Some(internal_oid))?;
|
||||||
if let Set(Some(ref content)) = object_model.content {
|
|
||||||
object_model.content = Set(Some(ctx.sanitize(content)));
|
|
||||||
}
|
|
||||||
object_model.context = NotSet; // TODO dont overwrite context when updating!!
|
object_model.context = NotSet; // TODO dont overwrite context when updating!!
|
||||||
object_model.updated = Set(chrono::Utc::now());
|
object_model.updated = Set(chrono::Utc::now());
|
||||||
object_model.update(tx).await?;
|
object_model.update(tx).await?;
|
||||||
|
|
Loading…
Reference in a new issue