
    Ii                        d dl mZ d dlmZ d dlmZ d dlmZ  e       Zedefd       Z	 eddd	e	
      Z
e
j                  eej                  j                  d      ddgdg       e
j                  d      d        Zd dlmZ e
j%                  eej&                         d dlmZ d dlmZ d dlmZ e
j                  d      ddededz  defd       Zy)    )asynccontextmanager)FastAPI)CORSMiddleware)get_settingsappc                B   K   t        d       d  t        d       y w)Nu+   🚀 DWA AI Adoption Tracker starting up...u   👋 Shutting down...)print)r   s    /code/app/main.pylifespanr      s      

78		
!"s   zDWA AI Adoption TrackerzEEnterprise platform for tracking and gamifying AI adoption across DWAz0.1.0)titledescriptionversionr   ,T*)allow_originsallow_credentialsallow_methodsallow_headersz/healthc                     K   dddS w)Nhealthyzdwa-ai-tracker)statusservice r       r
   healthr   &   s     ,<==s   )
api_router)prefix)router)Request)RedirectResponsez/r/{short_code}N
short_codeuidrequestc           	        K   ddl m} ddlm}  |       4 d{   } ||| ||r|j                  j                  d      nd|r"|j                  r|j                  j                  nd       d{   }|j                          d{    |sddl	m
}  |dd	
      t        |j                  d      cddd      d{    S 7 7 X7 B7 # 1 d{  7  sw Y   yxY ww)z>Root-level redirect for tracked links (no /api prefix needed).r   )async_session)log_content_accessNz
user-agent)r!   
user_email
user_agent
ip_address)HTTPExceptioni  zLink not found)status_codedetaili.  )urlr+   )app.databaser%   app.services.content_trackerr&   headersgetclienthostcommitfastapir*   r    destination_url)r!   r"   r#   r%   r&   dblinkr*   s           r
   root_redirectr9   7   s      +?"'!<Cw**<8.5'..w~~**d
 
 iik-C8HIID$8$8cJ 
 	 si   C$CC$AC0C	1CC	,C5C$CC$	CCC$C!CC!C$)NN)
contextlibr   r5   r   fastapi.middleware.corsr   
app.configr   settingsr   r   add_middlewarecors_originssplitr1   r   app.api.routerr   include_router
api_prefixapp.api.contentr   content_redirect_routerr   fastapi.responsesr    strr9   r   r   r
   <module>rH      s   *  2 #> # # # 
#W	   ''--c2%%   > >
 &   :h&9&9  : >  .	KC KcDj K' K Kr   