mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-19 22:34:15 +00:00
## Summary - Type `onExecuted` callbacks with `NodeExecutionOutput` in saveMesh.ts and uploadAudio.ts - Type composable parameters and return values properly (useLoad3dViewer, useImageMenuOptions, useJobMenu, useResultGallery, useContextMenuTranslation) - Type `taskRef` as `TaskItemImpl` with updated test mocks - Fix error catch and index signature patterns without `any` - Add `NodeOutputWith<T>` generic helper for typed access to passthrough properties on `NodeExecutionOutput` ## Test plan - [x] `pnpm typecheck` passes - [x] `pnpm lint` passes - [x] Unit tests pass for affected files - [x] Sourcegraph checks confirm no external usage of modified types ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8083-Road-to-No-Explicit-Any-Part-6-Composables-and-Extensions-2e96d73d3650810fb033d745bf88a22b) by [Unito](https://www.unito.io)
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import type { NodeOutputWith } from '@/schemas/apiSchema'
|
|
import { api } from '@/scripts/api'
|
|
import { app } from '@/scripts/app'
|
|
import { useExtensionService } from '@/services/extensionService'
|
|
|
|
type ImageCompareOutput = NodeOutputWith<{
|
|
a_images?: Record<string, string>[]
|
|
b_images?: Record<string, string>[]
|
|
}>
|
|
|
|
useExtensionService().registerExtension({
|
|
name: 'Comfy.ImageCompare',
|
|
|
|
async nodeCreated(node) {
|
|
if (node.constructor.comfyClass !== 'ImageCompare') return
|
|
|
|
const [oldWidth, oldHeight] = node.size
|
|
node.setSize([Math.max(oldWidth, 400), Math.max(oldHeight, 350)])
|
|
|
|
const onExecuted = node.onExecuted
|
|
|
|
node.onExecuted = function (output: ImageCompareOutput) {
|
|
onExecuted?.call(this, output)
|
|
|
|
const { a_images: aImages, b_images: bImages } = output
|
|
const rand = app.getRandParam()
|
|
|
|
const beforeUrl =
|
|
aImages && aImages.length > 0
|
|
? api.apiURL(`/view?${new URLSearchParams(aImages[0])}${rand}`)
|
|
: ''
|
|
const afterUrl =
|
|
bImages && bImages.length > 0
|
|
? api.apiURL(`/view?${new URLSearchParams(bImages[0])}${rand}`)
|
|
: ''
|
|
|
|
const widget = node.widgets?.find((w) => w.type === 'imagecompare')
|
|
|
|
if (widget) {
|
|
widget.value = {
|
|
before: beforeUrl,
|
|
after: afterUrl
|
|
}
|
|
widget.callback?.(widget.value)
|
|
}
|
|
}
|
|
}
|
|
})
|