mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-05 21:20:12 +00:00
Move exportWorkflow from menu to workflowService (#1399)
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
import type { ComfyApp } from '@/scripts/app'
|
||||
import { $el } from '../../ui'
|
||||
import { downloadBlob } from '../../utils'
|
||||
import { ComfyButtonGroup } from '../components/buttonGroup'
|
||||
import { showPromptDialog } from '@/services/dialogService'
|
||||
import { useSettingStore } from '@/stores/settingStore'
|
||||
import './menu.css'
|
||||
|
||||
// Export to make sure following components are shimmed and exported by vite
|
||||
@@ -33,35 +30,4 @@ export class ComfyAppMenu {
|
||||
this.viewGroup.element
|
||||
])
|
||||
}
|
||||
|
||||
async getFilename(defaultName: string): Promise<string | null> {
|
||||
if (useSettingStore().get('Comfy.PromptFilename')) {
|
||||
let filename = await showPromptDialog({
|
||||
title: 'Export Workflow',
|
||||
message: 'Enter the filename:',
|
||||
defaultValue: defaultName
|
||||
})
|
||||
if (!filename) return null
|
||||
if (!filename.toLowerCase().endsWith('.json')) {
|
||||
filename += '.json'
|
||||
}
|
||||
return filename
|
||||
}
|
||||
return defaultName
|
||||
}
|
||||
|
||||
async exportWorkflow(
|
||||
filename: string,
|
||||
promptProperty: 'workflow' | 'output'
|
||||
): Promise<void> {
|
||||
if (this.app.workflowManager.activeWorkflow?.path) {
|
||||
filename = this.app.workflowManager.activeWorkflow.name
|
||||
}
|
||||
const p = await this.app.graphToPrompt()
|
||||
const json = JSON.stringify(p[promptProperty], null, 2)
|
||||
const blob = new Blob([json], { type: 'application/json' })
|
||||
const file = await this.getFilename(filename)
|
||||
if (!file) return
|
||||
downloadBlob(file, blob)
|
||||
}
|
||||
}
|
||||
|
||||
39
src/services/workflowService.ts
Normal file
39
src/services/workflowService.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { downloadBlob } from '@/scripts/utils'
|
||||
import { useSettingStore } from '@/stores/settingStore'
|
||||
import { useWorkflowStore } from '@/stores/workflowStore'
|
||||
import { showPromptDialog } from './dialogService'
|
||||
import { app } from '@/scripts/app'
|
||||
|
||||
async function getFilename(defaultName: string): Promise<string | null> {
|
||||
if (useSettingStore().get('Comfy.PromptFilename')) {
|
||||
let filename = await showPromptDialog({
|
||||
title: 'Export Workflow',
|
||||
message: 'Enter the filename:',
|
||||
defaultValue: defaultName
|
||||
})
|
||||
if (!filename) return null
|
||||
if (!filename.toLowerCase().endsWith('.json')) {
|
||||
filename += '.json'
|
||||
}
|
||||
return filename
|
||||
}
|
||||
return defaultName
|
||||
}
|
||||
|
||||
export const workflowService = {
|
||||
async exportWorkflow(
|
||||
filename: string,
|
||||
promptProperty: 'workflow' | 'output'
|
||||
): Promise<void> {
|
||||
const workflow = useWorkflowStore().activeWorkflow
|
||||
if (workflow?.path) {
|
||||
filename = workflow.name
|
||||
}
|
||||
const p = await app.graphToPrompt()
|
||||
const json = JSON.stringify(p[promptProperty], null, 2)
|
||||
const blob = new Blob([json], { type: 'application/json' })
|
||||
const file = await getFilename(filename)
|
||||
if (!file) return
|
||||
downloadBlob(file, blob)
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import { type KeybindingImpl, useKeybindingStore } from './keybindingStore'
|
||||
import { useBottomPanelStore } from './workspace/bottomPanelStore'
|
||||
import { LGraphNode } from '@comfyorg/litegraph'
|
||||
import { useWorkspaceStore } from './workspaceStore'
|
||||
import { workflowService } from '@/services/workflowService'
|
||||
|
||||
export interface ComfyCommand {
|
||||
id: string
|
||||
@@ -167,7 +168,7 @@ export const useCommandStore = defineStore('command', () => {
|
||||
label: 'Export Workflow',
|
||||
menubarLabel: 'Export',
|
||||
function: () => {
|
||||
app.menu.exportWorkflow('workflow', 'workflow')
|
||||
workflowService.exportWorkflow('workflow', 'workflow')
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -176,7 +177,7 @@ export const useCommandStore = defineStore('command', () => {
|
||||
label: 'Export Workflow (API Format)',
|
||||
menubarLabel: 'Export (API)',
|
||||
function: () => {
|
||||
app.menu.exportWorkflow('workflow_api', 'output')
|
||||
workflowService.exportWorkflow('workflow_api', 'output')
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user