Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
-
import shutil
|
| 4 |
import json
|
| 5 |
import time
|
| 6 |
|
|
@@ -49,7 +48,7 @@ remove_expired_files()
|
|
| 49 |
# --- Upload ---
|
| 50 |
st.header("📤 Upload de Arquivos")
|
| 51 |
|
| 52 |
-
categoria = st.selectbox("Selecione a categoria", CATEGORIES)
|
| 53 |
uploaded_files = st.file_uploader("Selecione arquivos", accept_multiple_files=True)
|
| 54 |
auto_delete = st.checkbox("Excluir automaticamente após 24 horas")
|
| 55 |
|
|
@@ -70,51 +69,53 @@ if uploaded_files:
|
|
| 70 |
st.success("Arquivos enviados com sucesso!")
|
| 71 |
st.rerun()
|
| 72 |
|
| 73 |
-
# --- Lista de Arquivos ---
|
| 74 |
-
st.header(
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
|
|
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
with
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
expirations.pop(key, None)
|
| 107 |
-
with open(EXPIRATION_FILE, "w") as f:
|
| 108 |
-
json.dump(expirations, f)
|
| 109 |
-
st.success(f"Arquivo '{file}' excluído.")
|
| 110 |
-
st.rerun()
|
| 111 |
-
|
| 112 |
-
with col3:
|
| 113 |
-
with open(os.path.join(folder, file), "rb") as f_obj:
|
| 114 |
-
if st.download_button("⬇ Baixar & Apagar", f_obj, file_name=file, key=f"download_delete_{categoria}_{file}"):
|
| 115 |
os.remove(os.path.join(folder, file))
|
| 116 |
expirations.pop(key, None)
|
| 117 |
with open(EXPIRATION_FILE, "w") as f:
|
| 118 |
json.dump(expirations, f)
|
| 119 |
-
st.success(f"Arquivo '{file}'
|
| 120 |
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
|
|
|
| 3 |
import json
|
| 4 |
import time
|
| 5 |
|
|
|
|
| 48 |
# --- Upload ---
|
| 49 |
st.header("📤 Upload de Arquivos")
|
| 50 |
|
| 51 |
+
categoria = st.selectbox("Selecione a categoria para upload", CATEGORIES)
|
| 52 |
uploaded_files = st.file_uploader("Selecione arquivos", accept_multiple_files=True)
|
| 53 |
auto_delete = st.checkbox("Excluir automaticamente após 24 horas")
|
| 54 |
|
|
|
|
| 69 |
st.success("Arquivos enviados com sucesso!")
|
| 70 |
st.rerun()
|
| 71 |
|
| 72 |
+
# --- Lista de Arquivos agrupada por pasta ---
|
| 73 |
+
st.header("📄 Arquivos Disponíveis")
|
| 74 |
|
| 75 |
+
for categoria in CATEGORIES:
|
| 76 |
+
folder = os.path.join(BASE_FOLDER, categoria)
|
| 77 |
+
files = os.listdir(folder)
|
| 78 |
|
| 79 |
+
st.subheader(f"📁 {categoria}")
|
| 80 |
+
|
| 81 |
+
if not files:
|
| 82 |
+
st.info("Nenhum arquivo na categoria.")
|
| 83 |
+
else:
|
| 84 |
+
for file in files:
|
| 85 |
+
st.write(f"**{file}**")
|
| 86 |
+
key = f"{categoria}|||{file}"
|
| 87 |
+
|
| 88 |
+
expira = expirations.get(key)
|
| 89 |
+
if expira:
|
| 90 |
+
restante = int(expira - time.time())
|
| 91 |
+
if restante > 0:
|
| 92 |
+
restante_horas = restante // 3600
|
| 93 |
+
restante_min = (restante % 3600) // 60
|
| 94 |
+
st.caption(f"⏳ Expira em {restante_horas}h {restante_min}min")
|
| 95 |
+
else:
|
| 96 |
+
st.caption("⚠ Expiração iminente")
|
| 97 |
+
|
| 98 |
+
col1, col2, col3 = st.columns(3)
|
| 99 |
+
|
| 100 |
+
with col1:
|
| 101 |
+
with open(os.path.join(folder, file), "rb") as f_obj:
|
| 102 |
+
st.download_button("⬇ Download", f_obj, file_name=file, key=f"down_{categoria}_{file}")
|
| 103 |
+
|
| 104 |
+
with col2:
|
| 105 |
+
if st.button("🗑 Excluir", key=f"delete_{categoria}_{file}"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
os.remove(os.path.join(folder, file))
|
| 107 |
expirations.pop(key, None)
|
| 108 |
with open(EXPIRATION_FILE, "w") as f:
|
| 109 |
json.dump(expirations, f)
|
| 110 |
+
st.success(f"Arquivo '{file}' excluído.")
|
| 111 |
st.rerun()
|
| 112 |
+
|
| 113 |
+
with col3:
|
| 114 |
+
with open(os.path.join(folder, file), "rb") as f_obj:
|
| 115 |
+
if st.download_button("⬇ Baixar & Apagar", f_obj, file_name=file, key=f"download_delete_{categoria}_{file}"):
|
| 116 |
+
os.remove(os.path.join(folder, file))
|
| 117 |
+
expirations.pop(key, None)
|
| 118 |
+
with open(EXPIRATION_FILE, "w") as f:
|
| 119 |
+
json.dump(expirations, f)
|
| 120 |
+
st.success(f"Arquivo '{file}' baixado e removido.")
|
| 121 |
+
st.rerun()
|