mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-27 03:19:56 +00:00
* knip: Don't ignore exports that are only used within a given file * knip: More pruning after rebase * knip: Vite plugin config fix * knip: vitest plugin config * knip: Playwright config, remove unnecessary ignores. * knip: Simplify project file enumeration. * knip: simplify the config file patterns ?(.optional_segment) * knip: tailwind v4 fix * knip: A little more, explain some of the deps. Should be good for this PR. * knip: remove unused disabling of classMembers. It's opt-in, which we should probably do. * knip: floating comments We should probably delete _one_ of these parallell trees, right? * knip: Add additional entrypoints * knip: Restore UserData that's exposed via the types for now. * knip: Add as an entry file even though knip says it's not necessary. * knip: re-export functions used by nodes (h/t @christian-byrne)
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import { api } from '@/scripts/api'
|
|
import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
|
|
import { NodeSourceType, getNodeSource } from '@/types/nodeSource'
|
|
import { extractCustomNodeName } from '@/utils/nodeHelpUtil'
|
|
|
|
class NodeHelpService {
|
|
async fetchNodeHelp(node: ComfyNodeDefImpl, locale: string): Promise<string> {
|
|
const nodeSource = getNodeSource(node.python_module)
|
|
|
|
if (nodeSource.type === NodeSourceType.CustomNodes) {
|
|
return this.fetchCustomNodeHelp(node, locale)
|
|
} else {
|
|
return this.fetchCoreNodeHelp(node, locale)
|
|
}
|
|
}
|
|
|
|
private async fetchCustomNodeHelp(
|
|
node: ComfyNodeDefImpl,
|
|
locale: string
|
|
): Promise<string> {
|
|
const customNodeName = extractCustomNodeName(node.python_module)
|
|
if (!customNodeName) {
|
|
throw new Error('Invalid custom node module')
|
|
}
|
|
|
|
// Try locale-specific path first
|
|
const localePath = `/extensions/${customNodeName}/docs/${node.name}/${locale}.md`
|
|
let res = await fetch(api.fileURL(localePath))
|
|
|
|
if (!res.ok) {
|
|
// Fall back to non-locale path
|
|
const fallbackPath = `/extensions/${customNodeName}/docs/${node.name}.md`
|
|
res = await fetch(api.fileURL(fallbackPath))
|
|
}
|
|
|
|
if (!res.ok) {
|
|
throw new Error(res.statusText)
|
|
}
|
|
|
|
return res.text()
|
|
}
|
|
|
|
private async fetchCoreNodeHelp(
|
|
node: ComfyNodeDefImpl,
|
|
locale: string
|
|
): Promise<string> {
|
|
const mdUrl = `/docs/${node.name}/${locale}.md`
|
|
const res = await fetch(api.fileURL(mdUrl))
|
|
|
|
if (!res.ok) {
|
|
throw new Error(res.statusText)
|
|
}
|
|
|
|
return res.text()
|
|
}
|
|
}
|
|
|
|
// Export singleton instance
|
|
export const nodeHelpService = new NodeHelpService()
|