🚸 Generate consistent aliases using hashes
This commit is contained in:
parent
dc5988ce8d
commit
80da16a880
|
@ -1,6 +1,10 @@
|
|||
import base64
|
||||
import hashlib
|
||||
import random
|
||||
import string
|
||||
|
||||
from ..config import SHORT_URL_LEN
|
||||
|
||||
from .home_view import HomeView
|
||||
from .wildcard_view import WildcardView
|
||||
from .download import Download
|
||||
|
@ -13,6 +17,7 @@ from .logout_view import LogoutView
|
|||
from .middlewhere import middleware_factory
|
||||
|
||||
|
||||
|
||||
class Views(
|
||||
HomeView,
|
||||
Download,
|
||||
|
@ -33,12 +38,15 @@ class Views(
|
|||
chat_id = chat.id
|
||||
title = chat.title
|
||||
while True:
|
||||
alias_id = "".join(
|
||||
[
|
||||
random.choice(string.ascii_letters + string.digits)
|
||||
for _ in range(len(str(chat_id)))
|
||||
]
|
||||
)
|
||||
# alias_id = "".join(
|
||||
# [
|
||||
# random.choice(string.ascii_letters + string.digits)
|
||||
# for _ in range(len(str(chat_id)))
|
||||
# ]
|
||||
# )
|
||||
orig_id = f"{title}{chat_id}" # the original id
|
||||
alias_id = base64.urlsafe_b64encode(hashlib.md5(orig_id.encode()).digest())[:SHORT_URL_LEN].decode()
|
||||
|
||||
if alias_id in self.chat_ids:
|
||||
continue
|
||||
|
||||
|
|
Loading…
Reference in New Issue