proxy
/ build (push) Successful in 42s Details

This commit is contained in:
kosma 2026-03-04 16:47:28 +01:00
parent 5f7b61eb37
commit 69fa70c743
2 changed files with 30 additions and 3 deletions

32
app.py
View File

@ -5,10 +5,11 @@ import json
import secrets import secrets
from urllib.parse import urlencode from urllib.parse import urlencode
import requests
import yaml import yaml
from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import padding, rsa 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 = argparse.ArgumentParser()
parser.add_argument("config", help="Path to configuration file") parser.add_argument("config", help="Path to configuration file")
@ -39,7 +40,7 @@ def authorize():
session["nonce"] = nonce session["nonce"] = nonce
params = { params = {
"auth_redirect": config["redirect_url"], "auth_redirect": config["app_url"] + "/callback",
"application_name": config["application_name"], "application_name": config["application_name"],
"scopes": "read", "scopes": "read",
"client_id": client_id, "client_id": client_id,
@ -71,7 +72,7 @@ def callback():
key = response["key"] key = response["key"]
calendar_url = ( calendar_url = (
f"{config['forum_url']}/discourse-post-event/events.ics?" f"{config['app_url']}/calendar?"
+ urlencode({"order": "desc", "api_key": key}) + urlencode({"order": "desc", "api_key": key})
) )
@ -81,6 +82,31 @@ def callback():
calendar_url=calendar_url, 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__": if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000) app.run(host="0.0.0.0", port=8000)

View File

@ -1,3 +1,4 @@
flask flask
cryptography cryptography
pyyaml pyyaml
requests