mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-05 15:40:10 +00:00
- Replace direct fetch() with fetchWithHeaders across entire codebase - Replace axios.create() with createAxiosWithHeaders in all services - Update tests to properly mock network client adapters - Fix hoisting issues in test mocks for axios instances - Ensure all network calls now support header injection This completes Step 2: integrating the header registry infrastructure with all existing HTTP clients in the codebase.
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { api } from '@/scripts/api'
|
|
import { fetchWithHeaders } from '@/services/networkClientAdapter'
|
|
import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
|
|
import { NodeSourceType, getNodeSource } from '@/types/nodeSource'
|
|
import { extractCustomNodeName } from '@/utils/nodeHelpUtil'
|
|
|
|
export 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 fetchWithHeaders(api.fileURL(localePath))
|
|
|
|
if (!res.ok) {
|
|
// Fall back to non-locale path
|
|
const fallbackPath = `/extensions/${customNodeName}/docs/${node.name}.md`
|
|
res = await fetchWithHeaders(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 fetchWithHeaders(api.fileURL(mdUrl))
|
|
|
|
if (!res.ok) {
|
|
throw new Error(res.statusText)
|
|
}
|
|
|
|
return res.text()
|
|
}
|
|
}
|
|
|
|
// Export singleton instance
|
|
export const nodeHelpService = new NodeHelpService()
|