-
-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding admin purging of DB items and pictures. #904 #1331 #1809
Conversation
e9f9d80
to
4d3a210
Compare
- Added pictrs_config block, for API_KEY - Clear out image columns after purging
This is getting close, I just need to build out the front end for it. |
/// Set a custom pictrs API key. ( Required for deleting images ) | ||
#[default("API_KEY")] | ||
#[doku(example = "API_KEY")] | ||
pub api_key: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should put an actual (testing) api key here, to show how it looks. And not specify any default i guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove the default, but I'm not sure what would be better than just API_KEY
as a test.
Once this is merged, in lemmy-ansible, I plan to generate this key in the same way the postgres password is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its not meant to be a test, but an example, so it should look similar to a real value. With API_KEY
, people might think that they need an env var for this.
/// Address where pictrs is available (for image hosting) | ||
#[default("http://pictrs:8080")] | ||
#[doku(example = "http://localhost:8080")] | ||
pub url: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its enough to specify only default in this case.
struct PictrsPurgeParams { | ||
file: Option<String>, | ||
alias: Option<String>, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to make this work a bit more cleanly using enum.
crates/routes/src/images.rs
Outdated
Ok(HttpResponse::build(res.status()).body(BodyStream::new(res.bytes_stream()))) | ||
} | ||
|
||
fn pictrs_config(settings: Settings) -> Result<PictrsConfig, LemmyError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this method into impl settings, and then probably make the member private.
.set(form) | ||
.get_result::<Self>(conn) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to use some macro to generate these crud methods, and avoid all the copy-paste. For example https://github.com/shssoichiro/diesel-derives-extra (but looks unmaintained). Anyway, not necessarily in this pr.
actor.id, | ||
context.pool(), | ||
&context.settings(), | ||
context.client(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, just pass in context. I would start passing in context directly as soon as there are 2 or more params from it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately that'd require lemmy_utils pulling in lemmy_websocket, since that's where LemmyContext
lives.
blocked_person.id, | ||
context.pool(), | ||
&context.settings(), | ||
context.client(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pass in context.
@@ -505,13 +506,99 @@ pub async fn check_private_instance_and_federation_enabled( | |||
Ok(()) | |||
} | |||
|
|||
pub async fn remove_user_data(banned_person_id: PersonId, pool: &DbPool) -> Result<(), LemmyError> { | |||
pub async fn purge_image_posts_for_person( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is already quite big, so please put all the purge/remove related stuff into a new file. Or turn utils into a folder with multiple files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do that in a separate PR, I'll make an issue for it. Utils touches almost every file so that'd make this PR huge.
crates/api_common/src/request.rs
Outdated
"Could not purge Pictrs image with incorrect domain: {}", | ||
image_url.as_str() | ||
))); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this check necessary? If something is wrong, pictrs will return an error on its own. But if someone changes the instance url, this would prevent image purges for no reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're probably right, it's not necessary.
crates/api_common/src/request.rs
Outdated
settings: &Settings, | ||
image_url: &Url, | ||
) -> Result<(), LemmyError> { | ||
if let Some(pictrs_config) = settings.pictrs_config.to_owned() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the pictrs_config function you defined in lemmy_routes (after moving it to lemmy_utils).
|
||
let post_id = comment.post_id; | ||
|
||
// TODO read comments for pictrs images and purge them |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is about inline images in comments, right? And similarly for inline images in post body, community/user profile. Those are generally tricky to manage. Easiest option would be not to permit inline images, otherwise we will have to add some functionality to retrieve them sooner or later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. We could have something that scans through every comment, post body, bio, community sidebar... ( there's probably a few others I'm not thinking of), does a regex search for pictrs URLs, and tries to remove them. IMO that's a little excessive, but it might be necessary later on. I'll just leave that TODO in there to remind us.
crates/api/src/site/mod_log.rs
Outdated
Vec::new(), | ||
Vec::new(), | ||
Vec::new(), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should work with simply Default::Default()
I have the front end for this done also, everything works. |
Actually something in the merge from main broke image uploads, I'm tracing it down. |
@Nutomic This line breaks pictrs functionality. All uploads and such return the error:
I think the only option is for me to create a separate pictrs reqwest client without that middleware. |
Yes it should be pretty straightforward to define a |
I did this in |
No description provided.