clean up PR

This commit is contained in:
Lendemor 2024-04-08 21:26:53 +02:00
parent 5b283baef4
commit 60798ed1a1
5 changed files with 10 additions and 7 deletions

View File

@ -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();

View File

@ -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()),

View File

@ -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):

View File

@ -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

View File

@ -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.