fix(): Ajuste arquivo main.py, aplicado rota estática para visualização de arquivos
This commit is contained in:
parent
4d1943f37f
commit
f2f5fc31cd
1 changed files with 2 additions and 35 deletions
37
main.py
37
main.py
|
|
@ -42,46 +42,13 @@ if not os.path.isdir(STORAGE_DIR):
|
|||
|
||||
# 3. Monte o diretório estático
|
||||
# Isso mapeia o caminho local STORAGE_DIR para o prefixo de URL '/storage-files'
|
||||
prefix = date.today().strftime("%Y%m%d")
|
||||
app.mount(
|
||||
"/storage-files", # <- ESTE É O PREFIXO DA URL PÚBLICA
|
||||
"/" + prefix, # <- ESTE É O PREFIXO DA URL PÚBLICA
|
||||
StaticFiles(directory=STORAGE_DIR),
|
||||
name="storage_access",
|
||||
)
|
||||
|
||||
# main.py (adicione abaixo do app.mount)
|
||||
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
|
||||
# [INÍCIO DO NOVO CÓDIGO DE DIAGNÓSTICO]
|
||||
@app.get(
|
||||
"/api/v1/storage-check"
|
||||
) # Note o prefixo /api/v1 (ou ajuste se o seu config.url for outro)
|
||||
def check_storage_path():
|
||||
storage_path = "/app/storage"
|
||||
|
||||
response_data = {
|
||||
"diretorio_montado": storage_path,
|
||||
"diretorio_existe": os.path.isdir(storage_path),
|
||||
"arquivo_alvo_existe": os.path.exists(
|
||||
os.path.join(storage_path, "Grantfile_jbpdy8ex.pdf")
|
||||
),
|
||||
"arquivos_encontrados": [],
|
||||
}
|
||||
|
||||
try:
|
||||
# Tenta listar o conteúdo da pasta
|
||||
response_data["arquivos_encontrados"] = os.listdir(storage_path)
|
||||
except FileNotFoundError:
|
||||
response_data["erro_listdir"] = "Diretório não encontrado pelo Python"
|
||||
except Exception as e:
|
||||
response_data["erro_listdir"] = f"Erro de permissão ou outro: {e}"
|
||||
|
||||
return JSONResponse(response_data)
|
||||
|
||||
|
||||
# [FIM DO NOVO CÓDIGO DE DIAGNÓSTICO]
|
||||
|
||||
# Adiciona o middleware global de erro
|
||||
# app.middleware("http")(database_error_handler)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue