feat: basic FileResponse
This commit is contained in:
2
README.md
Normal file
2
README.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# epub2go-web
|
||||||
|
A simple Website to provide a `NNI (Non-Nerd Interface)` to [epub2go.py](https://github.com/eneller/epub2go.py).
|
||||||
@@ -1,21 +1,31 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse, FileResponse
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from epub2go.convert import get_all_books, Book
|
from epub2go.convert import get_all_books, Book, GBConvert
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
def index(request: HttpRequest):
|
def index(request: HttpRequest):
|
||||||
title = 'epub2go'
|
title = 'epub2go'
|
||||||
targetParam = request.GET.get('t', None)
|
targetParam = request.GET.get('t', None)
|
||||||
books = get_all_books()
|
books = get_all_books()
|
||||||
if targetParam is not None:
|
if targetParam:
|
||||||
getEpub(targetParam)
|
epub = getEpub(targetParam)
|
||||||
|
fname = os.path.join(settings.MEDIA_ROOT, epub)
|
||||||
|
file = open(fname, 'rb')
|
||||||
|
response = FileResponse(file)
|
||||||
|
response['Content-Type'] = 'application/octet-stream'
|
||||||
|
response['Content-Disposition'] = f'attachment; filename="{os.path.basename(fname)}"'
|
||||||
|
return response
|
||||||
|
|
||||||
return render(request, 'index.html', locals())
|
return render(request, 'index.html', locals())
|
||||||
|
|
||||||
def getEpub(param):
|
def getEpub(param):
|
||||||
print(param)
|
print(param)
|
||||||
# TODO validate / sanitize input
|
# TODO validate / sanitize input
|
||||||
# TODO check for existing file and age
|
# TODO check for existing file and age
|
||||||
# TODO download
|
#GBConvert(param,downloaddir=settings.MEDIA_ROOT).run()
|
||||||
# TODO redirect to loading page
|
# TODO redirect to loading page
|
||||||
# TODO redirect to download page
|
# TODO redirect to download page
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|||||||
Reference in New Issue
Block a user