From 712d4fbb90766fca9024ae05310e2e522793ab1a Mon Sep 17 00:00:00 2001 From: shanshuirenjia <978987373@qq.com> Date: Wed, 5 Jan 2022 16:36:40 +0800 Subject: [PATCH 1/9] repair code bug --- frontend/src/markdown-editor.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/frontend/src/markdown-editor.js b/frontend/src/markdown-editor.js index 21cce8af61..76c5c233ea 100644 --- a/frontend/src/markdown-editor.js +++ b/frontend/src/markdown-editor.js @@ -734,9 +734,8 @@ class MarkdownEditor extends React.Component { const fileName = Utils.getFileName(filePath); const suffix = fileName.slice(fileName.indexOf('.') + 1); if (IMAGE_SUFFIXES.includes(suffix)) { - seafileAPI.getFileDownloadLink(repoID, filePath).then((res) => { - window.richMarkdownEditor.addLink(fileName, res.data, true); - }); + let innerURL = serviceUrl + '/lib/' + repoID + '/file' + Utils.encodePath(filePath) + '?raw=1'; + window.richMarkdownEditor.addLink(fileName, innerURL, true); return; } let innerURL = serviceUrl + '/lib/' + repoID + '/file' + Utils.encodePath(filePath); From cd44343b980e8a797923c0ce2ae64f6d2d6147ed Mon Sep 17 00:00:00 2001 From: shanshuirenjia <978987373@qq.com> Date: Tue, 18 Jan 2022 17:28:10 +0800 Subject: [PATCH 2/9] repair code bug --- frontend/src/markdown-editor.js | 4 ++-- frontend/src/shared-file-view-markdown.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/markdown-editor.js b/frontend/src/markdown-editor.js index 76c5c233ea..153e855a35 100644 --- a/frontend/src/markdown-editor.js +++ b/frontend/src/markdown-editor.js @@ -26,7 +26,7 @@ const { siteRoot, serviceUrl, seafileCollabServer } = window.app.config; const userInfo = window.app.userInfo; const userName = userInfo.username; let dirPath = Utils.getDirName(filePath); -const IMAGE_SUFFIXES = ['png', 'PNG', 'jpg', 'JPG', 'gif', 'GIF']; +const IMAGE_SUFFIXES = ['png', 'PNG', 'jpg', 'jpeg', 'JPG', 'gif', 'GIF']; function getImageFileNameWithTimestamp() { var d = Date.now(); @@ -734,7 +734,7 @@ class MarkdownEditor extends React.Component { const fileName = Utils.getFileName(filePath); const suffix = fileName.slice(fileName.indexOf('.') + 1); if (IMAGE_SUFFIXES.includes(suffix)) { - let innerURL = serviceUrl + '/lib/' + repoID + '/file' + Utils.encodePath(filePath) + '?raw=1'; + let innerURL = serviceUrl + '/lib/' + repoID + '/file' + filePath + '?raw=1'; window.richMarkdownEditor.addLink(fileName, innerURL, true); return; } diff --git a/frontend/src/shared-file-view-markdown.js b/frontend/src/shared-file-view-markdown.js index 3995267b94..2f5f55a7e4 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=' + Utils.encodePath(imagePath); + innerNode.data.src = serviceURL + '/view-image-via-share-link/?token=' + sharedToken + '&path=' + imagePath; } return innerNode; } From 2ae795b5489054f45d8e29c4694747a91250111c Mon Sep 17 00:00:00 2001 From: shanshuirenjia <978987373@qq.com> Date: Tue, 18 Jan 2022 21:29:45 +0800 Subject: [PATCH 3/9] optimize code --- frontend/src/markdown-editor.js | 4 ++-- frontend/src/shared-file-view-markdown.js | 1 + seahub/views/file.py | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/src/markdown-editor.js b/frontend/src/markdown-editor.js index 153e855a35..2a9c0bbf0b 100644 --- a/frontend/src/markdown-editor.js +++ b/frontend/src/markdown-editor.js @@ -26,7 +26,7 @@ const { siteRoot, serviceUrl, seafileCollabServer } = window.app.config; const userInfo = window.app.userInfo; const userName = userInfo.username; let dirPath = Utils.getDirName(filePath); -const IMAGE_SUFFIXES = ['png', 'PNG', 'jpg', 'jpeg', 'JPG', 'gif', 'GIF']; +const IMAGE_SUFFIXES = ['png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'GIF']; function getImageFileNameWithTimestamp() { var d = Date.now(); @@ -734,7 +734,7 @@ class MarkdownEditor extends React.Component { const fileName = Utils.getFileName(filePath); const suffix = fileName.slice(fileName.indexOf('.') + 1); if (IMAGE_SUFFIXES.includes(suffix)) { - let innerURL = serviceUrl + '/lib/' + repoID + '/file' + filePath + '?raw=1'; + let innerURL = serviceUrl + '/lib/' + repoID + '/file' + Utils.encodePath(filePath) + '?raw=1'; window.richMarkdownEditor.addLink(fileName, innerURL, true); return; } diff --git a/frontend/src/shared-file-view-markdown.js b/frontend/src/shared-file-view-markdown.js index 2f5f55a7e4..1d8d259fd6 100644 --- a/frontend/src/shared-file-view-markdown.js +++ b/frontend/src/shared-file-view-markdown.js @@ -55,6 +55,7 @@ class FileContent extends React.Component { let index2 = imagePath.indexOf('?'); imagePath = imagePath.substring(index + 5, index2); // change image url + // the image path has been encoded when inserting the image innerNode.data.src = serviceURL + '/view-image-via-share-link/?token=' + sharedToken + '&path=' + imagePath; } return innerNode; diff --git a/seahub/views/file.py b/seahub/views/file.py index 0190820af4..e76ea8de03 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -5,6 +5,7 @@ File related views, including view_file, view_history_file, view_trash_file, view_snapshot_file, view_shared_file, etc. """ +from asyncio.proactor_events import constants import os import json import time @@ -1972,8 +1973,9 @@ def view_media_file_via_share_link(request): # Translation ‘(’ ')' image_file_name = image_file_name.replace('(', '\(') image_file_name = image_file_name.replace(')', '\)') + encoded_image_file_name = urllib.parse.quote(image_file_name) - p = re.compile('(%s)/lib/(%s)/file(.*?)%s\?raw=1' % (serviceURL, repo_id, image_file_name)) + p = re.compile('(%s)/lib/(%s)/file(.*?)%s\?raw=1' % (serviceURL, repo_id, encoded_image_file_name)) result = re.search(p, file_content) if not result: return render_error(request, 'Image does not exist') From ac713ef815a68a495cd22667b43ebb99447ca60b Mon Sep 17 00:00:00 2001 From: shanshuirenjia <978987373@qq.com> Date: Tue, 18 Jan 2022 21:43:13 +0800 Subject: [PATCH 4/9] fix code --- seahub/views/file.py | 1 - 1 file changed, 1 deletion(-) diff --git a/seahub/views/file.py b/seahub/views/file.py index e76ea8de03..5be38d6efc 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -5,7 +5,6 @@ File related views, including view_file, view_history_file, view_trash_file, view_snapshot_file, view_shared_file, etc. """ -from asyncio.proactor_events import constants import os import json import time From 54004118c63f805f15ef29b8b22235be471623e2 Mon Sep 17 00:00:00 2001 From: Daniel Pan Date: Tue, 18 Jan 2022 22:04:04 +0800 Subject: [PATCH 5/9] Revert "repair code bug" --- frontend/src/markdown-editor.js | 2 +- frontend/src/shared-file-view-markdown.js | 3 +-- seahub/views/file.py | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/frontend/src/markdown-editor.js b/frontend/src/markdown-editor.js index 2a9c0bbf0b..76c5c233ea 100644 --- a/frontend/src/markdown-editor.js +++ b/frontend/src/markdown-editor.js @@ -26,7 +26,7 @@ const { siteRoot, serviceUrl, seafileCollabServer } = window.app.config; const userInfo = window.app.userInfo; const userName = userInfo.username; let dirPath = Utils.getDirName(filePath); -const IMAGE_SUFFIXES = ['png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'GIF']; +const IMAGE_SUFFIXES = ['png', 'PNG', 'jpg', 'JPG', 'gif', 'GIF']; function getImageFileNameWithTimestamp() { var d = Date.now(); diff --git a/frontend/src/shared-file-view-markdown.js b/frontend/src/shared-file-view-markdown.js index 1d8d259fd6..3995267b94 100644 --- a/frontend/src/shared-file-view-markdown.js +++ b/frontend/src/shared-file-view-markdown.js @@ -55,8 +55,7 @@ class FileContent extends React.Component { let index2 = imagePath.indexOf('?'); imagePath = imagePath.substring(index + 5, index2); // change image url - // the image path has been encoded when inserting the image - 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 5be38d6efc..0190820af4 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -1972,9 +1972,8 @@ def view_media_file_via_share_link(request): # Translation ‘(’ ')' image_file_name = image_file_name.replace('(', '\(') image_file_name = image_file_name.replace(')', '\)') - encoded_image_file_name = urllib.parse.quote(image_file_name) - p = re.compile('(%s)/lib/(%s)/file(.*?)%s\?raw=1' % (serviceURL, repo_id, encoded_image_file_name)) + 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') From 9044e283ecd6b864ccf035d80b92453d15340ede Mon Sep 17 00:00:00 2001 From: shanshuirenjia <978987373@qq.com> Date: Tue, 18 Jan 2022 17:28:10 +0800 Subject: [PATCH 6/9] repair code bug --- frontend/src/markdown-editor.js | 4 ++-- frontend/src/shared-file-view-markdown.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/markdown-editor.js b/frontend/src/markdown-editor.js index 76c5c233ea..153e855a35 100644 --- a/frontend/src/markdown-editor.js +++ b/frontend/src/markdown-editor.js @@ -26,7 +26,7 @@ const { siteRoot, serviceUrl, seafileCollabServer } = window.app.config; const userInfo = window.app.userInfo; const userName = userInfo.username; let dirPath = Utils.getDirName(filePath); -const IMAGE_SUFFIXES = ['png', 'PNG', 'jpg', 'JPG', 'gif', 'GIF']; +const IMAGE_SUFFIXES = ['png', 'PNG', 'jpg', 'jpeg', 'JPG', 'gif', 'GIF']; function getImageFileNameWithTimestamp() { var d = Date.now(); @@ -734,7 +734,7 @@ class MarkdownEditor extends React.Component { const fileName = Utils.getFileName(filePath); const suffix = fileName.slice(fileName.indexOf('.') + 1); if (IMAGE_SUFFIXES.includes(suffix)) { - let innerURL = serviceUrl + '/lib/' + repoID + '/file' + Utils.encodePath(filePath) + '?raw=1'; + let innerURL = serviceUrl + '/lib/' + repoID + '/file' + filePath + '?raw=1'; window.richMarkdownEditor.addLink(fileName, innerURL, true); return; } diff --git a/frontend/src/shared-file-view-markdown.js b/frontend/src/shared-file-view-markdown.js index 3995267b94..2f5f55a7e4 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=' + Utils.encodePath(imagePath); + innerNode.data.src = serviceURL + '/view-image-via-share-link/?token=' + sharedToken + '&path=' + imagePath; } return innerNode; } From 935f3d71e8df25698f1dfb1d708f999237f269a2 Mon Sep 17 00:00:00 2001 From: shanshuirenjia <978987373@qq.com> Date: Tue, 18 Jan 2022 21:29:45 +0800 Subject: [PATCH 7/9] optimize code --- frontend/src/markdown-editor.js | 4 ++-- frontend/src/shared-file-view-markdown.js | 1 + seahub/views/file.py | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/src/markdown-editor.js b/frontend/src/markdown-editor.js index 153e855a35..2a9c0bbf0b 100644 --- a/frontend/src/markdown-editor.js +++ b/frontend/src/markdown-editor.js @@ -26,7 +26,7 @@ const { siteRoot, serviceUrl, seafileCollabServer } = window.app.config; const userInfo = window.app.userInfo; const userName = userInfo.username; let dirPath = Utils.getDirName(filePath); -const IMAGE_SUFFIXES = ['png', 'PNG', 'jpg', 'jpeg', 'JPG', 'gif', 'GIF']; +const IMAGE_SUFFIXES = ['png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'GIF']; function getImageFileNameWithTimestamp() { var d = Date.now(); @@ -734,7 +734,7 @@ class MarkdownEditor extends React.Component { const fileName = Utils.getFileName(filePath); const suffix = fileName.slice(fileName.indexOf('.') + 1); if (IMAGE_SUFFIXES.includes(suffix)) { - let innerURL = serviceUrl + '/lib/' + repoID + '/file' + filePath + '?raw=1'; + let innerURL = serviceUrl + '/lib/' + repoID + '/file' + Utils.encodePath(filePath) + '?raw=1'; window.richMarkdownEditor.addLink(fileName, innerURL, true); return; } diff --git a/frontend/src/shared-file-view-markdown.js b/frontend/src/shared-file-view-markdown.js index 2f5f55a7e4..1d8d259fd6 100644 --- a/frontend/src/shared-file-view-markdown.js +++ b/frontend/src/shared-file-view-markdown.js @@ -55,6 +55,7 @@ class FileContent extends React.Component { let index2 = imagePath.indexOf('?'); imagePath = imagePath.substring(index + 5, index2); // change image url + // the image path has been encoded when inserting the image innerNode.data.src = serviceURL + '/view-image-via-share-link/?token=' + sharedToken + '&path=' + imagePath; } return innerNode; diff --git a/seahub/views/file.py b/seahub/views/file.py index 0190820af4..e76ea8de03 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -5,6 +5,7 @@ File related views, including view_file, view_history_file, view_trash_file, view_snapshot_file, view_shared_file, etc. """ +from asyncio.proactor_events import constants import os import json import time @@ -1972,8 +1973,9 @@ def view_media_file_via_share_link(request): # Translation ‘(’ ')' image_file_name = image_file_name.replace('(', '\(') image_file_name = image_file_name.replace(')', '\)') + encoded_image_file_name = urllib.parse.quote(image_file_name) - p = re.compile('(%s)/lib/(%s)/file(.*?)%s\?raw=1' % (serviceURL, repo_id, image_file_name)) + p = re.compile('(%s)/lib/(%s)/file(.*?)%s\?raw=1' % (serviceURL, repo_id, encoded_image_file_name)) result = re.search(p, file_content) if not result: return render_error(request, 'Image does not exist') From baf51c8e6f02c8a183657f1109fa437c06f357b1 Mon Sep 17 00:00:00 2001 From: shanshuirenjia <978987373@qq.com> Date: Tue, 18 Jan 2022 21:43:13 +0800 Subject: [PATCH 8/9] fix code --- seahub/views/file.py | 1 - 1 file changed, 1 deletion(-) diff --git a/seahub/views/file.py b/seahub/views/file.py index e76ea8de03..5be38d6efc 100644 --- a/seahub/views/file.py +++ b/seahub/views/file.py @@ -5,7 +5,6 @@ File related views, including view_file, view_history_file, view_trash_file, view_snapshot_file, view_shared_file, etc. """ -from asyncio.proactor_events import constants import os import json import time From 87a9bf4d785f3015a9b99202461521f6466d39f8 Mon Sep 17 00:00:00 2001 From: lian Date: Sat, 8 Jan 2022 17:14:53 +0800 Subject: [PATCH 9/9] update test-requirements.txt add selenium --- test-requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test-requirements.txt b/test-requirements.txt index 5a79b0bdbe..3e88a07350 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -6,3 +6,4 @@ exam splinter pytest pytest-django +selenium