mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-09 19:01:42 +00:00
Use dictionary in file extension and type map.
This commit is contained in:
8
urls.py
8
urls.py
@@ -17,7 +17,7 @@ from seahub.views import root, peers, myhome, \
|
||||
from seahub.notifications.views import notification_list
|
||||
from seahub.share.views import share_admin
|
||||
from seahub.group.views import group_list
|
||||
from seahub.utils import set_file_ext_cache
|
||||
from seahub.utils import gen_fileext_type_map
|
||||
|
||||
# Uncomment the next two lines to enable the admin:
|
||||
#from django.contrib import admin
|
||||
@@ -110,6 +110,6 @@ if settings.DEBUG:
|
||||
(r'^%s/(?P<path>.*)$' % (media_url), 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
|
||||
)
|
||||
|
||||
# Set file extension cache at django startup, this function should be
|
||||
# called only once.
|
||||
set_file_ext_cache()
|
||||
# Add file extension and type to dictionary at django startup,
|
||||
# this function should be called only once.
|
||||
FILEEXT_TYPE_MAP = gen_fileext_type_map()
|
||||
|
23
utils.py
23
utils.py
@@ -24,7 +24,6 @@ PREVIEW_FILEEXT = {
|
||||
'SVG': ('svg',),
|
||||
}
|
||||
|
||||
FILEEXT_PREFIX = 'FILEEXT_'
|
||||
def go_permission_error(request, msg=None):
|
||||
"""
|
||||
Return permisson error page.
|
||||
@@ -238,16 +237,9 @@ def valid_previewed_file(filename):
|
||||
Check whether file can preview on web
|
||||
|
||||
"""
|
||||
from urls import FILEEXT_TYPE_MAP
|
||||
fileExt = os.path.splitext(filename)[1][1:]
|
||||
filetype = cache.get(FILEEXT_PREFIX + fileExt)
|
||||
if filetype:
|
||||
return filetype
|
||||
else:
|
||||
for k in PREVIEW_FILEEXT.keys():
|
||||
if fileExt in PREVIEW_FILEEXT.get(k):
|
||||
cache.set(FILEEXT_PREFIX + fileExt, k)
|
||||
return k
|
||||
return None
|
||||
return FILEEXT_TYPE_MAP.get(fileExt)
|
||||
|
||||
def get_file_revision_id_size (commit_id, path):
|
||||
"""Given a commit and a file path in that commit, return the seafile id
|
||||
@@ -264,13 +256,14 @@ def get_file_revision_id_size (commit_id, path):
|
||||
|
||||
return None, None
|
||||
|
||||
def set_file_ext_cache():
|
||||
def gen_fileext_type_map():
|
||||
"""
|
||||
Put previewed file extension and file type to cache.
|
||||
Generate previewed file extension and file type relation map.
|
||||
|
||||
"""
|
||||
d = {}
|
||||
for filetype in PREVIEW_FILEEXT.keys():
|
||||
for fileext in PREVIEW_FILEEXT.get(filetype):
|
||||
key = FILEEXT_PREFIX + fileext
|
||||
value = filetype
|
||||
cache.set(key, value)
|
||||
d[fileext] = filetype
|
||||
|
||||
return d
|
||||
|
Reference in New Issue
Block a user