feat: Control features with build arg
This commit is contained in:
committed by
TheOnlyWayUp
parent
b9ec2b1b5a
commit
c2104ee514
+10
-1
@@ -17,6 +17,7 @@ from fastapi.responses import (
|
||||
StreamingResponse,
|
||||
)
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from os import getenv
|
||||
|
||||
from create_book import (
|
||||
EPUBGenerator,
|
||||
@@ -36,6 +37,8 @@ from create_book.parser import clean_tree, fetch_tree_images
|
||||
app = FastAPI()
|
||||
BUILD_PATH = Path(__file__).parent / "build"
|
||||
|
||||
feature_flag = True if getenv("VITE_FEATURE_FLAG") == "true" else False
|
||||
|
||||
|
||||
class RequestCancelledMiddleware:
|
||||
# Thanks https://github.com/fastapi/fastapi/discussions/11360#discussion-6427734
|
||||
@@ -192,6 +195,12 @@ async def handle_download(
|
||||
book = EPUBGenerator(metadata, part_trees, cover_data, images)
|
||||
media_type = "application/epub+zip"
|
||||
case DownloadFormat.pdf:
|
||||
if not feature_flag:
|
||||
logger.error("PDF downloads not enabled.")
|
||||
return HTMLResponse(
|
||||
status_code=403,
|
||||
content='PDF downloads have been disabled by the server administrator. Support is available on the <a href="https://discord.gg/P9RHC4KCwd" target="_blank">Discord</a>',
|
||||
)
|
||||
author_image = await fetch_image(
|
||||
metadata["user"]["avatar"].replace("-256-", "-512-")
|
||||
)
|
||||
@@ -215,7 +224,7 @@ async def handle_download(
|
||||
yield chunk
|
||||
|
||||
return StreamingResponse(
|
||||
iterfile(),
|
||||
book_buffer if feature_flag else iterfile(),
|
||||
media_type=media_type,
|
||||
headers={
|
||||
"Content-Disposition": f'attachment; filename="{slugify(metadata["title"])}_{story_id}{"_images" if download_images else ""}.{format.value}"', # Thanks https://stackoverflow.com/a/72729058
|
||||
|
||||
Reference in New Issue
Block a user