allow text and application uploads (text, md, html, json, etc)

This commit is contained in:
Russell Ballestrini 2025-01-25 11:59:42 +00:00
parent 74fc955f5e
commit 479e77875e

6
app.py
View file

@ -76,6 +76,8 @@ if not os.path.exists(DATA_DIR):
APP_SECRET_FILE = os.path.join(DATA_DIR, "pyrafiles_secret.txt")
JWT_SECRET_FILE = os.path.join(DATA_DIR, "jwt_secret.txt")
ALLOWED_MIME_PREFIXES = ("image/", "audio/", "video/", "text/", "application/")
def get_or_create_secret(env_var_name, secret_file_path):
"""
@ -1176,7 +1178,7 @@ def upload_media_post_view(request):
# Determine media type based on MIME type
filename = media_file.filename
mime_type = get_mime_type(filename)
if not mime_type.startswith(("image/", "audio/", "video/")):
if not mime_type.startswith(ALLOWED_MIME_PREFIXES):
return Response("Unsupported media type.", status=400)
media_type = mime_type.split("/")[0]
@ -1330,7 +1332,7 @@ def edit_media_post_view(request):
file_size = len(raw_bytes)
filename = new_media_file.filename
mime_type = get_mime_type(filename)
if not mime_type.startswith(("image/", "audio/", "video/")):
if not mime_type.startswith(ALLOWED_MIME_PREFIXES):
return Response("Unsupported media type.", status=400)
media_type = mime_type.split("/")[0]
encoded_str = base64.b64encode(raw_bytes).decode("utf-8")