cutycat2000x commited on
Commit
f2696d8
1 Parent(s): 130f8c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -31
app.py CHANGED
@@ -5,8 +5,6 @@ import asyncio
5
  import os
6
  import json
7
 
8
- request_count = {}
9
- ongoing_requests = {}
10
  bypass = os.getenv("BYPASS")
11
  MAX_REQUESTS_PER_MINUTE = 7
12
  app = Flask("DiscordRocks Instant Chat Proxy")
@@ -28,13 +26,6 @@ def handle_request(path=""):
28
  if method == 'POST':
29
  headers = {'Content-Type': 'application/json'}
30
  if 'reply' in path:
31
- if request_count.get(ip, 0) >= MAX_REQUESTS_PER_MINUTE:
32
- return jsonify({"error": "Too Many Requests. Please try again later."+ ip}), 429
33
- if ip in ongoing_requests:
34
- return jsonify({"error": "Concurrent requests not allowed."}), 429
35
- ongoing_requests[ip] = True
36
- request_count[ip] = request_count.get(ip, 0) + 1
37
- didReply = True
38
  json_data = request.get_json()
39
  json_data['bypass'] = bypass
40
  data = json.dumps(json_data)
@@ -44,31 +35,9 @@ def handle_request(path=""):
44
  proxied_response = Response(response.content)
45
  proxied_response.status_code = response.status_code
46
  proxied_response.headers["Content-Type"] = "text/html"
47
- if didReply:
48
- del ongoing_requests[ip]
49
- decrement_request_count_task(ip)
50
 
51
  return proxied_response
52
 
53
- def decrement_request_count_task(ip):
54
- @copy_current_request_context
55
- def decrement_count():
56
- try:
57
- loop = asyncio.new_event_loop()
58
- asyncio.set_event_loop(loop)
59
- loop.run_until_complete(decrement_request_count(ip))
60
- except Exception as e:
61
- print(e)
62
-
63
- threading.Thread(target=decrement_count).start()
64
-
65
- async def decrement_request_count(ip):
66
- try:
67
- await asyncio.sleep(60) # Ensure this runs asynchronously
68
- request_count[ip] = request_count.get(ip, 0) - 1
69
- print(request_count[ip])
70
- except Exception as es:
71
- print(es)
72
 
73
  if __name__ == "__main__":
74
  app.run(host="0.0.0.0", port=7860)
 
5
  import os
6
  import json
7
 
 
 
8
  bypass = os.getenv("BYPASS")
9
  MAX_REQUESTS_PER_MINUTE = 7
10
  app = Flask("DiscordRocks Instant Chat Proxy")
 
26
  if method == 'POST':
27
  headers = {'Content-Type': 'application/json'}
28
  if 'reply' in path:
 
 
 
 
 
 
 
29
  json_data = request.get_json()
30
  json_data['bypass'] = bypass
31
  data = json.dumps(json_data)
 
35
  proxied_response = Response(response.content)
36
  proxied_response.status_code = response.status_code
37
  proxied_response.headers["Content-Type"] = "text/html"
 
 
 
38
 
39
  return proxied_response
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  if __name__ == "__main__":
43
  app.run(host="0.0.0.0", port=7860)