1
0
Fork 0
mirror of synced 2024-06-26 18:10:26 +12:00

Use regex to strip id

This commit is contained in:
Ali Parlakci 2021-03-27 19:31:34 +03:00
parent 7a436d0481
commit a32dd6d0fe

View file

@ -62,7 +62,7 @@ class FileNameFormatter:
def _limit_file_name_length(filename: str, ending: str) -> str:
possible_id = re.search(r'((?:_\w{6})?$)', filename).group(1)
ending = possible_id + ending
filename = filename.strip(possible_id)
filename = re.sub(rf"^{possible_id}|{possible_id}$", "", filename)
max_length_chars = 255 - len(ending)
max_length_bytes = 255 - len(ending.encode('utf-8'))
while len(filename) > max_length_chars or len(filename.encode('utf-8')) > max_length_bytes: