diff --git a/thoughts/models.py b/thoughts/models.py index 830549d..e2fd36f 100644 --- a/thoughts/models.py +++ b/thoughts/models.py @@ -55,7 +55,8 @@ ALLOWED_MEDIA_TYPES = { "image/png": "png", "image/jpeg": "jpeg", "audio/x-m4a": "m4a", - "audio/mp3": "mp3", + "audio/mpegaudio/mpeg": "mp3", + "audio/x-hx-aac-adts": "aac", "video/mp4": "mp4", "video/quicktime": "mov", } diff --git a/thoughts/views.py b/thoughts/views.py index 5f1de0f..507f4c6 100644 --- a/thoughts/views.py +++ b/thoughts/views.py @@ -134,7 +134,7 @@ def post(request): thought.media.name = f"{thought.uuid}.{ALLOWED_MEDIA_TYPES[media_type]}" - if media_type == "audio/x-m4a": + if media_type == "audio/x-m4a" or media_type == "audio/x-hx-aac-adts": # This is a hack-fix because I want to be able to upload audio # In the future, this should be refactored to convert file types # using ffmpeg.js on the client side (so there are 0 security concerns) @@ -142,11 +142,11 @@ def post(request): thought.save() # Save so that we have a file to work with subprocess.run(["ffmpeg", "-i", thought.media.path, - "-codec:a", "aac", "-vn", - os.path.join(settings.MEDIA_ROOT, f"{thought.uuid}.aac") + "-codec:a", "mp3", "-vn", + os.path.join(settings.MEDIA_ROOT, f"{thought.uuid}.mp3") ], check=True) - os.remove(os.path.join(settings.MEDIA_ROOT, f"{thought.uuid}.m4a")) # Remove the original file - thought.media.name = f"{thought.uuid}.aac" # Update the file in the DB + os.remove(os.path.join(settings.MEDIA_ROOT, thought.media.name)) # Remove the original file + thought.media.name = f"{thought.uuid}.mp3" # Update the file in the DB # We need to make sure that if we remove an image, the alt text is removed with it if not thought.media: