Skip to content

Commit

Permalink
add-zip-task-request-limit (#6825)
Browse files Browse the repository at this point in the history
* add-zip-task-request-limit

* update

* Update settings.py

* Update share_link_zip_task.py

* Update test_settings.py
  • Loading branch information
r350178982 authored Sep 23, 2024
1 parent 315fcc0 commit 99bc315
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions frontend/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,8 @@ export const Utils = {
);
}
errorMsg = gettext('Permission denied');
} else if (error.response.status == 429) {
errorMsg = gettext('Too many requests');
} else if (error.response.data &&
error.response.data['error_msg']) {
errorMsg = error.response.data['error_msg'];
Expand Down
4 changes: 2 additions & 2 deletions seahub/api2/endpoints/share_link_zip_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from django.conf import settings

from seahub.api2.throttling import UserRateThrottle
from seahub.api2.throttling import ShareLinkZipTaskThrottle
from seahub.api2.utils import api_error

from seahub.views.file import send_file_access_msg
Expand All @@ -27,7 +27,7 @@

class ShareLinkZipTaskView(APIView):

throttle_classes = (UserRateThrottle,)
throttle_classes = (ShareLinkZipTaskThrottle, )

def get(self, request, format=None):
""" Only used for download dir when view dir share link from web.
Expand Down
17 changes: 17 additions & 0 deletions seahub/api2/throttling.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.core.cache import cache as default_cache
from django.core.exceptions import ImproperlyConfigured
from rest_framework.settings import api_settings
from rest_framework.throttling import BaseThrottle
import time

from seahub.utils.ip import get_remote_ip
Expand Down Expand Up @@ -207,6 +208,22 @@ def get_cache_key(self, request, view):
'ident': ident
}

class ShareLinkZipTaskThrottle(SimpleRateThrottle):

scope = 'share_link_zip_task'

def get_cache_key(self, request, view):
if request.user.is_authenticated:
ident = request.user.id
else:
ident = self.get_ident(request)

return self.cache_format % {
'scope': self.scope,
'ident': ident
}



class ScopedRateThrottle(SimpleRateThrottle):
"""
Expand Down
1 change: 1 addition & 0 deletions seahub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@
'ping': '3000/minute',
'anon': '60/minute',
'user': '3000/minute',
'share_link_zip_task': '10/minute'
},
# https://github.com/tomchristie/django-rest-framework/issues/2891
'UNICODE_JSON': False,
Expand Down
1 change: 1 addition & 0 deletions seahub/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'ping': '90000/minute',
'anon': '90000/minute',
'user': '90000/minute',
'share_link_zip_task': '90000/minute'
},
}

Expand Down

0 comments on commit 99bc315

Please sign in to comment.