diff --git a/README.md b/README.md index d909430..d289994 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ dokku git:from-image publitebackend publite/backend:latest ``` # TODO -* Separate epub and fb2 files to python modules -* Rewrite own `.opf` file parsing to get rid of dependency on EbookLib -* Add cli interfaces for epub and fb2 libs + +- Separate epub and fb2 files to python modules +- Rewrite own `.opf` file parsing to get rid of dependency on EbookLib +- Add cli interfaces for epub and fb2 libs diff --git a/app/epub.py b/app/epub.py index 0a3d1f7..106de36 100644 --- a/app/epub.py +++ b/app/epub.py @@ -8,7 +8,7 @@ from base64 import b64encode from functools import cache from tempfile import SpooledTemporaryFile -import aiofiles as aiof +import aiofiles import ebooklib from ebooklib import epub from fastapi import HTTPException @@ -61,7 +61,7 @@ async def epub_to_tokens( tokens = {} - async with aiof.tempfile.NamedTemporaryFile() as tmp: + async with aiofiles.tempfile.NamedTemporaryFile() as tmp: await tmp.write(file.read()) # Reading book file diff --git a/app/main.py b/app/main.py index c538693..e9d7e46 100644 --- a/app/main.py +++ b/app/main.py @@ -3,12 +3,17 @@ from datetime import datetime from fastapi import FastAPI, File, HTTPException, UploadFile +from fastapi.middleware.cors import CORSMiddleware from pydantic import BaseModel # pylint: disable=no-name-in-module from .epub import epub2html from .fb2 import fb22html from .utils import HashedHTMLBook, add_hash +origins = ( + "*" +) + class DebugInfo(BaseModel): # pylint: disable=too-few-public-methods """Main handler return types""" @@ -18,6 +23,14 @@ class DebugInfo(BaseModel): # pylint: disable=too-few-public-methods app = FastAPI() +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + start_time = datetime.now() @@ -47,7 +60,8 @@ async def create_upload_file(file: UploadFile = File(...)): elif file.filename.endswith(".epub"): content = await epub2html(file.file) 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)