mkaczanowski / pastebin

Simple, fast, standalone pastebin service
MIT License
155 stars 27 forks source link

[Feature Request] Configure Pastebin URL slug length through CLI args #5

Closed acherunilam closed 3 years ago

acherunilam commented 3 years ago

nanoid supports generating an ID of a certain length, all you have to do is pass the length as an argument. Can we have this? We can pass the slug length as a CLI arg to pastebin.

This does bring in additional complexity in the form of potential namespace collisions, so we might want to generate a new ID until we avoid collision, and in the edge case that the whole namespace is exhausted, fail to create a paste.

mkaczanowski commented 3 years ago

Hey @acherunilam,

sounds good (y)

mkaczanowski commented 3 years ago

The '-slug-len' is now available, but there is no namespace collision check yet (#6)

mkaczanowski commented 3 years ago

I am closing this issue, though I think that once the Transactions support lands: https://github.com/rust-rocksdb/rust-rocksdb/pull/250

I'll use the transaction mechanism as the protection against key collision

acherunilam commented 3 years ago

@mkaczanowski Shall we fail to start the app up front in the off chance that a user mistakenly specifies a slug length of zero?

$ cargo build

# validation works as expected, application fails fast
$ ./target/debug/pastebin --slug-len=-1
error: Invalid value for '--slug-len <slug-len>': invalid digit found in string

# whoops, app starts and gets stuck after getting the first request instead of failing up front
$ ./target/debug/pastebin --slug-len=0
...
🚀 Rocket has launched from http://localhost:8000
$ echo "hello World $RANDOM" | curl -q -L -d @- -o - http://localhost:8000/
# both server and client are stuck doing the POST request
mkaczanowski commented 3 years ago

I assumed people would know what they're doing (ie. setup slug len to be above 0). But one extra check at the startup doesn't hurt anyone, so I'll add this as well