Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,13 +3,27 @@ import requests
|
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
|
| 6 |
-
@app.route('/api/webhooks/<webhook_id>/<webhook_token>', methods=['GET'])
|
| 7 |
-
def
|
| 8 |
discord_url = f"https://discord.com/api/webhooks/{webhook_id}/{webhook_token}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
return jsonify(response.json()), response.status_code
|
| 13 |
|
| 14 |
if __name__ == '__main__':
|
| 15 |
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
|
| 6 |
+
@app.route('/api/webhooks/<webhook_id>/<webhook_token>', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'])
|
| 7 |
+
def mirror_all_methods(webhook_id, webhook_token):
|
| 8 |
discord_url = f"https://discord.com/api/webhooks/{webhook_id}/{webhook_token}"
|
| 9 |
+
|
| 10 |
+
headers = {key: value for (key, value) in request.headers if key.lower() != 'host'}
|
| 11 |
+
|
| 12 |
+
response = requests.request(
|
| 13 |
+
method=request.method,
|
| 14 |
+
url=discord_url,
|
| 15 |
+
headers=headers,
|
| 16 |
+
data=request.get_data(),
|
| 17 |
+
params=request.args,
|
| 18 |
+
allow_redirects=False
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
response_data = response.json() if response.content else {}
|
| 23 |
+
except ValueError:
|
| 24 |
+
response_data = response.text
|
| 25 |
|
| 26 |
+
return jsonify(response_data), response.status_code, dict(response.headers)
|
|
|
|
|
|
|
| 27 |
|
| 28 |
if __name__ == '__main__':
|
| 29 |
app.run(host='0.0.0.0', port=7860)
|