@@ -4,12 +4,33 @@ import { addPriceBadgeToNode, hasModelInput } from "./model_price.js";
44// 用于存储模型类型的属性名(会被序列化保存到工作流中)
55const BIZYAIR_MODEL_TYPE_KEY = "bizyair_model_type" ;
66
7+ /**
8+ * 检查是否应该显示 API 节点价格徽章
9+ * @returns {boolean } 如果设置开启则返回 true,否则返回 false
10+ */
11+ function shouldShowApiPricingBadge ( ) {
12+ try {
13+ const app = document . querySelector ( "#vue-app" ) . __vue_app__ ;
14+ const pinia = app . config . globalProperties . $pinia ;
15+ const settingStore = pinia . _s . get ( "setting" ) ;
16+ const showApiPricing = settingStore . get ( "Comfy.NodeBadge.ShowApiPricing" ) ;
17+ return showApiPricing !== false ;
18+ } catch ( error ) {
19+ // 如果无法获取 store 或出错,默认返回 true(保持原有行为)
20+ return true ;
21+ }
22+ }
23+
724// 获取node 的模型配置input
825export async function applyBadgeToNode ( _this , forceRefresh = false ) {
26+ const shouldShowBadge = shouldShowApiPricingBadge ( ) ;
27+
928 // 如果不是强制刷新,优先从节点属性中恢复模型类型(用于工作流加载场景)
1029 if ( ! forceRefresh && _this . properties && _this . properties [ BIZYAIR_MODEL_TYPE_KEY ] ) {
1130 const modelType = _this . properties [ BIZYAIR_MODEL_TYPE_KEY ] ;
12- await addPriceBadgeToNode ( _this , modelType ) ;
31+ if ( shouldShowBadge ) {
32+ await addPriceBadgeToNode ( _this , modelType ) ;
33+ }
1334 return ;
1435 }
1536
@@ -38,9 +59,12 @@ export async function applyBadgeToNode(_this, forceRefresh = false) {
3859 }
3960 _this . properties [ BIZYAIR_MODEL_TYPE_KEY ] = modelType ;
4061
41- await addPriceBadgeToNode ( _this , modelType ) ;
62+ // 只有在设置开启时才添加badge
63+ if ( shouldShowBadge ) {
64+ await addPriceBadgeToNode ( _this , modelType ) ;
65+ }
4266
43- // 删除无用的outputs
67+ // 无论是否添加badge,都要删除无用的outputs
4468 _this . outputs = _this . outputs . filter (
4569 ( output ) => output . name !== hiddenOutput . name
4670 ) ;
0 commit comments