
    hP                         d dl Z d dlZd dlZd dlmZ 	 	 	 	 ddedededededed	edz  d
edz  dedz  dedz  defdZdededefdZy)    N)	urlencoderegion_aliasfile_keyapi_keyapp_id	file_name	file_size	file_type	custom_idcontent_dispositionaclreturnc
                     t        t        j                         dz        dz   }
|
|||d}|r||d<   |r||d<   |r||d<   |	r|	|d<   d|  d	| }t        |      }| d
| }t        ||      }| d| }|S )a  
    Constructs a pre-signed URL for uploading a file.

    This function creates a URL with signed query parameters for a file upload.
    It includes required and optional parameters, calculates an expiration
    time, encodes the URL, and appends an HMAC-SHA256 signature to ensure
    secure access to the upload endpoint.

    Args:
        region_alias (str): The region alias to be used in the URL (e.g.,
                            "us-east"). This is a subdomain for the base URL.
        file_key (str): The unique file key or identifier used in the URL path.
        api_key (str): The API key used to generate the HMAC-SHA256 signature.
        app_id (str): The application identifier.
        file_name (str): The name of the file being uploaded.
        file_size (int): The size of the file in bytes.
        file_type (str | None, optional): The MIME type of the file.
        custom_id (str | None, optional): An optional custom identifier for
        the file.
        content_disposition (str | None, optional): Content disposition
        directive.
        acl (str | None, optional): Access control list setting for the file.


    Returns:
        str: A fully constructed pre-signed URL including the signature that
        can be used to securely upload the file.
    i  i6 )expireszx-ut-identifierzx-ut-file-namezx-ut-file-sizezx-ut-file-typezx-ut-custom-idzx-ut-content-dispositionzx-ut-aclzhttps://z.ingest.uploadthing.com/?z&signature=)inttimer   hmac_sha256)r   r   r   r   r   r	   r
   r   r   r   r   paramsbase_urlencoded_paramsurl	signatureurl_with_signatures                    P/var/www/Befach/backend/env/lib/python3.12/site-packages/upyloadthing/presign.pymake_presigned_urlr      s    P $))+$%6G!##	F #, #, -@)*
 z ,'?zJH v&N Ja'
(C C)I  5I;7    r   c                     | j                  d      }|j                  d      }t        j                  ||t        j                        }|j                         }d| S )a  
    Calculates the HMAC-SHA256 signature of the given URL.

    This function takes the URL and an API key, then returns a signature
    string in the format required by UploadThing.

    Args:
        url (str): The URL string to be signed.
        api_key (str): The secret API key used to generate the HMAC signature.

    Returns:
        str: A string containing the HMAC-SHA256 signature prefixed with
             "hmac-sha256=".
    zutf-8zhmac-sha256=)encodehmacnewhashlibsha256	hexdigest)r   r   messagesecrethmac_objr   s         r   r   r   S   sQ     jj!G^^G$Fxx8H""$I)%%r   )NNinlinezpublic-read)	r"   r    r   urllib.parser   strr   r   r    r   r   <module>r,      s       " ! &.#III I 	I
 I I TzI TzI tI 
tI 	IX&S &3 &3 &r   