fix(): Ajuste na função que retorna o hash para visualização do arquivo
This commit is contained in:
parent
c0e5808ec0
commit
f0dfec03dd
2 changed files with 32 additions and 2 deletions
|
|
@ -5,6 +5,31 @@ from datetime import date
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
|
||||||
|
# Separa a última parte de uma string com três partes separadas por "/"
|
||||||
|
def get_last_part(text: str) -> str:
|
||||||
|
"""
|
||||||
|
Separa uma string por "/" e retorna a última parte.
|
||||||
|
Exemplo: "100/15/arquivo.txt" -> "arquivo.txt"
|
||||||
|
|
||||||
|
Args:
|
||||||
|
text (str): String no formato com três partes separadas por "/"
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: Última parte da string (após a última "/")
|
||||||
|
"""
|
||||||
|
# Divide a string em partes
|
||||||
|
partes = text.split("/")
|
||||||
|
|
||||||
|
# Verifica se há pelo menos 3 partes
|
||||||
|
if len(partes) < 3:
|
||||||
|
raise ValueError(
|
||||||
|
"A string deve conter pelo menos três partes separadas por '/'."
|
||||||
|
)
|
||||||
|
|
||||||
|
# Retorna a última parte
|
||||||
|
return partes[-1]
|
||||||
|
|
||||||
|
|
||||||
# Função que gera o hash baseado na data atual
|
# Função que gera o hash baseado na data atual
|
||||||
def generate_storage_hash() -> str:
|
def generate_storage_hash() -> str:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ from packages.v1.administrativo.schemas.ato_principal_schema import (
|
||||||
from actions.validations.hash import (
|
from actions.validations.hash import (
|
||||||
generate_storage_hash,
|
generate_storage_hash,
|
||||||
generate_temporary_token,
|
generate_temporary_token,
|
||||||
|
get_last_part,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -115,7 +116,9 @@ class ShowAtosRepository:
|
||||||
documentos_list = [
|
documentos_list = [
|
||||||
{
|
{
|
||||||
"url": (
|
"url": (
|
||||||
f"{URL_API}/view/{generate_storage_hash()}/{d.url.decode('utf-8')}?token="
|
f"{URL_API}/view/{generate_storage_hash()}/"
|
||||||
|
+ get_last_part({d.url.decode("utf-8")})
|
||||||
|
+ "?token="
|
||||||
if d.url
|
if d.url
|
||||||
else None
|
else None
|
||||||
),
|
),
|
||||||
|
|
@ -179,7 +182,9 @@ class ShowAtosRepository:
|
||||||
documentos_vinc_list = [
|
documentos_vinc_list = [
|
||||||
{
|
{
|
||||||
"url": (
|
"url": (
|
||||||
f"{URL_API}/view/{generate_storage_hash()}/{d.url.decode('utf-8')}?token="
|
f"{URL_API}/view/{generate_storage_hash()}/"
|
||||||
|
+ get_last_part({d.url.decode("utf-8")})
|
||||||
|
+ "?token="
|
||||||
if d.url
|
if d.url
|
||||||
else None
|
else None
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue