From 60798ed1a1feb7ecc347a238d685258746699a46 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Mon, 8 Apr 2024 21:26:53 +0200 Subject: [PATCH] clean up PR --- reflex/.templates/web/utils/state.js | 3 +++ reflex/app.py | 4 ++-- reflex/components/core/upload.py | 7 ++++--- reflex/components/core/upload.pyi | 2 +- reflex/constants/event.py | 1 - 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/reflex/.templates/web/utils/state.js b/reflex/.templates/web/utils/state.js index aa60c02b7..b12fbac43 100644 --- a/reflex/.templates/web/utils/state.js +++ b/reflex/.templates/web/utils/state.js @@ -166,6 +166,9 @@ export const applyEvent = async (event, socket) => { "${getBackendURL(env.UPLOAD)}", getBackendURL(env.UPLOAD) ); + if (event.payload.filename) { + a.href = a.href + "?filename=" + event.payload.filename; + } a.download = event.payload.filename; a.click(); a.remove(); diff --git a/reflex/app.py b/reflex/app.py index 27f34a8bb..4544f8917 100644 --- a/reflex/app.py +++ b/reflex/app.py @@ -271,12 +271,12 @@ class App(Base): self.api.get(str(constants.Endpoint.PING))(ping) def add_optional_endpoints(self): - """Add optional api endpoints (_upload and _download).""" + """Add optional api endpoints (_upload).""" # To upload files. if Upload.is_used: self.api.post(str(constants.Endpoint.UPLOAD))(upload(self)) - # To access uploaded files as assets. + # To access uploaded files. self.api.mount( str(constants.Endpoint.UPLOAD), UploadedFiles(directory=get_upload_dir()), diff --git a/reflex/components/core/upload.py b/reflex/components/core/upload.py index 75154ca37..343553d1e 100644 --- a/reflex/components/core/upload.py +++ b/reflex/components/core/upload.py @@ -129,19 +129,20 @@ uploaded_files_url_prefix: Var = Var.create_safe( ) -def get_upload_url(file_path: str, download: bool = False) -> Var[str]: +def get_upload_url(file_path: str) -> Var[str]: """Get the URL of an uploaded file. Args: file_path: The path of the uploaded file. - download: Whether to get the download URL instead of the upload URL. Returns: The URL of the uploaded file to be rendered from the frontend (as a str-encoded Var). """ Upload.is_used = True - return Var.create_safe(f"{uploaded_files_url_prefix}/{file_path}") + return Var.create_safe( + f"{uploaded_files_url_prefix}/{file_path}", _var_is_string=True + ) def _on_drop_spec(files: Var): diff --git a/reflex/components/core/upload.pyi b/reflex/components/core/upload.pyi index 1f9d16d73..b8387e696 100644 --- a/reflex/components/core/upload.pyi +++ b/reflex/components/core/upload.pyi @@ -40,7 +40,7 @@ def get_upload_dir() -> Path: ... uploaded_files_url_prefix: Var -def get_upload_url(file_path: str, download: bool = False) -> Var[str]: ... +def get_upload_url(file_path: str) -> Var[str]: ... class UploadFilesProvider(Component): @overload diff --git a/reflex/constants/event.py b/reflex/constants/event.py index 4797a65ca..fcfe9cdfc 100644 --- a/reflex/constants/event.py +++ b/reflex/constants/event.py @@ -10,7 +10,6 @@ class Endpoint(Enum): PING = "ping" EVENT = "_event" UPLOAD = "_upload" - DOWNLOAD = "_download" def __str__(self) -> str: """Get the string representation of the endpoint.