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
+2 -2
View File
@@ -7,8 +7,8 @@ RUN rm -rf build
RUN npm install RUN npm install
COPY src/frontend/. . COPY src/frontend/. .
ARG feature_flag=false ARG pdfs=false
ENV VITE_FEATURE_FLAG=$feature_flag ENV VITE_ENABLE_PDFS=$pdfs
RUN npm run build RUN npm run build
# Thanks https://stackoverflow.com/q/76988450 # Thanks https://stackoverflow.com/q/76988450
+4 -4
View File
@@ -2,6 +2,7 @@
import asyncio import asyncio
from enum import Enum from enum import Enum
from os import getenv
from pathlib import Path from pathlib import Path
from typing import Optional from typing import Optional
from zipfile import ZipFile from zipfile import ZipFile
@@ -17,7 +18,6 @@ from fastapi.responses import (
StreamingResponse, StreamingResponse,
) )
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from os import getenv
from create_book import ( from create_book import (
EPUBGenerator, EPUBGenerator,
@@ -37,7 +37,7 @@ from create_book.parser import clean_tree, fetch_tree_images
app = FastAPI() app = FastAPI()
BUILD_PATH = Path(__file__).parent / "build" 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: class RequestCancelledMiddleware:
@@ -195,7 +195,7 @@ async def handle_download(
book = EPUBGenerator(metadata, part_trees, cover_data, images) book = EPUBGenerator(metadata, part_trees, cover_data, images)
media_type = "application/epub+zip" media_type = "application/epub+zip"
case DownloadFormat.pdf: case DownloadFormat.pdf:
if not feature_flag: if not PDFS_ENABLED:
logger.error("PDF downloads not enabled.") logger.error("PDF downloads not enabled.")
return HTMLResponse( return HTMLResponse(
status_code=403, status_code=403,
@@ -224,7 +224,7 @@ async def handle_download(
yield chunk yield chunk
return StreamingResponse( return StreamingResponse(
book_buffer if feature_flag else iterfile(), book_buffer if PDFS_ENABLED else iterfile(),
media_type=media_type, media_type=media_type,
headers={ headers={
"Content-Disposition": f'attachment; filename="{slugify(metadata["title"])}_{story_id}{"_images" if download_images else ""}.{format.value}"', # Thanks https://stackoverflow.com/a/72729058 "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> <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 downloadImages = $state(false);
let downloadAsPdf = $state(false); // 0 = epub, 1 = pdf let downloadAsPdf = $state(false); // 0 = epub, 1 = pdf
@@ -112,7 +112,7 @@
> >
WP Downloader WP Downloader
</h1> </h1>
{#if !featureFlag} {#if !PDFS_ENABLED}
<div role="alert" class="alert mt-10 max-w-md break-words bg-green-200"> <div role="alert" class="alert mt-10 max-w-md break-words bg-green-200">
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
@@ -160,7 +160,7 @@
<ul class="list list-inside pt-4 text-xl"> <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. --> <!-- 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> <li>05/25 - ⚖️ Legal Compliance</li>
{#if featureFlag} {#if PDFS_ENABLED}
<li>12/24 - ⚡ Super-fast Downloads!</li> <li>12/24 - ⚡ Super-fast Downloads!</li>
<li>12/24 - 📑 PDF Downloads!</li> <li>12/24 - 📑 PDF Downloads!</li>
{:else} {:else}
@@ -259,7 +259,7 @@
> >
</div> </div>
{#if featureFlag} {#if PDFS_ENABLED}
<label class="swap w-fit label mt-2 pb-2"> <label class="swap w-fit label mt-2 pb-2">
<input type="checkbox" bind:checked={downloadAsPdf} /> <input type="checkbox" bind:checked={downloadAsPdf} />
<div class="swap-on absolute left-0 text-gray-800"> <div class="swap-on absolute left-0 text-gray-800">