
    i                          d dl mZmZmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZmZmZ  e       Zej!                  d      d        Zej%                  d ee
      g       e ed	            fd
efd       Zy)    )	APIRouterRequestDependsJSONResponse)requires_permissionassert_actor_match)verify_turnstile)response_errorresponse_successstore_uploaded_file_contentz/uploadc                  $   K   t        dd      S w)NOK   )contentstatus_coder        C/var/www/pod-logistic/pod-api/controller/admin/upload_controller.pyupload_optionsr      s     #66s   )dependenciesproduct_managementrequestc                   K   t        || j                  j                  d             | j                          d {   }t	        |j                  dd            j                         }t	        |j                  dd            j                         }t	        |j                  dd            j                         }|dk(  r|r|dvrt        d      S |d	k(  rd
nd}ddlm	} dd l
}|j                  j                  |||      }	|j                  j                  |	      r 	 |j                  |	       t        d|d      S t        d      S |dvrt        d      S |d	k(  }
|
rd
nd}|
r|j#                  d      }|st        d      S g }|D ]Q  }|j$                  s|j'                          d {   }t)        |j$                  ||d      }|j+                  |       S t        |D cg c]  }|d   	 c}      S |j                  d      }|r|j$                  st        d      S |j'                          d {   }t)        |j$                  ||d      }t        |d   g      S 7 $# t         $ r t        d      cY S w xY w7 c c}w 7 Pw)Nz
x-actor-idaction typefileName
deletefile)img
file_excelu"   Thông tin xóa không hợp lệ.r    
upload_imgupload_file_excelr   )UPLOADS_DIRT)deletedfileu   Không thể xoá file.u   File không tồn tại.u&   Thiếu hoặc sai loại file (type).filesu   Không tìm thấy file ảnh.)sub_diris_imgpathr&   u   Không tìm thấy file excel.F)r	   headersgetformstrlowerstripr   utils.upload_helperr$   osr*   joinisfileremover   	Exceptiongetlistfilenamereadr   append)r   current_user	form_datar   req_type	file_namer(   r$   r2   	file_pathr)   r'   savedfile_objr   
saved_infoss                    r   handle_requestrD      sj    
 |W__%8%8%FGlln$Ix,-335F9==,-335HIMM*b1288:IH,AA!"FGG"*e"3,9L3GGLLgyA	77>>)$A		)$'D)(LMM 899,,FGGF$l*=G!!'*!"BCC 	%H$$$MMO+G4!!	J LL$	%  E :q6 :;;}}V$H8,,>??MMO#G,	J Z/011y %$  A%&?@@A( , !; $s`   9JIC JI" ;A-J(I<)9J"I>.AJ2J3-J"I96J8I99J>JN)fastapir   r   r   fastapi.responsesr   utils.auth_helperr   r	   utils.turnstile_helperr
   r1   r   r   r   routeroptionsr   postrD   r   r   r   <module>rL      s    / / * E 3  
	7 7 Yg.>&?%@A ,-ABCB2B2 BB2r   