o
    Ah                     @   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rd|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
    '