From c567a8cab6bb8724631068f07e3cc38a19be598d Mon Sep 17 00:00:00 2001 From: lian Date: Fri, 6 Aug 2021 11:53:58 +0800 Subject: [PATCH] use sha1 encrypted str as cache key --- seahub/onlyoffice/utils.py | 7 +++---- seahub/utils/__init__.py | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/seahub/onlyoffice/utils.py b/seahub/onlyoffice/utils.py index 8054c2e719..e071965bce 100644 --- a/seahub/onlyoffice/utils.py +++ b/seahub/onlyoffice/utils.py @@ -13,7 +13,7 @@ from seaserv import seafile_api from seahub.base.templatetags.seahub_tags import email2nickname from seahub.utils import get_file_type_and_ext, gen_file_get_url, \ - get_site_scheme_and_netloc, normalize_cache_key + get_site_scheme_and_netloc, encrypt_with_sha1 from seahub.utils.file_op import if_locked_by_online_office from seahub.settings import ENABLE_WATERMARK @@ -25,9 +25,8 @@ logger = logging.getLogger('onlyoffice') def generate_onlyoffice_cache_key(repo_id, file_path): - prefix = "ONLYOFFICE_" - value = "%s_%s" % (repo_id, file_path) - return normalize_cache_key(value, prefix) + + return "ONLYOFFICE_{}_{}".format(repo_id, encrypt_with_sha1(file_path)) def get_onlyoffice_dict(request, username, repo_id, file_path, file_id='', diff --git a/seahub/utils/__init__.py b/seahub/utils/__init__.py index 46be5789f8..4bb58705fe 100644 --- a/seahub/utils/__init__.py +++ b/seahub/utils/__init__.py @@ -1387,3 +1387,8 @@ def is_valid_org_id(org_id): return True else: return False + + +def encrypt_with_sha1(origin_str): + + return hashlib.sha1(origin_str.encode()).hexdigest()