fix: oops not yet stable if let &&

This commit is contained in:
əlemi 2024-07-16 00:52:25 +02:00
parent b88c13e587
commit af5f5e2554
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 17 additions and 8 deletions

View file

@ -1,12 +1,12 @@
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::{NotSet, Set, Unchanged}, ColumnTrait, Condition, EntityTrait, IntoActiveModel, QueryFilter, QuerySelect, SelectColumns};
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, actors: bool) -> Result<(), RequestError> {
let local_base = format!("{}%", ctx.base())); 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(&local_base))
.stream(ctx.db()) .stream(ctx.db())
.await?; .await?;
@ -60,13 +60,22 @@ pub async fn cloak(ctx: upub::Context, post_contents: bool, actors: bool) -> Res
while let Some((internal, image, icon)) = stream.try_next().await? { while let Some((internal, image, icon)) = stream.try_next().await? {
if image.is_none() && icon.is_none() { continue } if image.is_none() && icon.is_none() { continue }
let image = if let Some(img) = image && !img.starts_with(ctx.base()) { // TODO can this if/else/else be made nicer??
Set(ctx.cloaked(&img)) let image = if let Some(img) = image {
if !img.starts_with(ctx.base()) {
Set(Some(ctx.cloaked(&img)))
} else {
NotSet
}
} else { } else {
NotSet NotSet
}; };
let icon = if let Some(icn) = icon && !icn.starts_with(ctx.base()) { let icon = if let Some(icn) = icon {
Set(ctx.cloaked(&icn)) if !icn.starts_with(ctx.base()) {
Set(Some(ctx.cloaked(&icn)))
} else {
NotSet
}
} else { } else {
NotSet NotSet
}; };

View file

@ -2,7 +2,7 @@ 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, ActiveValue::Set};
use crate::traits::normalize::AP; use crate::traits::normalize::AP;