From 2d4638eb6b63599568d67a921d1da13f50288a50 Mon Sep 17 00:00:00 2001 From: lian Date: Thu, 6 May 2021 14:46:36 +0800 Subject: [PATCH] check virus when upload file via share link --- seahub/api2/endpoints/share_links.py | 10 ++++++++-- seahub/api2/endpoints/upload_links.py | 14 +++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/seahub/api2/endpoints/share_links.py b/seahub/api2/endpoints/share_links.py index cab76063fc..1fb0db92e9 100644 --- a/seahub/api2/endpoints/share_links.py +++ b/seahub/api2/endpoints/share_links.py @@ -43,7 +43,7 @@ from seahub.settings import SHARE_LINK_EXPIRE_DAYS_MAX, \ SHARE_LINK_EXPIRE_DAYS_MIN, SHARE_LINK_LOGIN_REQUIRED, \ SHARE_LINK_EXPIRE_DAYS_DEFAULT, \ ENABLE_SHARE_LINK_AUDIT, ENABLE_VIDEO_THUMBNAIL, \ - THUMBNAIL_ROOT + THUMBNAIL_ROOT, ENABLE_UPLOAD_LINK_VIRUS_CHECK from seahub.wiki.models import Wiki from seahub.views.file import can_edit_file from seahub.views import check_folder_permission @@ -808,11 +808,17 @@ class ShareLinkUpload(APIView): # generate token obj_id = json.dumps({'parent_dir': path}) + + check_virus = False + if is_pro_version() and ENABLE_UPLOAD_LINK_VIRUS_CHECK: + check_virus = True + token = seafile_api.get_fileserver_access_token(repo_id, obj_id, 'upload-link', share_link.username, - use_onetime=False) + use_onetime=False, + check_virus=check_virus) if not token: error_msg = 'Internal Server Error' diff --git a/seahub/api2/endpoints/upload_links.py b/seahub/api2/endpoints/upload_links.py index 4974e9ad0e..7658c91481 100644 --- a/seahub/api2/endpoints/upload_links.py +++ b/seahub/api2/endpoints/upload_links.py @@ -25,12 +25,14 @@ from seahub.api2.throttling import AnonRateThrottle, UserRateThrottle from seahub.api2.permissions import CanGenerateUploadLink from seahub.share.models import UploadLinkShare, check_share_link_common -from seahub.utils import gen_shared_upload_link, gen_file_upload_url +from seahub.utils import gen_shared_upload_link, gen_file_upload_url, \ + is_pro_version from seahub.views import check_folder_permission from seahub.utils.timeutils import datetime_to_isoformat_timestr from seahub.settings import UPLOAD_LINK_EXPIRE_DAYS_DEFAULT, \ - UPLOAD_LINK_EXPIRE_DAYS_MIN, UPLOAD_LINK_EXPIRE_DAYS_MAX + UPLOAD_LINK_EXPIRE_DAYS_MIN, UPLOAD_LINK_EXPIRE_DAYS_MAX, \ + ENABLE_UPLOAD_LINK_VIRUS_CHECK logger = logging.getLogger(__name__) @@ -349,11 +351,17 @@ class UploadLinkUpload(APIView): return api_error(status.HTTP_403_FORBIDDEN, error_msg) obj_id = json.dumps({'parent_dir': path}) + + check_virus = False + if is_pro_version() and ENABLE_UPLOAD_LINK_VIRUS_CHECK: + check_virus = True + token = seafile_api.get_fileserver_access_token(repo_id, obj_id, 'upload-link', uls.username, - use_onetime=False) + use_onetime=False, + check_virus=check_virus) if not token: error_msg = 'Internal Server Error'