18
18
import signal
19
19
import nodes
20
20
21
- version = "V1.9 "
21
+ version = "V1.10 "
22
22
print (f"### Loading: ComfyUI-Manager ({ version } )" )
23
23
24
24
required_comfyui_revision = 1793
@@ -96,6 +96,7 @@ def run_script(cmd, cwd='.'):
96
96
js_path = os .path .join (comfy_path , "web" , "extensions" )
97
97
98
98
comfyui_manager_path = os .path .dirname (__file__ )
99
+ cache_dir = os .path .join (comfyui_manager_path , '.cache' )
99
100
local_db_model = os .path .join (comfyui_manager_path , "model-list.json" )
100
101
local_db_alter = os .path .join (comfyui_manager_path , "alter-list.json" )
101
102
local_db_custom_node_list = os .path .join (comfyui_manager_path , "custom-node-list.json" )
@@ -484,6 +485,44 @@ def setup_environment():
484
485
import urllib .request
485
486
486
487
488
+ def simple_hash (input_string ):
489
+ hash_value = 0
490
+ for char in input_string :
491
+ hash_value = (hash_value * 31 + ord (char )) % (2 ** 32 )
492
+
493
+ return hash_value
494
+
495
+
496
+ async def get_data_by_mode (mode , filename ):
497
+ try :
498
+ if mode == "local" :
499
+ uri = os .path .join (comfyui_manager_path , filename )
500
+ json_obj = await get_data (uri )
501
+ else :
502
+ uri = get_config ()['channel_url' ] + '/' + filename
503
+ cache_uri = str (simple_hash (uri ))+ '_' + filename
504
+ cache_uri = os .path .join (cache_dir , cache_uri )
505
+
506
+ if mode == "cache" :
507
+ if is_file_created_within_one_day (cache_uri ):
508
+ json_obj = await get_data (cache_uri )
509
+ else :
510
+ json_obj = await get_data (uri )
511
+ with open (cache_uri , "w" , encoding = 'utf-8' ) as file :
512
+ json .dump (json_obj , file , indent = 4 , sort_keys = True )
513
+ else :
514
+ uri = get_config ()['channel_url' ] + '/' + filename
515
+ json_obj = await get_data (uri )
516
+ with open (cache_uri , "w" , encoding = 'utf-8' ) as file :
517
+ json .dump (json_obj , file , indent = 4 , sort_keys = True )
518
+ except Exception as e :
519
+ print (f"[ComfyUI-Manager] Due to a network error, switching to local mode.\n => { filename } \n => { e } " )
520
+ uri = os .path .join (comfyui_manager_path , filename )
521
+ json_obj = await get_data (uri )
522
+
523
+ return json_obj
524
+
525
+
487
526
def get_model_dir (data ):
488
527
if data ['save_path' ] != 'default' :
489
528
if '..' in data ['save_path' ] or data ['save_path' ].startswith ('/' ):
@@ -609,14 +648,20 @@ def process_custom_node(item):
609
648
print (f"\x1b [2K\r Update check done." )
610
649
611
650
651
+ def is_file_created_within_one_day (file_path ):
652
+ if not os .path .exists (file_path ):
653
+ return False
654
+
655
+ file_creation_time = os .path .getctime (file_path )
656
+ current_time = datetime .datetime .now ().timestamp ()
657
+ time_difference = current_time - file_creation_time
658
+
659
+ return time_difference <= 86400
660
+
661
+
612
662
@server .PromptServer .instance .routes .get ("/customnode/getmappings" )
613
663
async def fetch_customnode_mappings (request ):
614
- if request .rel_url .query ["mode" ] == "local" :
615
- uri = local_db_extension_node_mappings
616
- else :
617
- uri = get_config ()['channel_url' ] + '/extension-node-map.json'
618
-
619
- json_obj = await get_data (uri )
664
+ json_obj = await get_data_by_mode (request .rel_url .query ["mode" ], 'extension-node-map.json' )
620
665
621
666
all_nodes = set ()
622
667
patterns = []
@@ -639,12 +684,8 @@ async def fetch_customnode_mappings(request):
639
684
@server .PromptServer .instance .routes .get ("/customnode/fetch_updates" )
640
685
async def fetch_updates (request ):
641
686
try :
642
- if request .rel_url .query ["mode" ] == "local" :
643
- uri = local_db_custom_node_list
644
- else :
645
- uri = get_config ()['channel_url' ] + '/custom-node-list.json'
687
+ json_obj = await get_data_by_mode (request .rel_url .query ["mode" ], 'custom-node-list.json' )
646
688
647
- json_obj = await get_data (uri )
648
689
check_custom_nodes_installed (json_obj , True )
649
690
650
691
update_exists = any ('custom_nodes' in json_obj and 'installed' in node and node ['installed' ] == 'Update' for node in
@@ -663,12 +704,8 @@ async def update_all(request):
663
704
try :
664
705
save_snapshot_with_postfix ('autosave' )
665
706
666
- if request .rel_url .query ["mode" ] == "local" :
667
- uri = local_db_custom_node_list
668
- else :
669
- uri = get_config ()['channel_url' ] + '/custom-node-list.json'
707
+ json_obj = await get_data_by_mode (request .rel_url .query ["mode" ], 'custom-node-list.json' )
670
708
671
- json_obj = await get_data (uri )
672
709
check_custom_nodes_installed (json_obj , do_update = True )
673
710
674
711
update_exists = any (item ['installed' ] == 'Update' for item in json_obj ['custom_nodes' ])
@@ -731,12 +768,11 @@ async def fetch_customnode_list(request):
731
768
732
769
if request .rel_url .query ["mode" ] == "local" :
733
770
channel = 'local'
734
- uri = local_db_custom_node_list
735
771
else :
736
772
channel = get_config ()['channel_url' ]
737
- uri = channel + '/custom-node-list.json'
738
773
739
- json_obj = await get_data (uri )
774
+ json_obj = await get_data_by_mode (request .rel_url .query ["mode" ], 'custom-node-list.json' )
775
+
740
776
check_custom_nodes_installed (json_obj , False , not skip_update )
741
777
742
778
for x in json_obj ['custom_nodes' ]:
@@ -766,15 +802,8 @@ async def fetch_alternatives_list(request):
766
802
else :
767
803
skip_update = False
768
804
769
- if request .rel_url .query ["mode" ] == "local" :
770
- uri1 = local_db_alter
771
- uri2 = local_db_custom_node_list
772
- else :
773
- uri1 = get_config ()['channel_url' ] + '/alter-list.json'
774
- uri2 = get_config ()['channel_url' ] + '/custom-node-list.json'
775
-
776
- alter_json = await get_data (uri1 )
777
- custom_node_json = await get_data (uri2 )
805
+ alter_json = await get_data_by_mode (request .rel_url .query ["mode" ], 'alter-list.json' )
806
+ custom_node_json = await get_data_by_mode (request .rel_url .query ["mode" ], 'custom-node-list.json' )
778
807
779
808
fileurl_to_custom_node = {}
780
809
@@ -813,12 +842,8 @@ def process_model(item):
813
842
814
843
@server .PromptServer .instance .routes .get ("/externalmodel/getlist" )
815
844
async def fetch_externalmodel_list (request ):
816
- if request .rel_url .query ["mode" ] == "local" :
817
- uri = local_db_model
818
- else :
819
- uri = get_config ()['channel_url' ] + '/model-list.json'
845
+ json_obj = await get_data_by_mode (request .rel_url .query ["mode" ], 'model-list.json' )
820
846
821
- json_obj = await get_data (uri )
822
847
check_model_installed (json_obj )
823
848
824
849
return web .json_response (json_obj , content_type = 'application/json' )
0 commit comments