mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-12-28 16:12:13 +00:00
remove restriction when using open api
This commit is contained in:
parent
745dba8cad
commit
03c68419b0
@ -14,6 +14,7 @@ class APITokenAuthMiddleware(MiddlewareMixin):
|
||||
try:
|
||||
request.user = User.objects.get(open_api_appkey=appkey, open_api=True, is_disabled=False)
|
||||
request.csrf_processing_done = True
|
||||
request.auth_method = "api_key"
|
||||
except User.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
@ -57,7 +57,7 @@ class ContestAPI(APIView):
|
||||
for ip_range in data["allowed_ip_ranges"]:
|
||||
try:
|
||||
ip_network(ip_range, strict=False)
|
||||
except ValueError as e:
|
||||
except ValueError:
|
||||
return self.error(f"{ip_range} is not a valid cidr network")
|
||||
if not contest.real_time_rank and data.get("real_time_rank"):
|
||||
cache_key = f"{CacheKey.contest_rank_cache}:{contest.id}"
|
||||
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import base64
|
||||
import copy
|
||||
import random
|
||||
|
@ -14,9 +14,9 @@ TEMPLATE_BASE = """//PREPEND BEGIN
|
||||
|
||||
|
||||
def parse_problem_template(template_str):
|
||||
prepend = re.findall("//PREPEND BEGIN\n([\s\S]+?)//PREPEND END", template_str)
|
||||
template = re.findall("//TEMPLATE BEGIN\n([\s\S]+?)//TEMPLATE END", template_str)
|
||||
append = re.findall("//APPEND BEGIN\n([\s\S]+?)//APPEND END", template_str)
|
||||
prepend = re.findall(r"//PREPEND BEGIN\n([\s\S]+?)//PREPEND END", template_str)
|
||||
template = re.findall(r"//TEMPLATE BEGIN\n([\s\S]+?)//TEMPLATE END", template_str)
|
||||
append = re.findall(r"//APPEND BEGIN\n([\s\S]+?)//APPEND END", template_str)
|
||||
return {"prepend": prepend[0] if prepend else "",
|
||||
"template": template[0] if template else "",
|
||||
"append": append[0] if append else ""}
|
||||
|
@ -18,6 +18,10 @@ from ..serializers import SubmissionSafeModelSerializer, SubmissionListSerialize
|
||||
|
||||
class SubmissionAPI(APIView):
|
||||
def throttling(self, request):
|
||||
# 使用 open_api 的请求暂不做限制
|
||||
auth_method = getattr(request, "auth_method", "")
|
||||
if auth_method == "api_key":
|
||||
return
|
||||
user_bucket = TokenBucket(key=str(request.user.id),
|
||||
redis_conn=cache, **SysOptions.throttling["user"])
|
||||
can_consume, wait = user_bucket.consume()
|
||||
|
Loading…
Reference in New Issue
Block a user