mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-04 16:31:13 +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');
|
errorMsg = gettext('Permission denied');
|
||||||
|
} else if (error.response.status == 429) {
|
||||||
|
errorMsg = gettext('Too many requests');
|
||||||
} else if (error.response.data &&
|
} else if (error.response.data &&
|
||||||
error.response.data['error_msg']) {
|
error.response.data['error_msg']) {
|
||||||
errorMsg = 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 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.api2.utils import api_error
|
||||||
|
|
||||||
from seahub.views.file import send_file_access_msg
|
from seahub.views.file import send_file_access_msg
|
||||||
@@ -27,7 +27,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class ShareLinkZipTaskView(APIView):
|
class ShareLinkZipTaskView(APIView):
|
||||||
|
|
||||||
throttle_classes = (UserRateThrottle,)
|
throttle_classes = (ShareLinkZipTaskThrottle, )
|
||||||
|
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
""" Only used for download dir when view dir share link from web.
|
""" 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.cache import cache as default_cache
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
|
from rest_framework.throttling import BaseThrottle
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from seahub.utils.ip import get_remote_ip
|
from seahub.utils.ip import get_remote_ip
|
||||||
@@ -207,6 +208,22 @@ class UserRateThrottle(SimpleRateThrottle):
|
|||||||
'ident': ident
|
'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):
|
class ScopedRateThrottle(SimpleRateThrottle):
|
||||||
"""
|
"""
|
||||||
|
@@ -544,6 +544,7 @@ REST_FRAMEWORK = {
|
|||||||
'ping': '3000/minute',
|
'ping': '3000/minute',
|
||||||
'anon': '60/minute',
|
'anon': '60/minute',
|
||||||
'user': '3000/minute',
|
'user': '3000/minute',
|
||||||
|
'share_link_zip_task': '10/minute'
|
||||||
},
|
},
|
||||||
# https://github.com/tomchristie/django-rest-framework/issues/2891
|
# https://github.com/tomchristie/django-rest-framework/issues/2891
|
||||||
'UNICODE_JSON': False,
|
'UNICODE_JSON': False,
|
||||||
|
@@ -13,6 +13,7 @@ REST_FRAMEWORK = {
|
|||||||
'ping': '90000/minute',
|
'ping': '90000/minute',
|
||||||
'anon': '90000/minute',
|
'anon': '90000/minute',
|
||||||
'user': '90000/minute',
|
'user': '90000/minute',
|
||||||
|
'share_link_zip_task': '90000/minute'
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user