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,
|
secret_key: str,
|
||||||
algorithm: str,
|
algorithm: str,
|
||||||
) -> 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."""
|
"""Gera um token JWT válido por poucos minutos."""
|
||||||
expire = datetime.utcnow() + timedelta(minutes=expires_minutes)
|
expire = datetime.utcnow() + timedelta(minutes=expires_minutes)
|
||||||
payload = {
|
payload = {
|
||||||
"sub": file_id,
|
"faixa_superior": file_path[0],
|
||||||
"filename": file_path, # caminho relativo completo
|
"ato_id": file_path[1],
|
||||||
|
"file_name": file_path[2], # caminho relativo completo
|
||||||
"exp": expire,
|
"exp": expire,
|
||||||
}
|
}
|
||||||
return jwt.encode(payload, secret_key, algorithm=algorithm)
|
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 ===
|
# === Configuração do token temporário ===
|
||||||
SECRET_KEY = getattr(DB_SETTINGS, "aeskey", None)
|
SECRET_KEY = getattr(DB_SETTINGS, "aeskey", None)
|
||||||
ALGORITHM = "HS256"
|
ALGORITHM = "HS256"
|
||||||
|
EXPIRE = 12
|
||||||
|
|
||||||
|
|
||||||
class ShowAtosRepository:
|
class ShowAtosRepository:
|
||||||
|
|
@ -119,6 +120,9 @@ class ShowAtosRepository:
|
||||||
f"{URL_API}/view/{generate_storage_hash()}/"
|
f"{URL_API}/view/{generate_storage_hash()}/"
|
||||||
+ get_last_part({d.url.decode("utf-8")})
|
+ get_last_part({d.url.decode("utf-8")})
|
||||||
+ "?token="
|
+ "?token="
|
||||||
|
+ generate_temporary_token(
|
||||||
|
{d.url.decode("utf-8")}, EXPIRE, SECRET_KEY, ALGORITHM
|
||||||
|
)
|
||||||
if d.url
|
if d.url
|
||||||
else None
|
else None
|
||||||
),
|
),
|
||||||
|
|
@ -185,6 +189,9 @@ class ShowAtosRepository:
|
||||||
f"{URL_API}/view/{generate_storage_hash()}/"
|
f"{URL_API}/view/{generate_storage_hash()}/"
|
||||||
+ get_last_part({d.url.decode("utf-8")})
|
+ get_last_part({d.url.decode("utf-8")})
|
||||||
+ "?token="
|
+ "?token="
|
||||||
|
+ generate_temporary_token(
|
||||||
|
{d.url.decode("utf-8")}, EXPIRE, SECRET_KEY, ALGORITHM
|
||||||
|
)
|
||||||
if d.url
|
if d.url
|
||||||
else None
|
else None
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue