mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-19 22:09:37 +00:00
Backport of #9037 to `cloud/1.39` Automatically created by backport workflow. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-9044-backport-cloud-1-39-bugfix-Fix-node-replacements-not-loading-due-to-feature-flag-timi-30e6d73d36508174895fea354b910d46) by [Unito](https://www.unito.io) Co-authored-by: Jin Yi <jin12cc@gmail.com>
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import type { NodeReplacement, NodeReplacementResponse } from './types'
|
|
|
|
import { defineStore } from 'pinia'
|
|
import { computed, ref } from 'vue'
|
|
|
|
import { ServerFeatureFlag } from '@/composables/useFeatureFlags'
|
|
import { useSettingStore } from '@/platform/settings/settingStore'
|
|
import { api } from '@/scripts/api'
|
|
import { fetchNodeReplacements } from './nodeReplacementService'
|
|
|
|
export const useNodeReplacementStore = defineStore('nodeReplacement', () => {
|
|
const settingStore = useSettingStore()
|
|
const replacements = ref<NodeReplacementResponse>({})
|
|
const isLoaded = ref(false)
|
|
const isEnabled = computed(() =>
|
|
settingStore.get('Comfy.NodeReplacement.Enabled')
|
|
)
|
|
|
|
async function load() {
|
|
if (!isEnabled.value || isLoaded.value) return
|
|
if (!api.getServerFeature(ServerFeatureFlag.NODE_REPLACEMENTS, false))
|
|
return
|
|
|
|
try {
|
|
replacements.value = await fetchNodeReplacements()
|
|
isLoaded.value = true
|
|
} catch (error) {
|
|
console.error('Failed to load node replacements:', error)
|
|
}
|
|
}
|
|
|
|
function getReplacementFor(nodeType: string): NodeReplacement | null {
|
|
if (!isEnabled.value) return null
|
|
return replacements.value[nodeType]?.[0] ?? null
|
|
}
|
|
|
|
function hasReplacement(nodeType: string): boolean {
|
|
if (!isEnabled.value) return false
|
|
return !!replacements.value[nodeType]?.length
|
|
}
|
|
|
|
return {
|
|
replacements,
|
|
isLoaded,
|
|
isEnabled,
|
|
load,
|
|
getReplacementFor,
|
|
hasReplacement
|
|
}
|
|
})
|