mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-31 06:34:40 +00:00
add-zip-task-request-limit (#6825)
* add-zip-task-request-limit * update * Update settings.py * Update share_link_zip_task.py * Update test_settings.py
This commit is contained in:
@@ -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'];
|
||||
|
@@ -10,7 +10,7 @@ from rest_framework import status
|
||||
|
||||
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
|
||||
@@ -27,7 +27,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
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.
|
||||
|
@@ -7,6 +7,7 @@ from django.conf import settings
|
||||
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
|
||||
@@ -207,6 +208,22 @@ class UserRateThrottle(SimpleRateThrottle):
|
||||
'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):
|
||||
"""
|
||||
|
@@ -544,6 +544,7 @@ REST_FRAMEWORK = {
|
||||
'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,
|
||||
|
@@ -13,6 +13,7 @@ REST_FRAMEWORK = {
|
||||
'ping': '90000/minute',
|
||||
'anon': '90000/minute',
|
||||
'user': '90000/minute',
|
||||
'share_link_zip_task': '90000/minute'
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user