feat: error handling
This commit is contained in:
@@ -4,6 +4,7 @@ version = "0.1.0"
|
|||||||
description = "Web Interface to epub2go.py"
|
description = "Web Interface to epub2go.py"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
|
# TODO enable auto-reload using https://github.com/adamchainz/django-browser-reload
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"celery>=5.4.0",
|
"celery>=5.4.0",
|
||||||
"django>=5.1.6",
|
"django>=5.1.6",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from django.shortcuts import render
|
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 django.conf import settings
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
|
|
||||||
@@ -24,19 +24,22 @@ def index(request: HttpRequest):
|
|||||||
}
|
}
|
||||||
|
|
||||||
targetParam = request.GET.get('t', None)
|
targetParam = request.GET.get('t', None)
|
||||||
if validateUrl(targetParam):
|
if targetParam:
|
||||||
fpath = getEpub(targetParam)
|
if validateUrl(targetParam):
|
||||||
fname = os.path.basename(fpath)
|
# download file
|
||||||
file = open(fpath, 'rb')
|
fpath = getEpub(targetParam)
|
||||||
response = FileResponse(file)
|
fname = os.path.basename(fpath)
|
||||||
response['Content-Type'] = 'application/octet-stream'
|
file = open(fpath, 'rb')
|
||||||
response['Content-Disposition'] = f'attachment; filename="{fname}"'
|
response = FileResponse(file)
|
||||||
return response
|
response['Content-Type'] = 'application/octet-stream'
|
||||||
|
response['Content-Disposition'] = f'attachment; filename="{fname}"'
|
||||||
return render(request, 'index.html', context)
|
return response
|
||||||
|
else: return HttpResponseBadRequest('Input URL invalid.')
|
||||||
|
else:
|
||||||
|
# return base view
|
||||||
|
return render(request, 'index.html', context)
|
||||||
|
|
||||||
def validateUrl(param)->bool :
|
def validateUrl(param)->bool :
|
||||||
if not param: return False
|
|
||||||
|
|
||||||
netloc = urlparse(param).netloc
|
netloc = urlparse(param).netloc
|
||||||
if(netloc == gbnetloc): return True
|
if(netloc == gbnetloc): return True
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ body{
|
|||||||
line-height:1.6;
|
line-height:1.6;
|
||||||
font-size:18px;
|
font-size:18px;
|
||||||
color:#444;
|
color:#444;
|
||||||
padding:0
|
padding:0 10px;
|
||||||
10px}
|
}
|
||||||
|
|
||||||
h1,h2,h3{
|
h1,h2,h3{
|
||||||
line-height:1.2
|
line-height:1.2
|
||||||
@@ -17,7 +17,8 @@ h1,h2,h3{
|
|||||||
--white:#faf0e673;
|
--white:#faf0e673;
|
||||||
}
|
}
|
||||||
body{
|
body{
|
||||||
background-color: var(--white)
|
background-color: var(--white);
|
||||||
|
font-family: serif;
|
||||||
}
|
}
|
||||||
header{
|
header{
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@@ -36,13 +37,11 @@ tr:hover{
|
|||||||
background-color: #DDDDDD;
|
background-color: #DDDDDD;
|
||||||
transition: all 2ms;
|
transition: all 2ms;
|
||||||
}
|
}
|
||||||
.inline-icon{
|
.inline-icon, .header-icon{
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
height: 1em;
|
height: 1em;
|
||||||
}
|
}
|
||||||
.header-icon{
|
.header-icon{
|
||||||
vertical-align: middle;
|
|
||||||
height: 1em;
|
|
||||||
padding: .5em;
|
padding: .5em;
|
||||||
}
|
}
|
||||||
a:hover, a:any-link{
|
a:hover, a:any-link{
|
||||||
|
|||||||
Reference in New Issue
Block a user