From 6e168a54ecc9f20110faaa6884ca87ecc1b98128 Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Tue, 15 May 2018 19:01:49 +0200
Subject: [PATCH] Fix #204: missing dot when downloading file

---
 api/funkwhale_api/music/models.py | 2 +-
 api/funkwhale_api/music/views.py  | 5 ++++-
 api/tests/music/test_models.py    | 8 ++++++++
 changes/changelog.d/204.bugfix    | 1 +
 4 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 changes/changelog.d/204.bugfix

diff --git a/api/funkwhale_api/music/models.py b/api/funkwhale_api/music/models.py
index 5ee5d851d..64c6e9913 100644
--- a/api/funkwhale_api/music/models.py
+++ b/api/funkwhale_api/music/models.py
@@ -467,7 +467,7 @@ class TrackFile(models.Model):
 
     @property
     def filename(self):
-        return '{}{}'.format(
+        return '{}.{}'.format(
             self.track.full_name,
             self.extension)
 
diff --git a/api/funkwhale_api/music/views.py b/api/funkwhale_api/music/views.py
index b104bf389..f06f86f1d 100644
--- a/api/funkwhale_api/music/views.py
+++ b/api/funkwhale_api/music/views.py
@@ -275,7 +275,10 @@ def handle_serve(track_file):
         file_path = get_file_path(audio_file)
     elif f.source and f.source.startswith('file://'):
         file_path = get_file_path(f.source.replace('file://', '', 1))
-    response = Response()
+    if mt:
+        response = Response(content_type=mt)
+    else:
+        response = Response()
     filename = f.filename
     mapping = {
         'nginx': 'X-Accel-Redirect',
diff --git a/api/tests/music/test_models.py b/api/tests/music/test_models.py
index 9f52ba887..d76c09a01 100644
--- a/api/tests/music/test_models.py
+++ b/api/tests/music/test_models.py
@@ -77,3 +77,11 @@ def test_audio_track_mime_type(extention, mimetype, factories):
     tf = factories['music.TrackFile'](audio_file__from_path=path)
 
     assert tf.mimetype == mimetype
+
+
+def test_track_file_file_name(factories):
+    name = 'test.mp3'
+    path = os.path.join(DATA_DIR, name)
+    tf = factories['music.TrackFile'](audio_file__from_path=path)
+
+    assert tf.filename == tf.track.full_name + '.mp3'
diff --git a/changes/changelog.d/204.bugfix b/changes/changelog.d/204.bugfix
new file mode 100644
index 000000000..370f1d837
--- /dev/null
+++ b/changes/changelog.d/204.bugfix
@@ -0,0 +1 @@
+Fixed missing dot when downloading file (#204)
-- 
GitLab