Merge pull request #1925 from lbryio/fix-extension
fix application/x-ext mime types
This commit is contained in:
commit
ca686041e7
2 changed files with 18 additions and 2 deletions
|
@ -154,5 +154,7 @@ types_map = {
|
||||||
|
|
||||||
def guess_media_type(path):
|
def guess_media_type(path):
|
||||||
_, ext = os.path.splitext(path)
|
_, ext = os.path.splitext(path)
|
||||||
default = f'application/x-ext-{ext}' if ext else 'application/octet-stream'
|
return types_map.get(
|
||||||
return types_map.get(ext, default)
|
ext,
|
||||||
|
'application/octet-stream' if not (ext and ext[1:].strip()) else f'application/x-ext-{ext[1:].strip().lower()}'
|
||||||
|
)
|
||||||
|
|
14
tests/unit/lbrynet_daemon/test_mime_types.py
Normal file
14
tests/unit/lbrynet_daemon/test_mime_types.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import unittest
|
||||||
|
from lbrynet.extras.daemon import mime_types
|
||||||
|
|
||||||
|
|
||||||
|
class TestMimeTypes(unittest.TestCase):
|
||||||
|
def test_mp4_video(self):
|
||||||
|
self.assertEqual("video/mp4", mime_types.guess_media_type("test.mp4"))
|
||||||
|
|
||||||
|
def test_x_ext_(self):
|
||||||
|
self.assertEqual("application/x-ext-lbry", mime_types.guess_media_type("test.lbry"))
|
||||||
|
|
||||||
|
def test_octet_stream(self):
|
||||||
|
self.assertEqual("application/octet-stream", mime_types.guess_media_type("test."))
|
||||||
|
self.assertEqual("application/octet-stream", mime_types.guess_media_type("test"))
|
Loading…
Add table
Reference in a new issue