Added cors
This commit is contained in:
parent
dcab64c78d
commit
a1a4d15e4e
@ -57,6 +57,7 @@ dokku git:from-image publitebackend publite/backend:latest
|
|||||||
```
|
```
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
* Separate epub and fb2 files to python modules
|
|
||||||
* Rewrite own `.opf` file parsing to get rid of dependency on EbookLib
|
- Separate epub and fb2 files to python modules
|
||||||
* Add cli interfaces for epub and fb2 libs
|
- Rewrite own `.opf` file parsing to get rid of dependency on EbookLib
|
||||||
|
- Add cli interfaces for epub and fb2 libs
|
||||||
|
@ -8,7 +8,7 @@ from base64 import b64encode
|
|||||||
from functools import cache
|
from functools import cache
|
||||||
from tempfile import SpooledTemporaryFile
|
from tempfile import SpooledTemporaryFile
|
||||||
|
|
||||||
import aiofiles as aiof
|
import aiofiles
|
||||||
import ebooklib
|
import ebooklib
|
||||||
from ebooklib import epub
|
from ebooklib import epub
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
@ -61,7 +61,7 @@ async def epub_to_tokens(
|
|||||||
|
|
||||||
tokens = {}
|
tokens = {}
|
||||||
|
|
||||||
async with aiof.tempfile.NamedTemporaryFile() as tmp:
|
async with aiofiles.tempfile.NamedTemporaryFile() as tmp:
|
||||||
await tmp.write(file.read())
|
await tmp.write(file.read())
|
||||||
|
|
||||||
# Reading book file
|
# Reading book file
|
||||||
|
16
app/main.py
16
app/main.py
@ -3,12 +3,17 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from fastapi import FastAPI, File, HTTPException, UploadFile
|
from fastapi import FastAPI, File, HTTPException, UploadFile
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from pydantic import BaseModel # pylint: disable=no-name-in-module
|
from pydantic import BaseModel # pylint: disable=no-name-in-module
|
||||||
|
|
||||||
from .epub import epub2html
|
from .epub import epub2html
|
||||||
from .fb2 import fb22html
|
from .fb2 import fb22html
|
||||||
from .utils import HashedHTMLBook, add_hash
|
from .utils import HashedHTMLBook, add_hash
|
||||||
|
|
||||||
|
origins = (
|
||||||
|
"*"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class DebugInfo(BaseModel): # pylint: disable=too-few-public-methods
|
class DebugInfo(BaseModel): # pylint: disable=too-few-public-methods
|
||||||
"""Main handler return types"""
|
"""Main handler return types"""
|
||||||
@ -18,6 +23,14 @@ class DebugInfo(BaseModel): # pylint: disable=too-few-public-methods
|
|||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
allow_origins=origins,
|
||||||
|
allow_credentials=True,
|
||||||
|
allow_methods=["*"],
|
||||||
|
allow_headers=["*"],
|
||||||
|
)
|
||||||
|
|
||||||
start_time = datetime.now()
|
start_time = datetime.now()
|
||||||
|
|
||||||
|
|
||||||
@ -47,7 +60,8 @@ async def create_upload_file(file: UploadFile = File(...)):
|
|||||||
elif file.filename.endswith(".epub"):
|
elif file.filename.endswith(".epub"):
|
||||||
content = await epub2html(file.file)
|
content = await epub2html(file.file)
|
||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=415, detail="Error! Unsupported file type")
|
raise HTTPException(
|
||||||
|
status_code=415, detail="Error! Unsupported file type")
|
||||||
|
|
||||||
h_content = add_hash(content)
|
h_content = add_hash(content)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user