o
    vqi%                  
   @   s   d Z ddlZddlZddlZddlmZ ddlZddlZddl	m
Z
mZ ddlmZ ddlmZ dedefd	d
ZdedededejfddZdededededejf
ddZdededefddZdedededefddZdS )z
dot
    N)HTTPException)#STUDIO_MODEL_API_URL_PREFIX_DEFAULTSALT)datetime)logsaltreturnc                 C   s$   | d|  }t |  }|S )z	get param_)hashlibmd5encode	hexdigest)r   api_timerawr    r   W/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/aistudio_sdk/dot.pygenerate_api_key   s   r   repo_idrevisionactionc              
   C   s   t }| d}tt d }tt|}d| dd|t|||d}ddi}ztj|||d	}	|	j	d
kr=t
d|	j	  |	W S  tyR }
 zW Y d}
~
dS d}
~
ww )	post infoz/modelcenter/v2/statistic/repoi  modeldownloadsdk)Zbiz_idr   Zac_typeZclient_typer   r   r   api_keyContent-Typeapplication/jsonjsonheaders   dot.response:N)r   inttimer   r   r   dumpsrequestspoststatus_coder   debug	Exception)r   r   r   addressurlr   r   payloadr   responseer   r   r   post_repo_statistic   s0   


r/   token	file_path	file_sizec              
   C   s   t }| d}t d}|d||| dd}||d}tj|dd}	d	d
i}
ztj||	|
d}|jdkr>t	
d|j  |W S  tyS } zW Y d}~dS d}~ww )r   z/studio-dot/reportz%Y-%m-%d %H:%M:%Sr   Z137)ZrepoIdZ
clientTypeZfilePathZfileSizer0   Zeid)r   r#   ),:)
separatorsr   r   r   r    r!   N)r   r   nowstrftimer   r$   r%   r&   r'   r   r(   r)   )r0   r   r1   r2   r*   r+   r   r   r,   Zcompact_jsonr   r-   r.   r   r   r   post_upload_statistic7   s2   
	
r8   c                 C   sD   t jjdd}|t| || W d   dS 1 sw   Y  dS z
    async
       )max_workersN)
concurrentfuturesThreadPoolExecutorsubmitr/   )r   r   r   executorr   r   r   post_repo_statistic_async\   s   "rA   c                 C   sF   t jjdd}|t| ||| W d   dS 1 sw   Y  dS r9   )r<   r=   r>   r?   r8   )r0   r   r1   r2   r@   r   r   r   post_upload_statistic_asyncf   s   	"rB   )__doc__concurrent.futuresr<   r#   r
   http.clientr   r%   r   Zaistudio_sdk.configr   r   r   Zaistudio_sdkr   strr   dictResponser/   r"   r8   rA   rB   r   r   r   r   <module>   sZ    
 
%

