
    h                     b    d dl mZmZ d dlZd dlmZ d dlmZmZm	Z	m
Z
 d dlmZ  G d de      Zy)    )BinaryIOListN)	BaseUTApi)DeleteFileResponseListFileResponseUploadResultUsageInfoResponse)snakifyc                       e Zd ZdZ	 	 ddedededz  dedef
dZ	 	 dd	ee	e   z  d
ededz  de	e
   fdZ	 ddee	e   z  dedz  defdZ	 ddedz  dedz  defdZdefdZy)UTApizSynchronous UploadThing API client.

    This class provides synchronous methods for interacting with the
    UploadThing API. Use this client for standard synchronous operations.
    Nmethodpathdatatimeoutreturnc                 (   | j                  |||      \  }}}|xs i }|j                  d|i       	 t        j                         5 } |j                  d|||d|}	|	j                          t        |	j                               }
t        |
t              r|
cddd       S t        d      # 1 sw Y   yxY w# t        j                  $ r t        j                  d| d| d      dt        j                  $ r}| j                  |        d}~ww xY w)	a  Make an HTTP request to the UploadThing API.

        Args:
            method: HTTP method to use
            path: API endpoint path
            data: Request data/parameters
            timeout: Request timeout in seconds

        Returns:
            dict: Parsed JSON response

        Raises:
            httpx.TimeoutException: If the request times out
            httpx.HTTPStatusError: If the server returns an error status
        r   )r   urlheadersNzExpected dict responsezRequest to z timed out after z seconds )_prepare_requestupdatehttpxClientrequestraise_for_statusr
   json
isinstancedict	TypeErrorTimeoutExceptionHTTPStatusError_handle_error_response)selfr   r   r   r   r   r   request_kwargsclientresponseresultes               O/var/www/Befach/backend/env/lib/python3.12/site-packages/upyloadthing/client.py_requestzUTApi._request   s)   , (,'<'<D$(
$Wn (-2y'23	 :6)6>> !sG?M ))+ 1fd+!: :   899: : %% 	((cU"3G9HE $$ 	''*	s=   B8 AB,	B8 !B,,B51B8 5B8 8AD:DDfilescontent_dispositionaclc           
      *   t        |t              s|g}|D cg c]  }| j                  |||       }}g }|D ]S  }| j                  d|d   d|d   |d   |d   fi      }t	        d	|d   |d   |d   |d   d|}	|j                  |	       U |S c c}w )
a  Upload one or more files to UploadThing synchronously.

        Args:
            files: Single file or list of files to upload (file-like objects)
            content_disposition: Content disposition header value ('inline' or 'attachment')
            acl: Access control list setting for uploaded files

        Returns:
            List[UploadResult]: List of upload results containing file information
        PUT
ingest_urlfilenametypefile_keysize)r4   r2   r5   r3   r   )r   list_prepare_file_datar*   r   append)
r#   r+   r,   r-   r1   
files_dataresults	file_datar'   upload_results
             r)   upload_fileszUTApi.upload_filesD   s      %&GE 
 ##D*=sC

 

 #I]],'!&)!&)!&)
F ) ":.v&v&v&	
 M NN=)) $, 9
s   Bkeyskey_typec                 ~    t        |t              r|gn|}|dk(  rdnd|i}| j                  dd|      }t        di |S )a7  Delete one or more files from UploadThing synchronously.

        Args:
            keys: Single key or list of keys identifying files to delete
            key_type: Type of key provided ('file_key' or 'custom_id')

        Returns:
            DeleteFileResponse: Response containing deletion results
        r4   fileKeys	customIdsPOSTz/v6/deleteFilesr   )r   strr*   r   )r#   r>   r?   	keys_listr   r'   s         r)   delete_fileszUTApi.delete_filesu   sN     )s3TF	"j0Jk9
 v'8$?!+F++    limitoffsetc                 ^    i }|r||d<   |r||d<   | j                  dd|      }t        di |S )a	  List files stored in UploadThing synchronously.

        Args:
            limit: Maximum number of files to return
            offset: Number of files to skip for pagination

        Returns:
            ListFileResponse: Response containing list of files
        rH   rI   rC   z/v6/listFilesr   )r*   r   )r#   rH   rI   paramsr&   s        r)   
list_fileszUTApi.list_files   sB     #F7O%F8==&A+(++rG   c                 <    | j                  dd      }t        di |S )zGet usage information for the UploadThing account synchronously.

        Returns:
            UsageInfoResponse: Response containing usage statistics
        rC   z/v6/getUsageInfor   )r*   r	   )r#   r'   s     r)   get_usage_infozUTApi.get_usage_info   s#     v'9: *6**rG   )Ng      >@)inlinezpublic-read)r4   )NN)__name__
__module____qualname____doc__rD   r   floatr*   r   r   r   r=   r   rF   intr   rL   r	   rN   r   rG   r)   r   r      s     !,, , Tk	,
 , 
,b $,'	/$x.(/ !/ 4Z	/
 
l	/d =G,$s)O,/2Tz,	,( >B,4Z,03d
,	,*+ 1 +rG   r   )typingr   r   r   upyloadthing.base_clientr   upyloadthing.schemasr   r   r   r	   upyloadthing.utilsr
   r   r   rG   r)   <module>rZ      s+    !  .  'U+I U+rG   