Line data Source code
1 : import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
2 : import type { ComfyNodeDef } from '@comfyorg/object-info-parser'
3 : import { applyTextReplacements } from '@/utils/searchAndReplace'
4 :
5 : import { app } from '@/scripts/app'
6 : import type { ComfyExtension } from '@/types/comfy'
7 :
8 2355 : const saveNodeTypes = new Set([
9 : 'SaveImage',
10 : 'SaveImageAdvanced',
11 : 'SaveSVGNode',
12 : 'SaveVideo',
13 : 'SaveAnimatedWEBP',
14 : 'SaveWEBM',
15 : 'SaveAudio',
16 : 'SaveAudioMP3',
17 : 'SaveAudioOpus',
18 : 'SaveAudioAdvanced',
19 : 'SaveGLB',
20 : 'Save3DAdvanced',
21 : 'SaveGaussianSplat',
22 : 'SavePointCloud',
23 : 'SaveAnimatedPNG',
24 : 'CLIPSave',
25 : 'VAESave',
26 : 'ModelSave',
27 : 'LoraSave',
28 : 'SaveLatent'
29 : ])
30 :
31 : // Use widget values and dates in output filenames
32 :
33 2355 : export const saveImageExtraOutputExtension: ComfyExtension = {
34 : name: 'Comfy.SaveImageExtraOutput',
35 : async beforeRegisterNodeDef(
36 : nodeType: typeof LGraphNode,
37 : nodeData: ComfyNodeDef
38 : ) {
39 2439372 : if (saveNodeTypes.has(nodeData.name)) {
40 47320 : const onNodeCreated = nodeType.prototype.onNodeCreated
41 : // When the SaveImage node is created we want to override the serialization of the output name widget to run our S&R
42 47320 : nodeType.prototype.onNodeCreated = function () {
43 2835 : const r = onNodeCreated?.call(this)
44 :
45 2835 : const widget = this.widgets?.find((w) => w.name === 'filename_prefix')
46 2835 : if (!widget) return r
47 2835 : widget.serializeValue = () =>
48 : typeof widget.value === 'string'
49 : ? applyTextReplacements(app.graph, widget.value)
50 : : widget.value
51 :
52 2835 : return r
53 : }
54 : } else {
55 : // When any other node is created add a property to alias the node
56 2392052 : const onNodeCreated = nodeType.prototype.onNodeCreated
57 2392052 : nodeType.prototype.onNodeCreated = function () {
58 19756 : const r = onNodeCreated?.call(this)
59 :
60 19756 : if (!('Node name for S&R' in this.properties)) {
61 19756 : this.addProperty('Node name for S&R', this.constructor.type, 'string')
62 : }
63 :
64 19756 : return r
65 : }
66 : }
67 : }
68 : }
|