Bug fix on too long vCard file name

This commit is contained in:
KnugiHK
2023-05-17 01:06:31 +08:00
parent 3bd6f288ea
commit b1d8d173a2
2 changed files with 4 additions and 2 deletions

View File

@@ -489,7 +489,8 @@ def vcard(db, data):
for index, row in enumerate(rows):
media_name = row["media_name"] if row["media_name"] is not None else ""
file_name = "".join(x for x in media_name if x.isalnum())
file_path = f"{base}/{file_name}.vcf"
file_name = file_name.encode('utf-8')[:251].decode('utf-8', 'ignore')
file_path = os.path.join(base, f"{file_name}.vcf")
if not os.path.isfile(file_path):
with open(file_path, "w", encoding="utf-8") as f:
f.write(row["vcard"])

View File

@@ -199,7 +199,8 @@ def vcard(db, data):
Path(base).mkdir(parents=True, exist_ok=True)
for index, row in enumerate(rows):
file_name = "".join(x for x in row[3] if x.isalnum())
file_path = f"{base}/{file_name[:200]}.vcf"
file_name = file_name.encode('utf-8')[:251].decode('utf-8', 'ignore')
file_path = os.path.join(base, f"{file_name}.vcf")
if not os.path.isfile(file_path):
with open(file_path, "w", encoding="utf-8") as f:
f.write(row[4])