mirror of
https://gitlab.com/octospacc/TelegramIndex-Fork.git
synced 2025-06-05 22:09:12 +02:00
🚸 Generate consistent aliases using hashes
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
|
import base64
|
||||||
|
import hashlib
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
|
||||||
|
from ..config import SHORT_URL_LEN
|
||||||
|
|
||||||
from .home_view import HomeView
|
from .home_view import HomeView
|
||||||
from .wildcard_view import WildcardView
|
from .wildcard_view import WildcardView
|
||||||
from .download import Download
|
from .download import Download
|
||||||
@@ -13,6 +17,7 @@ from .logout_view import LogoutView
|
|||||||
from .middlewhere import middleware_factory
|
from .middlewhere import middleware_factory
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Views(
|
class Views(
|
||||||
HomeView,
|
HomeView,
|
||||||
Download,
|
Download,
|
||||||
@@ -33,12 +38,15 @@ class Views(
|
|||||||
chat_id = chat.id
|
chat_id = chat.id
|
||||||
title = chat.title
|
title = chat.title
|
||||||
while True:
|
while True:
|
||||||
alias_id = "".join(
|
# alias_id = "".join(
|
||||||
[
|
# [
|
||||||
random.choice(string.ascii_letters + string.digits)
|
# random.choice(string.ascii_letters + string.digits)
|
||||||
for _ in range(len(str(chat_id)))
|
# 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:
|
if alias_id in self.chat_ids:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user