U
    i                     @   s   d dl mZmZmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlZd dlZd dlZd dlZddlmZ edeZed	ed
ddZeded
ddZeded
ddZdS )    )Flaskrequestjsonify	send_fileafter_this_request	Blueprint)CORS)FTPUtils)PathN   )Ftp_ServiceFTPz/getPathFormat/<int:id_format>)	id_formatc                 C   s0   t j | }|rtd|dS tddddfS )NT)successpathFFormato no encontrador   message  )r   get_path_By_idr   )r   r    r   _C:\Users\victor.barrera\Documents\proyectos\elepV3\Elep\src\App\api\controller\FtpController.pyapi_get_path_format   s    r   zdownload/<int:id_format>c              	      s   t j | }|s"tddddfS t|jp.d}tj|d\} t| t	
| }|dstt t  W 5 Q R X td|ddd	fS t|d
t|jj}t|d pd}t fdd}t |d|ddS )NFr   r   r   z.bin)suffixr   r   i  Zremote_relativer   zapplication/octet-streamc              	      s$   t t t  W 5 Q R X | S )N)
contextlibsuppress	Exceptionosremove)resptmpr   r   _cleanup(   s    z#api_file_download.<locals>._cleanupT)mimetypeas_attachmentdownload_namemax_age)r   r   r   r
   r   tempfilemkstempr   closer	   Zdownload_filegetr   r   r   r   name	mimetypes
guess_typer   r   )r   r   r   fdresfilenamemimer"   r   r    r   api_file_download   s     

r2   z/isExist/<int:id_format>c                 C   s<   t j | }|s"tddddfS t|}td||dS )NFzFalta ?path=r   i  T)r   existsr   )r   r   r   r	   Zfile_exists)r   r   r3   r   r   r   api_file_exists1   s
    
r4   )flaskr   r   r   r   r   r   Z
flask_corsr   ZApp.Utilities_module.FTPUtilsr	   pathlibr
   r,   r'   r   r   servicesr   __name__routerr*   intr   r2   r4   r   r   r   r   <module>   s     
