Update app.py
Browse files
app.py
CHANGED
|
@@ -46,28 +46,54 @@ def remove_expired_files():
|
|
| 46 |
remove_expired_files()
|
| 47 |
|
| 48 |
# --- Upload ---
|
|
|
|
| 49 |
st.header("📤 Upload de Arquivos")
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
# --- Lista de Arquivos agrupada por pasta ---
|
| 73 |
st.header("📄 Arquivos Disponíveis")
|
|
|
|
| 46 |
remove_expired_files()
|
| 47 |
|
| 48 |
# --- Upload ---
|
| 49 |
+
|
| 50 |
st.header("📤 Upload de Arquivos")
|
| 51 |
|
| 52 |
+
st.subheader("Selecione uma categoria:")
|
| 53 |
+
|
| 54 |
+
# Checkboxes exclusivos
|
| 55 |
+
selection = {cat: False for cat in CATEGORIES}
|
| 56 |
+
|
| 57 |
+
cols = st.columns(len(CATEGORIES))
|
| 58 |
+
|
| 59 |
+
for i, cat in enumerate(CATEGORIES):
|
| 60 |
+
selection[cat] = cols[i].checkbox(cat)
|
| 61 |
+
|
| 62 |
+
# Garante que só um esteja selecionado
|
| 63 |
+
selected_cats = [cat for cat, checked in selection.items() if checked]
|
| 64 |
+
|
| 65 |
+
if len(selected_cats) > 1:
|
| 66 |
+
st.error("Selecione apenas uma categoria!")
|
| 67 |
+
categoria = None
|
| 68 |
+
elif len(selected_cats) == 0:
|
| 69 |
+
categoria = None
|
| 70 |
+
else:
|
| 71 |
+
categoria = selected_cats[0]
|
| 72 |
+
|
| 73 |
+
if categoria:
|
| 74 |
+
uploaded_files = st.file_uploader(
|
| 75 |
+
f"Selecione arquivos para '{categoria}'",
|
| 76 |
+
accept_multiple_files=True,
|
| 77 |
+
key=f"uploader_{categoria}"
|
| 78 |
+
)
|
| 79 |
+
auto_delete = st.checkbox("Excluir automaticamente após 24 horas")
|
| 80 |
+
|
| 81 |
+
if uploaded_files:
|
| 82 |
+
for uploaded_file in uploaded_files:
|
| 83 |
+
folder = os.path.join(BASE_FOLDER, categoria)
|
| 84 |
+
file_path = os.path.join(folder, uploaded_file.name)
|
| 85 |
+
with open(file_path, "wb") as f:
|
| 86 |
+
f.write(uploaded_file.read())
|
| 87 |
+
|
| 88 |
+
# Salvar expiração se marcada
|
| 89 |
+
if auto_delete:
|
| 90 |
+
key = f"{categoria}|||{uploaded_file.name}"
|
| 91 |
+
expirations[key] = time.time() + 24 * 60 * 60
|
| 92 |
+
with open(EXPIRATION_FILE, "w") as f:
|
| 93 |
+
json.dump(expirations, f)
|
| 94 |
+
|
| 95 |
+
st.success("Arquivos enviados com sucesso!")
|
| 96 |
+
st.rerun()
|
| 97 |
|
| 98 |
# --- Lista de Arquivos agrupada por pasta ---
|
| 99 |
st.header("📄 Arquivos Disponíveis")
|