
    +jK                        % S SK r S SKrS SKrS SKrS SKJrJr  S SKJr  S SK	J
r
  1 Skr\\   \S'   0 q\\\\\   \\   4   4   \S'   \
R&                  (       a&  \ R(                  R+                  \
R&                  5      rO4\ R(                  R/                  \ R(                  R1                  \5      5      r\ R(                  R5                  \S5      r\ R(                  R5                  \S	5      /\4[        S	'   \ R(                  R5                  \S
5      /S/4[        S
'   \ R(                  R5                  \S5      /\4[        S'   \ R(                  R5                  \S5      /\4[        S'   \ R(                  R5                  \S5      \ R(                  R5                  \S5      /\4[        S'   \ R(                  R5                  \S5      \ R(                  R5                  \S5      /\4[        S'   \ R(                  R5                  \S5      /\4[        S'   \ R(                  R5                  \S5      /\4[        S'   \ R(                  R5                  \S5      /\4[        S'   \ R(                  R5                  \S5      /S/4[        S'   \ R(                  R5                  \S5      /\4[        S'   \ R(                  R5                  \S5      \ R(                  R5                  \S5      /\4[        S'   \ R(                  R5                  \S5      /\4[        S'   \ R(                  R5                  \S5      /\4[        S'   \ R(                  R5                  \S5      /\4[        S'   \ R(                  R5                  \S5      /\" 5       4[        S'   \ R(                  R5                  \S5      /\4[        S'   \ R(                  R5                  \S5      /\4[        S'   \ R(                  R5                  \S 5      /S!14[        S '   \ R(                  R5                  \S"5      /\4[        S"'   \ R(                  R5                  \S#5      /\4[        S#'   \ R(                  R5                  \S$5      /\4[        S$'   \ R(                  R5                  \S%5      /\4[        S%'   \ R(                  R5                  \S&5      /\4[        S&'   \ R(                  R5                  \S'5      /\4[        S''   \ R(                  R5                  \S(5      /\4[        S('   \ R(                  R5                  \S)5      q\ R(                  R5                  \S*5      q\ R(                  R5                  \S+5      q\ R(                  R5                  \S,5      q0 q \\\\\   \\\!4   \!4   4   \S-'    " S. S/5      r"\"" 5       r#S0S1S2.q$S3\S4\4S5 jr%\ R(                  RM                  [<        5      (       d   \ RN                  " [<        5        S7\S4S4S8 jr)S9\S4S4S: jr*S;\S4S4S< jr+S4\4S= jr,S4\4S> jr-S4\4S? jr.S4\4S@ jr/SA\S4S4SB jr0SCr1SdSD\S4\4SE jjr2SF\S4\S-  4SG jr3SH\S4\S-  4SI jr4SJ\\   SK\\SL      S4\\   4SM jr5SD\S4\\\S-  4   4SN jr6SeSD\SO\S-  S4\4SP jjr7S4\84SQ jr9SfS3\SR\SS\8S4S4ST jjr:S3\S4\\   4SU jr;SeSV\SW\\   S-  S4\\\   \\\!4   4   4SX jjr<SJ\\   SY\\   S4\\   4SZ jr=S3\S[\S4\S-  4S\ jr>S3\S[\S4\4S] jr?S3\S4\\\   \\\!4   \!4   4S^ jr@S3\S4\\\   \\\!4   \!4   S-  4S_ jrAS3\S4\\   4S` jrBSgSa\S7\S4\\\\C\\4   4Sb jjrDS4\\   4Sc jrEg!   \RP                  " S65         GN= f)h    N)LiteralList)
Collection)args>   .pt.bin.pkl.pt2.pth.sft.ckpt.safetensorssupported_pt_extensionsfolder_names_and_pathsmodelscheckpointsconfigsz.yamllorasvaetext_encodersclipunetdiffusion_modelsclip_visionstyle_models
embeddings	diffusersfolder
vae_approx
controlnett2i_adaptergligenupscale_modelslatent_upscale_modelscustom_nodeshypernetworks
photomakerclassifiers model_patchesaudio_encodersbackground_removalframe_interpolationgeometry_estimationoptical_flow	detectionoutputtempinputuserfilename_list_cachec            	           \ rS rSrSrS rSS\S\\\   \	\\
4   \
4   4S jjrS\S\\\   \	\\
4   \
4   SS4S	 jrS
 rS rS rSrg)CacheHelperF   z1
Helper class for managing file list cache data.
c                      0 U l         SU l        g NF)cacheactiveselfs    ,/home/wildlama/comfy/ComfyUI/folder_paths.py__init__CacheHelper.__init__J   s    KM
    Nkeyreturnc                 ^    U R                   (       d  U$ U R                  R                  X5      $ N)r<   r;   get)r>   rC   defaults      r?   rG   CacheHelper.getN   s!    {{Nzz~~c++rB   valuec                 D    U R                   (       a  X R                  U'   g g rF   r<   r;   )r>   rC   rJ   s      r?   setCacheHelper.setS   s    ;;#JJsO rB   c                 8    U R                   R                  5         g rF   )r;   clearr=   s    r?   rP   CacheHelper.clearW   s    

rB   c                     SU l         U $ )NT)r<   r=   s    r?   	__enter__CacheHelper.__enter__Z   s    rB   c                 2    SU l         U R                  5         g r:   )r<   rP   )r>   exc_type	exc_value	tracebacks       r?   __exit__CacheHelper.__exit__^   s    

rB   rL   rF   )__name__
__module____qualname____firstlineno____doc__r@   strtuplelistdictfloatrG   rM   rP   rS   rY   __static_attributes__ rB   r?   r7   r7   F   s|    ,s ,U49d3:>NPU3U-V ,
$s $5cDe4De)K#L $QU $rB   r7   imagemodel)webpfbxfolder_namerD   c                 .    SSS.nUR                  X 5      $ )Nr   r   )r   r   )rG   )rk   legacys     r?   
map_legacyrn   i   s    (%'F::k//rB   z Failed to create input directory
output_dirc                     U q g rF   output_directory)ro   s    r?   set_output_directoryrs   t   s    !rB   temp_dirc                     U q g rF   temp_directory)rt   s    r?   set_temp_directoryrx   x       NrB   	input_dirc                     U q g rF   input_directory)rz   s    r?   set_input_directoryr~   |   s    OrB   c                      [         $ rF   rq   rf   rB   r?   get_output_directoryr      s    rB   c                      [         $ rF   rv   rf   rB   r?   get_temp_directoryr      s    rB   c                      [         $ rF   r|   rf   rB   r?   get_input_directoryr      s    rB   c                      [         $ rF   user_directoryrf   rB   r?   get_user_directoryr      s    rB   user_dirc                     U q g rF   r   )r   s    r?   set_user_directoryr      ry   rB   __namec                 Z   U (       a  [        U [        5      (       d  [        S5      eU R                  SS5      R	                  5       (       d  [        SU  S35      eU R                  S5      (       a  [        S5      e[        R                  R                  [        5       [         U  35      $ )a[  
Get the path to a System User directory.

System User directories (prefixed with '__') are only accessible via internal API,
not through HTTP endpoints. Use this for storing system-internal data that
should not be exposed to users.

Args:
    name: System user name (e.g., "system", "cache"). Must be alphanumeric
          with underscores allowed, but cannot start with underscore.

Returns:
    Absolute path to the system user directory.

Raises:
    ValueError: If name is empty, invalid, or starts with underscore.

Example:
    >>> get_system_user_directory("cache")
    '/path/to/user/__cache'
z System user name cannot be empty_r)   zInvalid system user name: ''z1System user name should not start with underscore)
isinstancer`   
ValueErrorreplaceisalnum
startswithospathjoinr   SYSTEM_USER_PREFIX)r   s    r?   get_system_user_directoryr      s    , z$,,;<<<<R ((**6tfA>??sLMM77<<*,1C0DTF.KLLrB   user_idc                     U (       a  [        U [        5      (       d  gU R                  [        5      (       a  g[        R
                  R                  [        5       U 5      $ )a6  
Get the path to a Public User directory for HTTP endpoint access.

This function provides structural security by returning None for any
System User (prefixed with '__'). All HTTP endpoints should use this
function instead of directly constructing user paths.

Args:
    user_id: User identifier from HTTP request.

Returns:
    Absolute path to the user directory, or None if user_id is invalid
    or refers to a System User.

Example:
    >>> get_public_user_directory("default")
    '/path/to/user/default'
    >>> get_public_user_directory("__system")
    None
N)r   r`   r   r   r   r   r   r   )r   s    r?   get_public_user_directoryr      sD    * *Wc22,--77<<*,g66rB   	type_namec                 d    U S:X  a
  [        5       $ U S:X  a
  [        5       $ U S:X  a
  [        5       $ g )Nr1   r2   r3   )r   r   r   )r   s    r?   get_directory_by_typer      s8    H#%%F!##G"$$rB   filescontent_types)rg   videoaudiorh   c                    / nU  H  nUR                  S5      S   nU[        ;  a>  [        R                  " USS9u  pVU(       d  MA  UR                  S5      S   nU[        U'   O	[        U   nXq;   d  Mo  UR	                  U5        M     U$ )z
Example:
    files = os.listdir(folder_paths.get_input_directory())
    videos = filter_files_content_types(files, ["video"])

Note:
    - 'model' in MIME context refers to 3D models, not files containing trained weights and parameters
.F)strict/r   )splitextension_mimetypes_cache	mimetypes
guess_typeappend)r   r   resultfile	extension	mime_typer   content_types           r?   filter_files_content_typesr      s     FJJsOB'	55$//UCLI$??3/2L3?%i04Y?L(MM$  MrB   c                     U R                  S5      (       a  [        5       nU S S n X4$ U R                  S5      (       a  [        5       nU S S n X4$ U R                  S5      (       a  [        5       nU S S n X4$ U S 4$ )Nz[output]iz[input]iz[temp]i)endswithr   r   r   )r   base_dirs     r?   annotated_filepathr      s    }}Z  ')CRy > 
y	!	!&(CRy > 
x	 	 %'CRy > TzrB   default_dirc                     [        U 5      u  pUc  Ub  UnO
[        5       n[        R                  R	                  X 5      $ rF   )r   r   r   r   r   )r   r   r   s      r?   get_annotated_filepathr     s:    '-ND""H*,H77<<''rB   c                     [        U 5      u  pUc
  [        5       n[        R                  R	                  X5      n[        R                  R                  U5      $ rF   )r   r   r   r   r   exists)r   r   filepaths      r?   exists_annotated_filepathr     sA    '-ND&(ww||H+H77>>(##rB   full_folder_path
is_defaultc                 :   [        U 5      n U [        ;   ar  [        U    u  p4X;   a6  U(       a.  US   U:w  a$  UR                  U5        UR                  SU5        g g g U(       a  UR                  SU5        g UR	                  U5        g U/[        5       4[        U '   g Nr   )rn   r   removeinsertr   rM   )rk   r   r   paths_extss        r?   add_model_folder_pathr   !  s    [)K,,-k:$eAh*::-.Q 01 ;z
 Q 01-.0@/A35.I{+rB   c                 6    [        U 5      n [        U    S   S S  $ r   )rn   r   )rk   s    r?   get_folder_pathsr   3  s!    [)K!+.q1!44rB   	directoryexcluded_dir_namesc                    [         R                  R                  U 5      (       d  / 0 4$ Uc  / n/ n0 n [         R                  R                  U 5      X0'   [
        R                  " SR                  U 5      5        [         R                  " U SSS9 H  u  pEnU Vs/ s H  owU;  d  M
  UPM     snUS S & U HR  n [         R                  R                  [         R                  R                  XH5      U 5      n	UR                  U	5        MT     U HD  n[         R                  R                  XG5      n
 [         R                  R                  U
5      X:'   MF     M     [
        R                  " SR                  [        U5      5      5        X#4$ ! [         a    [
        R                  " SU  S35         GN\f = fs  snf !   [
        R                  " SU S35         GM%  = f! [         a    [
        R                  " SU
 S35         M  f = f)NzWarning: Unable to access z. Skipping this path.z#recursive file list on directory {}T)followlinkstopdownz. Skipping this file.zfound {} files)r   r   isdirgetmtimeFileNotFoundErrorloggingwarningdebugformatwalkrelpathr   r   len)r   r   r   dirsdirpathsubdirs	filenamesd	file_namerelative_pathr   s              r?   recursive_searchr   7  s   77==##2v!FDW''**95 MM7>>yIJ
 (*wwydTX'Y#)!(HA5G,GaH
"I "W0PR[ \m, # AW0DWW--d3
  (Z" MM"))#f+67<5  W4YK?TUVW I
"<YKG\ ]^ % "<TFBW XYs<   !F	 	F4&F48AF9/!G	$F10F19G$HH
extensionsc                 H   ^ [        [        [        U4S jU 5      5      5      $ )Nc                    > [         R                  R                  U 5      S   R                  5       T;   =(       d    [	        T5      S:H  $ )Nr   r   )r   r   splitextlowerr   )ar   s    r?   <lambda>)filter_files_extensions.<locals>.<lambda>a  s<    (8(8(;B(?(E(E(G:(U(mY\]gYhlmYm(mrB   )sortedrb   filter)r   r   s    `r?   filter_files_extensionsr   `  s    $vmotuvwwrB   filenamec                    [        U 5      n U [        ;  a  g[        U    n[        R                  R	                  [        R                  R                  SU5      S5      nUS    H  n[        R                  R                  X15      n[        R                  R                  U5      (       a  Us  $ [        R                  R                  U5      (       d  Mp  [        R                  " SR                  U5      5        M     g);
Get the full path of a file in a folder, has to be a file
Nr   r   z;WARNING path {} exists but doesn't link anywhere, skipping.)rn   r   r   r   r   r   isfileislinkr   r   r   )rk   r   foldersx	full_paths        r?   get_full_pathr   e  s    
 [)K00$[1Gwwrww||C:C@HQZGGLL-	77>>)$$WW^^I&&OOY``ajkl  rB   c                 F    [        X5      nUc  [        SU  SU S35      eU$ )r   zModel in folder 'z' with filename 'z' not found.)r   r   )rk   r   r   s      r?   get_full_path_or_raiser   y  s9     k4I"3K=@QRZQ[[g hiirB   c                    [        U 5      n [        5       n[        U    n0 nUS    H3  n[        US/S9u  pVUR	                  [        XRS   5      5        0 UEUEnM5     [        [        U5      5      U[        R                  " 5       4$ )Nr   z.git)r      )
rn   rM   r   r   updater   r   rb   timeperf_counter)rk   output_listr   output_foldersr   r   folders_alls          r?   get_filename_list_r     s    [)K%K$[1GNQZ-aVHM25!*EF:N:k: 
 ${#$nd6G6G6IIIrB   c                 x   [         R                  U 5      nUb  U$ [        U 5      n U [        ;  a  g [        U    nUS    H2  nUS   U   nUn[        R
                  R                  U5      U:w  d  M2    g    [        U    nUS    H3  n[        R
                  R                  U5      (       d  M)  X2S   ;  d  M3    g    U$ )Nr   r   )	cache_helperrG   rn   r5   r   r   r   r   r   )rk   strong_cacheoutr   time_modifiedr   r   s          r?   cached_filename_list_r    s    ##K0L [)K--
k
*CVAq	77F#}4	  %[1GQZ77==A 
 JrB   c                     [        U 5      n [        U 5      nUc  [        U 5      nU[        U '   [        R                  X5        [        US   5      $ r   )rn   r  r   r5   r  rM   rb   )rk   r  s     r?   get_filename_listr    sL    [)K

,C
{ -+.K([&A<rB   filename_prefixc                 X  ^ ^
 S[         S[        [        [         4   4U 4S jjnS[         S[        S[        S[         4S jnST ;   a	  U" T X#5      m [        R                  R                  [        R                  R                  T 5      5      n[        R                  R                  [        R                  R                  T 5      5      m
[        R                  R                  X5      n[        R                  R                  U[        R                  R                  U5      45      U:w  a  S	[        R                  R                  U5      -   S
-   U-   S-   [        R                  R                  U[        R                  R                  U5      45      -   n[        R                  " U5        [        U5      e [        [        U
4S j[!        U[        R"                  " U5      5      5      5      S   S-   n	UT
XT 4$ ! [$         a    Sn	 N[&         a    [        R(                  " USS9  Sn	 N6f = f)Nr   rD   c                    > [        [        R                  R                  T5      5      nU S US-    n XS-   S  nUR	                  S5      S   n[        UR	                  S5      S   5      nXR4$ !   Sn XR4$ = f)Nr   r   r   r   )r   r   r   basenamer   int)r   
prefix_lenprefix	remainderbase_remainderdigitsr	  s         r?   map_filename)get_save_image_path.<locals>.map_filename  s    ))/:;
/:>*	 a1I&__S1!4N--c2156F ~	F~s   8A. .A6r3   image_widthimage_heightc                    U R                  S[        U5      5      n U R                  S[        U5      5      n [        R                  " 5       nU R                  S[        UR                  5      5      n U R                  S[        UR
                  5      R                  S5      5      n U R                  S[        UR                  5      R                  S5      5      n U R                  S[        UR                  5      R                  S5      5      n U R                  S[        UR                  5      R                  S5      5      n U R                  S	[        UR                  5      R                  S5      5      n U $ )
Nz%width%z%height%z%year%z%month%   z%day%z%hour%z%minute%z%second%)r   r`   r   	localtimetm_yeartm_monzfilltm_mdaytm_hourtm_mintm_sec)r3   r  r  nows       r?   compute_vars)get_save_image_path.<locals>.compute_vars  s   i[)9:j#l*;<nnhCKK(89iSZZ)>)>q)ABgs3;;'7'='=a'@AhCKK(8(>(>q(ABj#cjj/*?*?*BCj#cjj/*?*?*BCrB   %zX**** ERROR: Saving image outside the output folder is not allowed.
 full_output_folder: z
         output_dir: z
         commonpath: c                    > [         R                  R                  U S   S S 5      [         R                  R                  T5      :H  =(       a    U S   S   S:H  $ )Nr   r   r   )r   r   normcase)r   r   s    r?   r   %get_save_image_path.<locals>.<lambda>  sN    rww'7'7!Sb	'BbggFVFVW_F`'`'tefgheijlemqtet'trB   r   r   T)exist_ok)r`   ra   r  r   r   dirnamenormpathr  r   
commonpathabspathr   error	Exceptionmaxr   maplistdirr   r   makedirs)r	  ro   r  r  r  r"  	subfolderfull_output_foldererrcounterr   s   `         @r?   get_save_image_pathr7    s    	s 	uS#X 	
C 
c 
 
 
 o&R 0 0 ABIww 0 0 ABHj<	ww:rww7I'JKLPZZ(*,''//:L*MN'(*45 (( +-''*<*<j"''//ZlJm=n*op 	cnftvy  {G  IK  IS  IS  Tf  Ig  wh  i  j  kl  m  pq  q x_LL   
&6s   5=G8 8H) H)(H)c                     [        5       n / n [        R                  R                  U 5      (       d  / $ [        R                  " U 5       H\  u  p#n[        R                  R                  X 5      nUS:w  d  M-  UR                  UR                  [        R                  S5      5        M^     [        U5      $ ! [         a    / s $ f = f)zReturns a list of all subfolder paths in the input directory, recursively.

Returns:
    List of folder paths relative to the input directory, excluding the root directory
r   r   )r   r   r   r   r   r   r   r   sepr   r   )rz   r   rootr   r   rel_paths         r?   get_input_subfoldersr<    s     $%IGww~~i((IWWY/MDwwt7H3x//<=	 0 g 	s   %B5 ?B5 7=B5 5CC)systemrF   )F)r   r   )Fr   r   r   r   typingr   r   collections.abcr   comfy.cli_argsr   r   rM   r`   __annotations__r   rc   ra   rb   base_directoryr   r,  	base_pathr)  realpath__file__r   
models_dirrr   rw   r}   r   r5   rd   r7   r  r   rn   r   r2  r-  rs   rx   r~   r   r   r   r   r   r   r   r   r   r   r   r   boolr   r   r   r   r   r   r   r   r  r  r  r7  r<  rf   rB   r?   <module>rH     s   	      & $l S l@B S%S	3s8(;"<<= B  3 34I 0 0 :;IWW\\)X.
*,'',,z=*Q)RTk(l } %&(ggll:y&I%JWI$V y !$&GGLLW$E#FH_"` w "$'',,z5"A!BD[ \ u ,.GGLL_,UWYW^W^WcWcdnpvWw+x  {R  +S  '/1ww||J/OQSQXQXQ]Q]^hj|Q}.~  AX  .Y ) **,'',,z=*Q)RTk(l } %+-77<<
N+S*TVm)n ~ &)+j,)O(PRi'j | $(*Z(M'NQYPZ&[ { #)+j,)O(PRi'j | $)+j,)OQSQXQXQ]Q]^hjwQx(y  |S  (T | $%'WW\\*h%G$HJa#b x  -/WW\\*FV-W,XZq+r ' (46GGLLMd4e3fh  3A . /+-77<<	>+R*SUXUZ)[ ~ &,.GGLL_,U+VXo*p  ')+j,)O(PRi'j | $*,'',,z=*Q)RUWTX(Y } %,.GGLL_,U+VXo*p  '-/WW\\*FV-W,XZq+r ' (13jJ^1_0`by/z + ,24'',,zK`2a1bd{0| , -24'',,zK`2a1bd{0| , -+-77<<
N+S*TVm)n ~ &(*Z(M'NPg&h { #77<<	84 i0'',,y'2i0LN T#uT#YS%Z0@%%GHHI N 8 }  
0C 0C 0
 
ww~~o&&:
O$"S "T "   3  4  c C S C     MC Ms M>7s 7sTz 7:S S4Z d3i WMoEp@q vz{~v 8S U3d
?%;  	( 	(3: 	(s 	($t $Js Jc Jt J`d J$5# 5$s) 5' 'cT9I 'SXY]^aYbdhilnsisdtYtSu 'Rx:c? x
3 xTXY\T] x
s c cDj ( s s JC JE$s)T#u*=Mu2T,U Js uT#YS%Z@PRW5W/X[_/_ 43 49 /M /M# /Mafgjloqtvy{~g~a /Mbd3i i:89s   ] ])