mirror of
https://gitlab.com/octospacc/TelegramIndex-Fork.git
synced 2025-02-17 20:10:42 +01:00
🩹 add alias duplication avoiding logic
This commit is contained in:
parent
6799af0572
commit
d067faed7b
@ -37,12 +37,14 @@ class Views(
|
|||||||
def generate_alias_id(self, chat):
|
def generate_alias_id(self, chat):
|
||||||
chat_id = chat.id
|
chat_id = chat.id
|
||||||
title = chat.title
|
title = chat.title
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
orig_id = f"{title}{chat_id}" # the original id
|
orig_id = f"{chat_id}" # the original id
|
||||||
alias_id = base64.urlsafe_b64encode(hashlib.md5(orig_id.encode()).digest())[:self.url_len].decode()
|
unique_hash = hashlib.md5(orig_id.encode()).digest()
|
||||||
|
alias_id = base64.urlsafe_b64encode(unique_hash).decode()[:self.url_len]
|
||||||
|
|
||||||
if alias_id in self.chat_ids:
|
if alias_id in self.chat_ids:
|
||||||
self.url_len += 1 # increment url_len just incase the hash is already used.
|
self.url_len += 1 # increment url_len just incase the hash is already used.
|
||||||
continue
|
continue
|
||||||
elif (self.url_len > SHORT_URL_LEN): # reset url_len to initial if hash was unique.
|
elif (self.url_len > SHORT_URL_LEN): # reset url_len to initial if hash was unique.
|
||||||
self.url_len = SHORT_URL_LEN
|
self.url_len = SHORT_URL_LEN
|
||||||
|
Loading…
x
Reference in New Issue
Block a user