fix: ensure privacy policy read only if path exists

Moved path file opening and reading logic inside a conditional block to prevent attempts to access a file when no valid path is assigned. This avoids potential errors and ensures only existing files are processed.
This commit is contained in:
Kumi 2024-10-04 15:23:59 +02:00
parent 065738eea2
commit 7682f4ba7f
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -357,17 +357,16 @@ def init_main_routes(app):
elif pathlib.Path("privacy.txt").exists(): elif pathlib.Path("privacy.txt").exists():
path = "privacy.txt" path = "privacy.txt"
try: if path:
with pathlib.Path(path).open() as f: try:
content = f.read() with pathlib.Path(path).open() as f:
content = f.read()
print(path, content) if path.endswith(".md"):
content = Markdown().convert(content)
if path.endswith(".md"): except OSError:
content = Markdown().convert(content) pass
except OSError:
pass
return render_template( return render_template(
"privacypolicy.html", title="Privacy Policy", content=content "privacypolicy.html", title="Privacy Policy", content=content