o
    |V
hã  ã                   @   s<   d dl Z d dlZd dlZdedefdd„Zdefdd„ZdS )	é    NÚapp_detailsÚreturnc                 Ã   s
  |   dd¡}t |¡}t|tƒrƒd|v r|d }| d¡r't|ƒI dH }|S | d¡r.dS t ¡ }tj	 
|d| d¡¡}z!t|dd	d
}t |¡}W d  ƒ W |S 1 sWw   Y  W |S  tyo   td|› ƒ Y dS  tjy€   td|› ƒ Y dS w |S dS )aX  
    Load the API schema as JSON. If 'api_schema' in app_details is a dictionary containing a 'url' key,
    check if the URL starts with 'https'. If not, treat it as a relative path to the local_directory.
    If it starts with 'https', load JSON from the URL directly. Otherwise, return 'api_schema' directly 
    if it is a JSON object.
    Ú
api_schemaNÚurlzhttps://zhttp://zapp/api/v1/apps/sdk/jsonú/Úrzutf-8)ÚencodingzFile not found: zError decoding JSON from file: )ÚgetÚjsonÚloadsÚ
isinstanceÚdictÚ
startswithÚload_json_from_urlÚosÚgetcwdÚpathÚjoinÚlstripÚopenÚloadÚFileNotFoundErrorÚprintÚJSONDecodeError)r   Úapi_schema_strr   r   Úcurrent_directoryÚ
local_pathÚfile© r   ú7/var/www/html/moveengine/app/v1/libraries/jsonloader.pyÚload_api_schema_as_json   s:   €



ïÿ	÷	ùþr    r   c              
   Ã   sÄ   t  ¡ 4 I d H šL}| | ¡4 I d H š,}|jdkr4| ¡ I d H W  d   ƒI d H  W  d   ƒI d H  S td| › d|j› ƒ‚1 I d H sEw   Y  W d   ƒI d H  d S 1 I d H s[w   Y  d S )NéÈ   zFailed to load JSON from URL: z - Status Code: )ÚaiohttpÚClientSessionr	   Ústatusr
   Ú	Exception)r   ÚsessionÚresponser   r   r   r   ,   s   €
þÿü.ÿr   )r   r
   r"   r   r    Ústrr   r   r   r   r   Ú<module>   s
    '