fix: Change name of flag to enable PDF downloads

This commit is contained in:
AaronBenDaniel
2025-06-24 15:26:53 -04:00
committed by TheOnlyWayUp
parent c2104ee514
commit d372020bac
3 changed files with 10 additions and 10 deletions
+4 -4
View File
@@ -2,6 +2,7 @@
import asyncio
from enum import Enum
from os import getenv
from pathlib import Path
from typing import Optional
from zipfile import ZipFile
@@ -17,7 +18,6 @@ from fastapi.responses import (
StreamingResponse,
)
from fastapi.staticfiles import StaticFiles
from os import getenv
from create_book import (
EPUBGenerator,
@@ -37,7 +37,7 @@ 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
PDFS_ENABLED = True if getenv("VITE_ENABLE_PDFS") == "true" else False
class RequestCancelledMiddleware:
@@ -195,7 +195,7 @@ async def handle_download(
book = EPUBGenerator(metadata, part_trees, cover_data, images)
media_type = "application/epub+zip"
case DownloadFormat.pdf:
if not feature_flag:
if not PDFS_ENABLED:
logger.error("PDF downloads not enabled.")
return HTMLResponse(
status_code=403,
@@ -224,7 +224,7 @@ async def handle_download(
yield chunk
return StreamingResponse(
book_buffer if feature_flag else iterfile(),
book_buffer if PDFS_ENABLED 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
+4 -4
View File
@@ -1,5 +1,5 @@
<script>
const featureFlag = import.meta.env.VITE_FEATURE_FLAG === "true";
const PDFS_ENABLED = import.meta.env.VITE_ENABLE_PDFS === "true";
let downloadImages = $state(false);
let downloadAsPdf = $state(false); // 0 = epub, 1 = pdf
@@ -112,7 +112,7 @@
>
WP Downloader
</h1>
{#if !featureFlag}
{#if !PDFS_ENABLED}
<div role="alert" class="alert mt-10 max-w-md break-words bg-green-200">
<svg
xmlns="http://www.w3.org/2000/svg"
@@ -160,7 +160,7 @@
<ul class="list list-inside pt-4 text-xl">
<!-- TODO: 'max-lg: hidden' to hide on screen sizes smaller than lg. I'll do this when I figure out how to make this show up _below_ the card on smaller screen sizes. -->
<li>05/25 - ⚖️ Legal Compliance</li>
{#if featureFlag}
{#if PDFS_ENABLED}
<li>12/24 - ⚡ Super-fast Downloads!</li>
<li>12/24 - 📑 PDF Downloads!</li>
{:else}
@@ -259,7 +259,7 @@
>
</div>
{#if featureFlag}
{#if PDFS_ENABLED}
<label class="swap w-fit label mt-2 pb-2">
<input type="checkbox" bind:checked={downloadAsPdf} />
<div class="swap-on absolute left-0 text-gray-800">