mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-17 07:41:26 +00:00
[api] handle the situation when mime type does not exist in the MIME_MAP
This commit is contained in:
16
api/mime.py
16
api/mime.py
@@ -414,18 +414,20 @@ zip application/zip
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
MIME_MAP = {}
|
MIME_MAP = {}
|
||||||
|
|
||||||
for line in mime_str.splitlines():
|
for line in mime_str.splitlines():
|
||||||
pair = line.split()
|
pair = line.split()
|
||||||
if len(pair) == 2:
|
if len(pair) == 2:
|
||||||
MIME_MAP[pair[0]] = pair[1]
|
MIME_MAP[pair[0]] = pair[1]
|
||||||
|
|
||||||
|
|
||||||
def get_file_mime(name):
|
def get_file_mime(name):
|
||||||
sufix = os.path.splitext(name)[1][1:]
|
try:
|
||||||
if sufix:
|
sufix = os.path.splitext(name)[1][1:]
|
||||||
return MIME_MAP[sufix]
|
if sufix:
|
||||||
return None
|
return MIME_MAP[sufix]
|
||||||
|
return None
|
||||||
|
except Exception, e:
|
||||||
|
return None
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print MIME_MAP
|
print MIME_MAP
|
||||||
|
Reference in New Issue
Block a user