1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 15:09:14 +00:00

add mime type for file

This commit is contained in:
poet
2012-07-25 10:40:14 +08:00
parent 3d76051a05
commit 10d462dc63
2 changed files with 433 additions and 0 deletions

View File

@@ -30,9 +30,14 @@ from auth.forms import AuthenticationForm
from auth import login as auth_login
from django.views.decorators.csrf import csrf_exempt
from mime import MIME_MAP
json_content_type = 'application/json; charset=utf-8'
def get_file_mime(name):
sufix = os.path.splitext(name)[1][1:]
return MIME_MAP[sufix]
def calculate_repo_info(repo_list, username):
"""
Get some info for repo.
@@ -90,6 +95,10 @@ def get_dir_entrys_by_path(reqquest, commit, path):
if stat.S_ISDIR(dirent.props.mode):
dtype = "dir"
else:
mime = get_file_mime (dirent.obj_name)
if mime:
entry["mime"] = mime
try:
entry["size"] = seafserv_threaded_rpc.get_file_size(dirent.obj_id)
except:
@@ -113,6 +122,9 @@ def get_dir_entrys_by_id(reqquest, dir_id):
if stat.S_ISDIR(dirent.props.mode):
dtype = "dir"
else:
mime = get_file_mime (dirent.obj_name)
if mime:
entry["mime"] = mime
try:
entry["size"] = seafserv_threaded_rpc.get_file_size(dirent.obj_id)
except Exception, e: