feat: error handling
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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,19 +24,22 @@ def index(request: HttpRequest):
|
||||
}
|
||||
|
||||
targetParam = request.GET.get('t', None)
|
||||
if validateUrl(targetParam):
|
||||
fpath = getEpub(targetParam)
|
||||
fname = os.path.basename(fpath)
|
||||
file = open(fpath, 'rb')
|
||||
response = FileResponse(file)
|
||||
response['Content-Type'] = 'application/octet-stream'
|
||||
response['Content-Disposition'] = f'attachment; filename="{fname}"'
|
||||
return response
|
||||
|
||||
return render(request, 'index.html', context)
|
||||
if targetParam:
|
||||
if validateUrl(targetParam):
|
||||
# download file
|
||||
fpath = getEpub(targetParam)
|
||||
fname = os.path.basename(fpath)
|
||||
file = open(fpath, 'rb')
|
||||
response = FileResponse(file)
|
||||
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
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user