orhun / rustypaste-cli

A CLI tool for rustypaste
https://github.com/orhun/rustypaste
MIT License
56 stars 8 forks source link

Sending expected file name via parameter to override random_url #82

Closed seqizz closed 7 months ago

seqizz commented 8 months ago

This is the fruit of the discussion #216

Normally users can decide resulting filename by sending filename on multipart request, as long as server does not use random_url

In case #217 is implemented, an extra argument like --file-name could be helpful to override random path result (on servers which explicitly allow overriding the random_url setting). An example:

# normal operation with random_url
$ rpaste imgurdownload.jpg
http://example.com/some-random-string.jpg

# if overriding allowed
$ rpaste --file-name i-dont-know-what-i-expected.jpg imgurdownload.jpg
http://example.com/i-dont-know-what-i-expected.jpg
tessus commented 8 months ago

Such a parameter would also be useful no matter what. Right now it doesn't seem possible to set the filename if random url is not used either. So apparently that was an oversight earlier.

tessus commented 8 months ago

I looked into this, but it seems a bit more complicated than expected.

Firstly, the arguments are not available to the upload function. Thus one either has to refactor quite a bit, or use a workaround and use the Config struct. The latter is easier but makes less sense, since this would also allow people to set it in the config file, which makes no sense at all.

Just for getting ahead quickly, I implemented the workaround, but for some reason setting the header for the request does not work. You can have a look at the code here: https://github.com/tessus/rustypaste-cli/commit/9c33fd18f022259842927e4a509b3ec48ea6aa49

I haven't had the time to debug the request/response via tcpdump.

tessus commented 7 months ago

I was mixing up a few things in my last comment. I was able to code it. I still have to update the README. Will do that tomorrow and then I'll create a PR.