
    gg                     V    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Z	h dZ
d Zd ZdS )	    N)requestjsonify)Image)secure_filenamez!/var/www/wisegym.app/api/data/pfp>   gifjpgpngjpegc                 t    d| v o4|                      dd          d                                         t          v S )N.   )rsplitlowerALLOWED_EXTENSIONS)filenames    0/var/www/wisegym.app/api/functions/upload_pfp.pyallowed_filer   
   s6    (?WxsA66q9??AAEWWW    c                     	 dt           j        vsdt           j        vrt          ddi          dfS t           j        d         } t           j        d         }| j        dk    st          | j                  st          ddi          dfS | j                            d          st          dd	i          dfS | j                            d
d          d         	                                }t          | d          }| d
| }t          j                            t          |          }t          D ]_}t          j                            t          | d
|           }t          j                            |          rt          j        |           `|                     |           	 t'          j        |          5 }|j        \  }	}
|	dk     s|
dk     r3t          j        |           t          ddi          dfcd d d            S |	dk    s|
dk    r3t          j        |           t          ddi          dfcd d d            S 	 d d d            n# 1 swxY w Y   n># t,          $ r1}t          j        |           t          ddi          dfcY d }~S d }~ww xY wt          d|d| d          dfS # t,          $ r>}t/          j                     t          dt3          |          d          dfcY d }~S d }~ww xY w)NfileusernameerrorzMissing file or usernamei   zInvalid filezimage/z'Invalid file type. Only images allowed.r   r   _pfpd   z%Image too small. Min size: 100x100px.i  z'Image too large. Max size: 1000x1000px.zInvalid image format.successz!https://api.wisegym.app/data/pfp/)statusr   url   zInternal error)r   detailsi  )r   filesformr   r   r   mimetype
startswithr   r   r   ospathjoinUPLOAD_FOLDERr   existsremovesaver   opensize	Exception	traceback	print_excstr)r   r   ext	safe_baser   	save_pathexisting_extold_pathimgwidthheightes               r   upload_profile_picturer;      s   ,L&&*GL*H*HG%?@AA3FF}V$<
+=Bl4=&A&AG^455s::}''11 	VG%NOPPRUUUm""3**1-3355#x$5$5$566	''#''GLL99	. 	$ 	$Lw||Mi3P3P,3P3PQQHw~~h'' $	(###		)	DI&& ^# #v3;;&3,,Ii((("G-T#UVVX[[	^ ^ ^ ^ ^ ^ ^ ^
 4<<6D==Ii((("G-V#WXXZ]]^ ^ ^ ^ ^ ^ ^ ^
 $1^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^  	D 	D 	DIi   G%<=>>CCCCCCC	D AxAA
 
   	 	  L L L!1c!ffEEFFKKKKKKKLs   .J. AJ. ,J. 4C-J. "I 6=I3I  2I2I  I II II J. 
J"&JJ	J. JJ. .
K683K1+K61K6)r%   r/   flaskr   r   PILr   werkzeug.utilsr   r(   r   r   r;    r   r   <module>r@      s    				     " " " " " " " "       * * * * * *3222 X X X-L -L -L -L -Lr   