ptpb / pb

pb is a formerly-lightweight pastebin and url shortener
Other
549 stars 52 forks source link

Remove already created vanity pastes #232

Closed wilful closed 5 years ago

wilful commented 5 years ago

How to remove vanity pastes without UUID or how to get UUID from created pastes?

# echo HelloWorld | curl -F c=@- http://DOMAIN/~testing
date: 2018-09-25T19:26:40.001844+00:00
digest: bc9faaae1e35d52f3dea9651da12cd36627b8403
label: ~testing
long: ALyfqq4eNdUvPeqWUdoSzTZie4QD
short: e4QD
size: 11
status: created
url: http://DOMAIN/~testing
uuid: e4956276-89fe-4e64-9810-ff2e870bd38f

# curl -X DELETE http://DOMAIN/~testing
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>405 Method Not Allowed</title>
<h1>Method Not Allowed</h1>
<p>The method is not allowed for the requested URL.</p>

# curl -X DELETE http://DOMAIN/e4956276-89fe-4e64-9810-ff2e870bd38f
date: 2018-09-25T19:26:40.001000+00:00
digest: bc9faaae1e35d52f3dea9651da12cd36627b8403
label: ~testing
long: ALyfqq4eNdUvPeqWUdoSzTZie4QD
short: e4QD
size: 11
status: deleted
url: http://DOMAIN/~testing

PS: Great work, i very liked it app

buhman commented 5 years ago

How to remove vanity pastes without UUID how to get UUID from created pastes?

You (as an API user) can't. This is intentional.

UUID is intended to be known only by the paste creator, which is why it is only revealed once during paste creation, and is also why all mutation operations require it (and all non-mutation operations do not).

no really, how do I do it

As implied by DOMAIN, if you're deploying your own pb instance, you can use the underdocumented pb-delete tool (an entrypoint defined in setup.cfg). This requires direct access to the database/configuration file.

You can also see read how this works (not really magic, just direct model manipulation): https://github.com/ptpb/pb/blob/master/pb/tools/delete.py

In your case, you could invoke like this:

pb-delete --endpoint http://DOMAIN ~testing
buhman commented 5 years ago

If for your own deployment, you'd rather a more "open" system where everyone can do anything, you can easily hack the behavior you're implying by replacing this line as follows:

https://github.com/ptpb/pb/blob/master/pb/paste/views.py#L223

-return PasteResponse(paste, "found")
+return PasteResponse(paste, "found", uuid=str(UUID(hex=paste['_id'])))

You would then call this with endpoint with:

curl -X REPORT http://DOMAIN/~testing
wilful commented 5 years ago

Thanks for the help. This will be enough for my purposes.

A small question: how would you advise doing a database cleanup? In my configuration, PB will receive 10-20 requests per minute, and after a while the database will be full.

buhman commented 5 years ago

how would you advise doing a database cleanup

If you mean "delete all pastes", that would be:

db.pastes.remove({});

In the mongo shell, making sure to select your database (probably called pb unless you changed that).

You can also .drop(), which is faster, but would require you re-run runonce.