diff --git a/app/main/routes.py b/app/main/routes.py index 44cca30e..3b259008 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -5,6 +5,7 @@ from random import randint import flask import markdown2 +import requests from sqlalchemy.sql.operators import or_, and_ from app import db, cache @@ -276,7 +277,22 @@ def list_files(directory): @bp.route('/test') def test(): - x = find_actor_or_create('artporn@lemm.ee') + headers = { + 'Authorization': f"Bearer {current_app.config['CLOUDFLARE_API_TOKEN']}", + 'Content-Type': 'application/json' + } + body = { + 'files': [''] + } + zone_id = current_app.config['CLOUDFLARE_ZONE_ID'] + response = requests.request( + 'POST', + f'https://api.cloudflare.com/client/v4/zones/{zone_id}/purge_cache', + headers=headers, + data=body, + timeout=5, + ) + return 'ok' users_to_notify = User.query.join(Notification, User.id == Notification.user_id).filter( diff --git a/config.py b/config.py index f26b3fe4..cb39d944 100644 --- a/config.py +++ b/config.py @@ -46,3 +46,6 @@ class Config(object): SESSION_COOKIE_SECURE = True SESSION_COOKIE_HTTPONLY = True SESSION_COOKIE_SAMESITE = 'Lax' + + CLOUDFLARE_API_TOKEN = os.environ.get('CLOUDFLARE_API_TOKEN') or '' + CLOUDFLARE_ZONE_ID = os.environ.get('CLOUDFLARE_ZONE_ID') or '' diff --git a/env.sample b/env.sample index c03c483b..e7d44a85 100644 --- a/env.sample +++ b/env.sample @@ -26,3 +26,6 @@ FLASK_APP = 'pyfedi.py' SENTRY_DSN = '' AWS_REGION = 'ap-southeast-2' + +CLOUDFLARE_API_TOKEN = '' +CLOUDFLARE_ZONE_ID = '' \ No newline at end of file