Compare commits

...

5 commits

Author SHA1 Message Date
Quantum 1a60694112 Add health check endpoint 2025-01-02 01:08:10 -05:00
Quantum 7ff577fd0c Update to latest version of cloudflare package 2025-01-02 00:52:45 -05:00
Quantum dea0154077 Add pymysql helper script for gevent 2025-01-02 00:48:32 -05:00
Quantum 971854f4c1 Upgrade to Django 4.2 2025-01-01 23:38:34 -05:00
Quantum 22f2a9761a Remove unnecessary imports 2023-07-26 02:12:28 -04:00
8 changed files with 18 additions and 12 deletions

2
pymysql_as_mysql.py Normal file
View file

@ -0,0 +1,2 @@
import pymysql
pymysql.install_as_MySQLdb()

View file

@ -1,18 +1,16 @@
from CloudFlare import CloudFlare from cloudflare import Cloudflare
from django.conf import settings from django.conf import settings
from qlinks.cdn_cache import BaseCDNCache from qlinks.cdn_cache import BaseCDNCache
class CloudflareCDNCache(BaseCDNCache): class CloudflareCDNCache(BaseCDNCache):
cf: CloudFlare cf: Cloudflare
zone: str zone: str
def __init__(self): def __init__(self):
self.cf = CloudFlare(token=getattr(settings, 'QLINKS_CDN_CLOUDFLARE_API_TOKEN', None)) self.cf = Cloudflare(api_token=getattr(settings, 'QLINKS_CDN_CLOUDFLARE_API_TOKEN', None))
self.zone = settings.QLINKS_CDN_CLOUDFLARE_ZONE_ID self.zone = settings.QLINKS_CDN_CLOUDFLARE_ZONE_ID
def purge(self, url: str) -> None: def purge(self, url: str) -> None:
self.cf.zones.purge_cache.post(self.zone, data={ self.cf.cache.purge(zone_id=self.zone, files=[url])
'files': [url],
})

View file

@ -1,6 +1,5 @@
from django.conf import settings from django.conf import settings
from django.core.mail import send_mail from django.core.mail import send_mail
from django.template import Context
from django.template.loader import get_template from django.template.loader import get_template
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _

View file

@ -1,9 +1,8 @@
# Generated by Django 4.0.1 on 2022-01-24 03:42 # Generated by Django 4.0.1 on 2022-01-24 03:42
import django.utils.timezone
from django.conf import settings from django.conf import settings
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration): class Migration(migrations.Migration):

View file

@ -1,6 +1,7 @@
# Generated by Django 4.0.1 on 2022-01-25 00:13 # Generated by Django 4.0.1 on 2022-01-25 00:13
from django.db import migrations, models from django.db import migrations, models
import qlinks.models import qlinks.models

View file

@ -2,9 +2,10 @@ from functools import partial
from django.urls import path from django.urls import path
from qlinks.views import short_link from qlinks.views import health_check, short_link
urlpatterns = [ urlpatterns = [
path('', partial(short_link, path=''), name='short_link'), path('', partial(short_link, path=''), name='short_link'),
path('api/health_check', health_check, name='health_check'),
path('<path:path>', short_link, name='short_link'), path('<path:path>', short_link, name='short_link'),
] ]

View file

@ -1,5 +1,5 @@
from django.conf import settings from django.conf import settings
from django.http import HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from qlinks.models import Link from qlinks.models import Link
@ -10,3 +10,8 @@ def short_link(request, path):
return HttpResponseRedirect(link, headers={ return HttpResponseRedirect(link, headers={
'X-Powered-By': settings.QLINKS_POWERED_BY 'X-Powered-By': settings.QLINKS_POWERED_BY
}) })
def health_check(request):
Link.objects.exists()
return HttpResponse('qlinks seems to work!')

View file

@ -1,3 +1,4 @@
Django>=4,<4.1 Django>=4.2,<5
django-hosts django-hosts
requests requests
cloudflare