add acounts
This commit is contained in:
6
reflex_app/.gitignore
vendored
Normal file
6
reflex_app/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
*.db
|
||||
assets/external/
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
.states
|
||||
.web
|
||||
0
reflex_app/reflex_app/__init__.py
Normal file
0
reflex_app/reflex_app/__init__.py
Normal file
81
reflex_app/reflex_app/reflex_app.py
Normal file
81
reflex_app/reflex_app/reflex_app.py
Normal file
@@ -0,0 +1,81 @@
|
||||
import reflex as rx
|
||||
import requests
|
||||
|
||||
API_URL = "http://127.0.0.1:8000"
|
||||
|
||||
class State(rx.State):
|
||||
storage_status: dict = {}
|
||||
upload_files: list[str]
|
||||
download_link: str = ""
|
||||
|
||||
@rx.var
|
||||
def total_space_gb(self) -> str:
|
||||
total = self.storage_status.get("total_space", 0)
|
||||
return f"{total / (1024**3):.2f} GB"
|
||||
|
||||
@rx.var
|
||||
def used_space_gb(self) -> str:
|
||||
used = self.storage_status.get("used_space", 0)
|
||||
return f"{used / (1024**3):.2f} GB"
|
||||
|
||||
@rx.var
|
||||
def free_space_gb(self) -> str:
|
||||
free = self.storage_status.get("free_space", 0)
|
||||
return f"{free / (1024**3):.2f} GB"
|
||||
|
||||
def get_storage_status(self):
|
||||
try:
|
||||
response = requests.get(f"{API_URL}/api/storage-status")
|
||||
response.raise_for_status()
|
||||
self.storage_status = response.json()
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"Error fetching storage status: {e}")
|
||||
|
||||
async def handle_upload(self, files: list[rx.UploadFile]):
|
||||
for file in files:
|
||||
upload_data = await file.read()
|
||||
files = {'file': (file.filename, upload_data, file.content_type)}
|
||||
|
||||
try:
|
||||
response = requests.post(f"{API_URL}/api/upload-file", files=files)
|
||||
response.raise_for_status()
|
||||
self.download_link = response.json().get("download_link", "")
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"Error uploading file: {e}")
|
||||
|
||||
def index():
|
||||
return rx.container(
|
||||
rx.heading("MultiDrive Box", size="9"),
|
||||
rx.hstack(
|
||||
rx.button("Refresh Status", on_click=State.get_storage_status),
|
||||
rx.link(
|
||||
rx.button("Add Account"),
|
||||
href=f"{API_URL}/api/add-account",
|
||||
is_external=True,
|
||||
),
|
||||
),
|
||||
rx.box(
|
||||
rx.text(f"Total Space: {State.total_space_gb}"),
|
||||
rx.text(f"Used Space: {State.used_space_gb}"),
|
||||
rx.text(f"Free Space: {State.free_space_gb}"),
|
||||
),
|
||||
rx.upload(
|
||||
rx.text("Drag and drop files here or click to select files."),
|
||||
id="upload",
|
||||
),
|
||||
rx.button(
|
||||
"Upload", on_click=State.handle_upload(rx.upload_files(upload_id="upload"))
|
||||
),
|
||||
rx.cond(
|
||||
State.download_link,
|
||||
rx.link(
|
||||
"Download File",
|
||||
href=API_URL + State.download_link,
|
||||
is_external=True
|
||||
)
|
||||
),
|
||||
padding="2em",
|
||||
)
|
||||
|
||||
app = rx.App()
|
||||
app.add_page(index)
|
||||
2
reflex_app/requirements.txt
Normal file
2
reflex_app/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
reflex==0.8.0
|
||||
5
reflex_app/rxconfig.py
Normal file
5
reflex_app/rxconfig.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import reflex as rx
|
||||
|
||||
config = rx.Config(
|
||||
app_name="reflex_app",
|
||||
)
|
||||
Reference in New Issue
Block a user