save chrrent changes

This commit is contained in:
2025-08-17 14:24:51 +02:00
parent 056b4091ef
commit 60a5272054
9 changed files with 5507 additions and 19 deletions

View File

@ -8,9 +8,32 @@ dotenv.config();
const COMFY_BASE_URL = process.env.COMFY_BASE_URL?.replace(/\/$/, '');
const COMFY_OUTPUT_DIR = process.env.COMFY_OUTPUT_DIR;
async function generateImage(prompt: string, newFileName: string): Promise<string> {
const workflow = JSON.parse(await fs.readFile('src/comfyworkflows/generate_image.json', 'utf-8'));
workflow['6']['inputs']['text'] = prompt;
interface ImageSize {
width: number;
height: number;
}
async function generateImage(
prompt: string,
newFileName: string,
imageModel: 'qwen' | 'flux' = 'qwen',
size: ImageSize = { width: 720, height: 1280 }
): Promise<string> {
let workflow;
if (imageModel === 'qwen') {
workflow = JSON.parse(await fs.readFile('src/comfyworkflows/generate_image.json', 'utf-8'));
workflow['6']['inputs']['text'] = prompt;
workflow['72']['inputs']['width'] = size.width;
workflow['72']['inputs']['height'] = size.height;
} else if (imageModel === 'flux') {
workflow = JSON.parse(await fs.readFile('src/comfyworkflows/generate_image_flux.json', 'utf-8'));
workflow['41']['inputs']['clip_l'] = prompt;
workflow['41']['inputs']['t5xxl'] = prompt;
workflow['27']['inputs']['width'] = size.width;
workflow['27']['inputs']['height'] = size.height;
} else {
throw new Error(`Unsupported image model: ${imageModel}`);
}
const response = await axios.post(`${COMFY_BASE_URL}/prompt`, { prompt: workflow });
const promptId = response.data.prompt_id;

View File

@ -8,10 +8,22 @@ dotenv.config();
const COMFY_BASE_URL = process.env.COMFY_BASE_URL?.replace(/\/$/, '');
const COMFY_OUTPUT_DIR = process.env.COMFY_OUTPUT_DIR;
async function generateVideo(prompt: string, imagePath: string, newFileName: string): Promise<string> {
interface VideoSize {
width: number;
height: number;
}
async function generateVideo(
prompt: string,
imagePath: string,
newFileName: string,
size: VideoSize = { width: 720, height: 1280 }
): Promise<string> {
const workflow = JSON.parse(await fs.readFile('src/comfyworkflows/generate_video.json', 'utf-8'));
workflow['6']['inputs']['text'] = prompt;
workflow['52']['inputs']['image'] = imagePath;
workflow['64']['inputs']['width'] = size.width;
workflow['64']['inputs']['height'] = size.height;
const response = await axios.post(`${COMFY_BASE_URL}/prompt`, { prompt: workflow });
const promptId = response.data.prompt_id;