fix(): Ajustado token para visualização de arquivos
This commit is contained in:
parent
d35d102bd1
commit
4b208ad03e
2 changed files with 21 additions and 2 deletions
|
|
@ -73,11 +73,23 @@ def generate_temporary_token(
|
|||
secret_key: str,
|
||||
algorithm: str,
|
||||
) -> str:
|
||||
|
||||
# Se for set, converte o primeiro elemento para string
|
||||
if isinstance(file_path, set):
|
||||
file_path = next(iter(file_path)) # pega o primeiro valor do set
|
||||
|
||||
# Se ainda não for string, força conversão
|
||||
file_path = str(file_path)
|
||||
|
||||
# Retorna a string separada por "/"
|
||||
file_path = file_path.split("/")
|
||||
|
||||
"""Gera um token JWT válido por poucos minutos."""
|
||||
expire = datetime.utcnow() + timedelta(minutes=expires_minutes)
|
||||
payload = {
|
||||
"sub": file_id,
|
||||
"filename": file_path, # caminho relativo completo
|
||||
"faixa_superior": file_path[0],
|
||||
"ato_id": file_path[1],
|
||||
"file_name": file_path[2], # caminho relativo completo
|
||||
"exp": expire,
|
||||
}
|
||||
return jwt.encode(payload, secret_key, algorithm=algorithm)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ URL_API = getattr(DB_SETTINGS, "url_api", None)
|
|||
# === Configuração do token temporário ===
|
||||
SECRET_KEY = getattr(DB_SETTINGS, "aeskey", None)
|
||||
ALGORITHM = "HS256"
|
||||
EXPIRE = 12
|
||||
|
||||
|
||||
class ShowAtosRepository:
|
||||
|
|
@ -119,6 +120,9 @@ class ShowAtosRepository:
|
|||
f"{URL_API}/view/{generate_storage_hash()}/"
|
||||
+ get_last_part({d.url.decode("utf-8")})
|
||||
+ "?token="
|
||||
+ generate_temporary_token(
|
||||
{d.url.decode("utf-8")}, EXPIRE, SECRET_KEY, ALGORITHM
|
||||
)
|
||||
if d.url
|
||||
else None
|
||||
),
|
||||
|
|
@ -185,6 +189,9 @@ class ShowAtosRepository:
|
|||
f"{URL_API}/view/{generate_storage_hash()}/"
|
||||
+ get_last_part({d.url.decode("utf-8")})
|
||||
+ "?token="
|
||||
+ generate_temporary_token(
|
||||
{d.url.decode("utf-8")}, EXPIRE, SECRET_KEY, ALGORITHM
|
||||
)
|
||||
if d.url
|
||||
else None
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue