o
    i	                     @   s6   d dl Z d dlZd dlmZ d dlZG dd dZdS )    N)webc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
AppSettingsc                 C   s
   || _ d S N)user_manager)selfr    r   ./mnt/c/Users/fbmor/ComfyUI/app/app_settings.py__init__   s   
zAppSettings.__init__c              
   C   s   z	| j |d}W n ty } z
td t |d }~ww tj	|rSzt
|}t|W  d    W S 1 s<w   Y  W d S    td|  i  Y S i S )Ncomfy.settings.jsonzUser settings not found.z%The user settings file is corrupted: )r   get_request_user_filepathKeyErrorloggingerrorr   HTTPUnauthorizedospathisfileopenjsonload)r   requestfileefr   r   r   get_settings   s&   


(zAppSettings.get_settingsc                 C   sR   | j |d}t|d}|tj|dd W d    d S 1 s"w   Y  d S )Nr
   w   )indent)r   r   r   writer   dumps)r   r   settingsr   r   r   r   r   save_settings   s   "zAppSettings.save_settingsc                    s\   | d fdd}| d fdd}|d fdd}|d fd	d
}d S )Nz	/settingsc                    s   t  | S r   )r   json_responser   )r   r   r   r   r   %   s   z,AppSettings.add_routes.<locals>.get_settingsz/settings/{id}c                    s<   d }  | }| jdd }|r||v r|| }t|S )Nid)r   
match_infogetr   r"   )r   valuer    
setting_idr#   r   r   get_setting)   s   

z+AppSettings.add_routes.<locals>.get_settingc                    s:     | }|  I d H } | i || tjddS )N   status)r   r   r!   r   Response)r   r    new_settingsr#   r   r   post_settings2   s
   
z-AppSettings.add_routes.<locals>.post_settingsc                    sT   | j dd }|stjddS  | }|  I d H ||<  | | tjddS )Nr$   i  r+   r*   )r%   r&   r   r-   r   r   r!   )r   r(   r    r#   r   r   post_setting9   s   
z,AppSettings.add_routes.<locals>.post_setting)r&   post)r   routesr   r)   r/   r0   r   r#   r   
add_routes$   s   zAppSettings.add_routesN)__name__
__module____qualname__r	   r   r!   r3   r   r   r   r   r      s
    r   )r   r   aiohttpr   r   r   r   r   r   r   <module>   s
    