Skip to content
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 image deletion endpoint. #5588

Merged
merged 9 commits into from
Apr 7, 2025
Merged

Conversation

dessalines
Copy link
Member

- Also moving the list media endpoints, since these can go under a
  common heading.
- Fixes #5563
.service(
scope("/media")
.route("/list", get().to(list_media))
.route("", delete().to(delete_image)),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user delete image was incorrectly under the admin scope. I moved it here.

)
.route("/proxy", get().to(image_proxy))
.route("/health", get().to(pictrs_health))
.route("/{filename}", get().to(get_image)),
.route("/{filename}", get().to(get_image))
.route("/list_all", get().to(list_all_media)),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just list would be fine?

Copy link
Member

@Nutomic Nutomic Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True the all part is unnecessary, and we may want to add more filters in the future.

@Nutomic
Copy link
Member

Nutomic commented Apr 3, 2025

Needs adjustments to api client.


LocalImage::delete_by_alias(&mut context.pool(), &data.filename).await?;

delete_image_from_pictrs(&data.filename, &context).await?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the admin deletion endpoint, this should branch here depending on whether a purge is desired

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any time its deleted from the DB, it should also be removed from pictrs. Since this one is an explicit call, it should do both, like the one above it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm talking about the difference between purge and delete.
This only deletes the current alias, but depending on the content, admins may want to purge the image, ensuring that it is fully deleted from storage, even if there are other aliases besides the one in the request.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a flag for this, it should just do one or the other. I think purge is better here, since this is an admin / mod action. I'll fix it for this one.

LocalImage::delete_by_alias(&mut context.pool(), &data.filename).await?;

// Use purge, since it should remove any other aliases.
purge_image_from_pictrs(&data.filename, &context).await?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with using purge here, but then we should also delete other aliases for the same image from LocalImage table. Pict-rs does return an array aliases from the purge endpoint.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's impossible, as we don't store anything else. I don't even think pictrs exposes real ids.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POST /internal/purge?alias={alias} Purge a file by it's alias. This removes all aliases and files associated with the query.

Available source arguments are

`?alias={alias}` Purge a file by it's alias
`?proxy={url}` Purge a proxied file by its URL

This endpoint returns the following JSON

{
    "msg": "ok",
    "aliases": ["asdf.png"]
}

The list of aliases can just be matched against the pictrs_alias column in local_image.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, got it.

@dessalines dessalines marked this pull request as draft April 4, 2025 13:14
@dessalines dessalines marked this pull request as ready for review April 4, 2025 13:27
@dessalines dessalines enabled auto-merge (squash) April 7, 2025 19:39
@dessalines dessalines merged commit 2f7ce1c into main Apr 7, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add admin API endpoint to delete or purge images from pict-rs
3 participants