feat: error handling

This commit is contained in:
eneller
2025-03-19 22:04:23 +01:00
parent 67b0654514
commit 3d10081846
3 changed files with 21 additions and 18 deletions

View File

@@ -4,6 +4,7 @@ version = "0.1.0"
description = "Web Interface to epub2go.py"
readme = "README.md"
requires-python = ">=3.12"
# TODO enable auto-reload using https://github.com/adamchainz/django-browser-reload
dependencies = [
"celery>=5.4.0",
"django>=5.1.6",

View File

@@ -1,5 +1,5 @@
from django.shortcuts import render
from django.http import HttpRequest, HttpResponse, FileResponse
from django.http import HttpRequest, HttpResponse, FileResponse, HttpResponseBadRequest
from django.conf import settings
from celery import shared_task
@@ -24,7 +24,9 @@ def index(request: HttpRequest):
}
targetParam = request.GET.get('t', None)
if targetParam:
if validateUrl(targetParam):
# download file
fpath = getEpub(targetParam)
fname = os.path.basename(fpath)
file = open(fpath, 'rb')
@@ -32,11 +34,12 @@ def index(request: HttpRequest):
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = f'attachment; filename="{fname}"'
return response
else: return HttpResponseBadRequest('Input URL invalid.')
else:
# return base view
return render(request, 'index.html', context)
def validateUrl(param)->bool :
if not param: return False
netloc = urlparse(param).netloc
if(netloc == gbnetloc): return True

View File

@@ -5,8 +5,8 @@ body{
line-height:1.6;
font-size:18px;
color:#444;
padding:0
10px}
padding:0 10px;
}
h1,h2,h3{
line-height:1.2
@@ -17,7 +17,8 @@ h1,h2,h3{
--white:#faf0e673;
}
body{
background-color: var(--white)
background-color: var(--white);
font-family: serif;
}
header{
text-align: center;
@@ -36,13 +37,11 @@ tr:hover{
background-color: #DDDDDD;
transition: all 2ms;
}
.inline-icon{
.inline-icon, .header-icon{
vertical-align: middle;
height: 1em;
}
.header-icon{
vertical-align: middle;
height: 1em;
padding: .5em;
}
a:hover, a:any-link{