Spaces:
Running
Running
File size: 1,312 Bytes
31a302b 595f0ee 20f4cd1 fa5c81c 534b6e8 3c2a81d fa5c81c 3c2a81d fa5c81c 3c2a81d 20f4cd1 3c2a81d b2ebd1d 595f0ee cfea4a6 88abbff fa5c81c 88abbff fa5c81c 88abbff cfea4a6 3c2a81d fa5c81c 3c2a81d fac94c9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
from flask import Flask, request, Response, copy_current_request_context, jsonify
import threading
import requests
import asyncio
import os
import json
bypass = os.getenv("BYPASS")
MAX_REQUESTS_PER_MINUTE = 7
app = Flask("DiscordRocks Instant Chat Proxy")
DISCORD_ROCKS_HOST = 'chat.discord.rocks'
CHAT_UI_HOST = 'cutycat2000x-instantchat.static.hf.space'
@app.route('/', methods=['GET', 'POST'])
@app.route("/<path:path>", methods=['GET', 'POST'])
def handle_request(path=""):
chat_ui_url = f'https://{DISCORD_ROCKS_HOST}/{path}'
ip = request.remote_addr
print("IP: "+ip)
method = request.method
data = request.data
params = request.args
headers = None
didReply = False
if method == 'POST':
headers = {'Content-Type': 'application/json'}
if 'reply' in path:
json_data = request.get_json()
json_data['bypass'] = bypass
data = json.dumps(json_data)
response = requests.request(method, chat_ui_url, params=params, data=data, headers=headers)
proxied_response = Response(response.content)
proxied_response.status_code = response.status_code
proxied_response.headers["Content-Type"] = "text/html"
return proxied_response
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860)
|