From e9dd31372ea6207cd0d9be4f60d1e4a7641fece9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E9=A1=BA=E5=BC=BA?= Date: Wed, 22 Apr 2020 20:46:19 +0800 Subject: [PATCH] repair share file image bug (#4543) --- frontend/src/shared-file-view-markdown.js | 2 +- seahub/views/file.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/src/shared-file-view-markdown.js b/frontend/src/shared-file-view-markdown.js index 206da3b8d2..7a502bf374 100644 --- a/frontend/src/shared-file-view-markdown.js +++ b/frontend/src/shared-file-view-markdown.js @@ -55,7 +55,7 @@ class FileContent extends React.Component { let index2 = imagePath.indexOf('?'); imagePath = imagePath.substring(index + 5, index2); // change image url - innerNode.data.src = serviceURL + '/view-image-via-share-link/?token=' + sharedToken + '&path=' + imagePath; + innerNode.data.src = serviceURL + '/view-image-via-share-link/?token=' + sharedToken + '&path=' + Utils.encodePath(imagePath); } return innerNode; } diff --git a/seahub/views/file.py b/seahub/views/file.py index 56ed842903..4ffb32cbdd 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -1967,14 +1967,18 @@ def view_media_file_via_share_link(request): # If the image does not exist in markdown serviceURL = get_service_url().rstrip('/') image_file_name = os.path.basename(image_path) - image_file_name = urlquote(image_file_name) + + # Translation ‘(’ ')' + image_file_name = image_file_name.replace('(', '\(') + image_file_name = image_file_name.replace(')', '\)') + p = re.compile('(%s)/lib/(%s)/file(.*?)%s\?raw=1' % (serviceURL, repo_id, image_file_name)) result = re.search(p, file_content) if not result: return render_error(request, 'Image does not exist') # get image - obj_id = seafile_api.get_file_id_by_path(repo_id, image_path) + obj_id = seafile_api.get_file_id_by_path(repo_id, urllib2.unquote(image_path)) if not obj_id: return render_error(request, 'Image does not exist')