proxy
/ build (push) Successful in 42s
Details
/ build (push) Successful in 42s
Details
This commit is contained in:
parent
5f7b61eb37
commit
69fa70c743
32
app.py
32
app.py
|
|
@ -5,10 +5,11 @@ import json
|
|||
import secrets
|
||||
from urllib.parse import urlencode
|
||||
|
||||
import requests
|
||||
import yaml
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
from cryptography.hazmat.primitives.asymmetric import padding, rsa
|
||||
from flask import Flask, redirect, render_template, request, session
|
||||
from flask import Flask, redirect, render_template, request, Response, session
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("config", help="Path to configuration file")
|
||||
|
|
@ -39,7 +40,7 @@ def authorize():
|
|||
session["nonce"] = nonce
|
||||
|
||||
params = {
|
||||
"auth_redirect": config["redirect_url"],
|
||||
"auth_redirect": config["app_url"] + "/callback",
|
||||
"application_name": config["application_name"],
|
||||
"scopes": "read",
|
||||
"client_id": client_id,
|
||||
|
|
@ -71,7 +72,7 @@ def callback():
|
|||
|
||||
key = response["key"]
|
||||
calendar_url = (
|
||||
f"{config['forum_url']}/discourse-post-event/events.ics?"
|
||||
f"{config['app_url']}/calendar?"
|
||||
+ urlencode({"order": "desc", "api_key": key})
|
||||
)
|
||||
|
||||
|
|
@ -81,6 +82,31 @@ def callback():
|
|||
calendar_url=calendar_url,
|
||||
)
|
||||
|
||||
@app.route("/calendar")
|
||||
def calendar():
|
||||
params = request.args.to_dict()
|
||||
user_api_key = params.pop('user_api_key', None)
|
||||
if not user_api_key:
|
||||
return {"error": "Missing user_api_key parameter"}, 400
|
||||
|
||||
calendar_url = config['forum_url'] + "/discourse-post-event/events.ics"
|
||||
|
||||
headers = {
|
||||
'User-Api-Key': user_api_key
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.get(calendar_url, params=params, headers=headers)
|
||||
|
||||
return Response(
|
||||
response.content,
|
||||
status=response.status_code,
|
||||
content_type=response.headers.get('Content-Type')
|
||||
)
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
return {"error": f"Backend connection failed: {str(e)}"}, 502
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=8000)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
flask
|
||||
cryptography
|
||||
pyyaml
|
||||
requests
|
||||
|
|
|
|||
Loading…
Reference in New Issue