Closed g-rock84 closed 1 year ago
Look at the new /view/
As for the length of the uuid, i tend to agree but i made changes to my private repo to reflect. I did 5 characters in mine and was thinking of reducing it to 3 since my pastebin is just for me. If there is interest i could make a patch that minimizes the url length.
This is what I went with
id_len = int(math.ceil( 2*math.log(len(listdir(config.data_directory))+2)/math.log(256) )) unique_id = secrets.token_urlsafe(id_len)
The mathematics of this are to calculate the number of digits (in bytes) needed to represent the square of the number of current entries in the pastebin. (+2 to avoid an edge case at 0 and 1.) The secrets.token_url is probably overkill for randomness, but works quite well to make a base64-encoded string of that number of bytes. The square of the number is used because that is a measure of unlikeliness of collisions in the namespace. 10 entries will have >100 spots to occupy, etc.
You can see an example of it working here: https://bin.st5ve.com/view/kR4/raw
Should I make a pull request?
This is what I went with
id_len = int(math.ceil( 2*math.log(len(listdir(config.data_directory))+2)/math.log(256) )) unique_id = secrets.token_urlsafe(id_len)
SUPER sorry that it has taken me almost two years to respond! I packed up and moved across several states since this. Anyway, this is pure genius! Way better than my solution. Bravo! I'll finally close this.
Unless pastey can already do this and I just reinvented the wheel big time, I'd like to propose a feature to allow for paste content retrieval from cli. Here are the changes I experimented with:
common.py (line 105)
I replaced uuid.uuid4() with the below function. A UUID is way too much to type in my humble opinion and using a random, six character combination of uppercase/lowercase letters and numbers that gives you 56,800,235,584 possible combinations. It would take you 1,800 years to burn through those if you created a new paste every second. Five characters would still take 31 years. ```python def id_generator(size=6, chars=string.ascii_uppercase + string.digits + string.ascii_lowercase ): return ''.join(random.SystemRandom().choice(chars) for _ in range(size)) ``` [https://github.com/g-rock84/pastey/blob/main/pastey/common.py](https://github.com/g-rock84/pastey/blob/main/pastey/common.py)functions.py (line 82)
```python unique_id = str(common.id_generator()) ``` [https://github.com/g-rock84/pastey/blob/main/pastey/functions.py](https://github.com/g-rock84/pastey/blob/main/pastey/functions.py)routes.py (line 191)
```python @app.route('/content/Thoughts? It could definitely be more polished/efficient/pretty, but it works. I've been using it on my network for a few days now without any issues. Of course, I haven't really given it a full shakedown. I think it is a pretty solid proof of concept if anything.
If this does not fit into what you envision for pastey then I will make sure to clearly indicate the differences between the two.
Either way, thank you for all your hard work. This is an awesome and extremely useful utility!