Skip to content

Unrestricted Open-source alternative to AI video platforms — Free AI image & video generation studio with 600+ models (Flux, Midjourney, Kling, Sora, Veo). No content filters. Self-hosted, MIT licensed.

Merge pull request #335 from antilya/fix-stuck-reference-upload

jaiprasad04ef42541f3d01
diff --cc packages/studio/src/components/ImageStudio.jsx
index 8b049b68,e26d9d54..3556048c
--- a/packages/studio/src/components/ImageStudio.jsx
+++ b/packages/studio/src/components/ImageStudio.jsx
@@@ -4,12 -4,9 +4,14 @@@ import { useState, useEffect, useRef, u
import toast, { Toaster } from "react-hot-toast";
import { generateImage, generateI2I, uploadFile } from "../muapi.js";
import { formatErrorMessage } from "../utils/formatError.js";
+ import { downloadImage } from "../utils/downloadImage.js";
+ import { appendGenerationRefundNotice } from "../utils/generationLifecycle.js";
import { scopedPersistKey, migrateLegacyPersistKey } from "../persistKey.js";
+import {
+ getAuxiliaryImageInputs,
+ getImageInputContract,
+ getImageInputValidationError,
+} from "../imageInputContracts.js";
import DrawModal from "./DrawModal.jsx";
import MobileGenerationActions, {
GenerationCopyButtons,
diff --cc packages/studio/src/muapi.js
index 7976a8cc,076e6890..2262b0bf
--- a/packages/studio/src/muapi.js
+++ b/packages/studio/src/muapi.js
@@@ -1,10 -1,5 +1,11 @@@
import { getModelById, getVideoModelById, getI2IModelById, getI2VModelById, getV2VModelById, getRecastModelById, getLipSyncModelById, getAudioModelById } from './models.js';
+import {
+ buildVideoToolPayload,
+ serializeVideoToolOptions,
+} from './videoToolCapabilities.js';
+import { buildImageSizePayload } from './imageSizing.js';
+import { buildImageInputPayload, getImageInputValidationError, normalizePrimaryImageUrls } from './imageInputContracts.js';
+ import { pollForGenerationResult } from './utils/generationLifecycle.js';
// In an http(s) browser we route through the host app's proxy (Next.js routes
// under /api/* re-issue the call server-side) so api.muapi.ai CORS is bypassed.
@@@ -21,39 -18,16 +24,25 @@@ function notifyAuthRequired(status, det
}
async function pollForResult(requestId, key, maxAttempts = 900, interval = 2000) {
- const pollUrl = `${BASE_URL}/api/v1/predictions/${requestId}/result`;
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
- await new Promise(resolve => setTimeout(resolve, interval));
- try {
- const response = await fetch(pollUrl, {
- headers: { 'Content-Type': 'application/json', 'x-api-key': key }
- });
- if (!response.ok) {
- const errText = await response.text();
- if (response.status >= 500) continue;
- notifyAuthRequired(response.status, errText);
- throw new Error(`Poll Failed: ${response.status} - ${errText.slice(0, 100)}`);
- }
- const data = await response.json();
- const status = data.status?.toLowerCase();
- if (status === 'completed' || status === 'succeeded' || status === 'success') return data;
- if (status === 'failed' || status === 'error') throw new Error(`Generation failed: ${data.error || 'Unknown error'}`);
- } catch (error) {
- if (attempt === maxAttempts) throw error;
- }
- }
- throw new Error('Generation timed out after polling.');
+ return pollForGenerationResult({
+ baseUrl: BASE_URL,
+ requestId,
+ apiKey: key,
+ maxAttempts,
+ interval,
+ onAuthRequired: notifyAuthRequired,
+ });
}
+function normalizePredictionResult(submitData, result, outputUrl) {
+ const requestId = submitData?.request_id || submitData?.id || result?.request_id || result?.id;
+ return {
+ ...result,
+ ...(requestId ? { request_id: requestId } : {}),
+ url: outputUrl,
+ };
+}
+
async function submitAndPoll(endpoint, payload, key, onRequestId, maxAttempts = 60) {
const url = `${BASE_URL}/api/v1/${endpoint}`;
const response = await fetch(url, {