mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-09-14 21:46:35 +00:00
refactor: use standalone tool run executor
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
import ToolSearch from './search/ToolSearch.svelte';
|
import ToolSearch from './search/ToolSearch.svelte';
|
||||||
import ChainToolBlock from './chain/ChainToolBlock.svelte';
|
import ChainToolBlock from './chain/ChainToolBlock.svelte';
|
||||||
import { createAutoRunner } from '$lib/tools/auto-run';
|
import { createAutoRunner } from '$lib/tools/auto-run';
|
||||||
|
import { executeStep } from '$lib/tools/executor';
|
||||||
import ParamsCard from './tool/ParamsCard.svelte';
|
import ParamsCard from './tool/ParamsCard.svelte';
|
||||||
import ResultCard from './tool/ResultCard.svelte';
|
import ResultCard from './tool/ResultCard.svelte';
|
||||||
import SourceCard from './tool/SourceCard.svelte';
|
import SourceCard from './tool/SourceCard.svelte';
|
||||||
@@ -146,9 +147,8 @@
|
|||||||
} else if (isSourceless) {
|
} else if (isSourceless) {
|
||||||
next = await tool.generate!(sanitized);
|
next = await tool.generate!(sanitized);
|
||||||
} else {
|
} else {
|
||||||
next = await tool.run!(source!, sanitized);
|
next = await executeStep(tool, source!, sanitized);
|
||||||
}
|
}
|
||||||
|
|
||||||
let nextPreview: PixelImage | null = null;
|
let nextPreview: PixelImage | null = null;
|
||||||
if (tool.preview && source) {
|
if (tool.preview && source) {
|
||||||
try {
|
try {
|
||||||
@@ -173,7 +173,7 @@
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
current = await stepTool.run(current, sanitizeParams(stepTool, step.values));
|
current = await executeStep(stepTool, current, sanitizeParams(stepTool, step.values));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const message = e instanceof Error ? e.message : String(e);
|
const message = e instanceof Error ? e.message : String(e);
|
||||||
throw new Error(`Шаг ${i + 1} (${stepTool.title}): ${message}`);
|
throw new Error(`Шаг ${i + 1} (${stepTool.title}): ${message}`);
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import type { PixelImage } from '../core/types';
|
||||||
|
|
||||||
|
type MaybeRunnable = {
|
||||||
|
run?: (img: PixelImage, params: Record<string, unknown>) => Promise<PixelImage> | PixelImage;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function executeStep(
|
||||||
|
tool: MaybeRunnable,
|
||||||
|
img: PixelImage,
|
||||||
|
params: Record<string, unknown>
|
||||||
|
): Promise<PixelImage> {
|
||||||
|
if (!tool.run) {
|
||||||
|
throw new Error('Этот инструмент не обрабатывает изображения');
|
||||||
|
}
|
||||||
|
return await tool.run(img, params);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user