()
| 294 | } |
| 295 | |
| 296 | async function generateVideo() { |
| 297 | const subject = videoSubject.value.trim(); |
| 298 | if (!subject) { |
| 299 | showToast("Please enter a video subject.", "error"); |
| 300 | videoSubject.focus(); |
| 301 | return; |
| 302 | } |
| 303 | |
| 304 | generateButton.disabled = true; |
| 305 | setGeneratingState(true); |
| 306 | |
| 307 | // Clear previous log entries |
| 308 | logViewerBody.innerHTML = ""; |
| 309 | |
| 310 | // Upload songs first if a folder was selected |
| 311 | if (useMusicToggle.checked && songFiles.files.length > 0) { |
| 312 | const uploaded = await uploadSongs(); |
| 313 | if (!uploaded) { |
| 314 | setGeneratingState(false); |
| 315 | return; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | const data = { |
| 320 | videoSubject: subject, |
| 321 | aiModel: aiModel.value || "llama3.1:8b", |
| 322 | voice: voice.value, |
| 323 | paragraphNumber: paragraphNumber.value, |
| 324 | automateYoutubeUpload: youtubeToggle.checked, |
| 325 | useMusic: useMusicToggle.checked, |
| 326 | threads: document.getElementById("threads").value, |
| 327 | subtitlesPosition: document.getElementById("subtitlesPosition").value, |
| 328 | customPrompt: customPrompt.value, |
| 329 | color: subtitlesColor.value, |
| 330 | }; |
| 331 | |
| 332 | try { |
| 333 | const result = await apiRequest("/api/generate", { |
| 334 | method: "POST", |
| 335 | body: JSON.stringify(data), |
| 336 | headers: { |
| 337 | "Content-Type": "application/json", |
| 338 | Accept: "application/json", |
| 339 | }, |
| 340 | }); |
| 341 | |
| 342 | if (result.status === "success") { |
| 343 | if (!result.jobId) { |
| 344 | showToast("Generation queued, but no job ID was returned.", "error"); |
| 345 | setGeneratingState(false); |
| 346 | return; |
| 347 | } |
| 348 | startJobPolling(result.jobId); |
| 349 | } else { |
| 350 | showToast(result.message, "error"); |
| 351 | setGeneratingState(false); |
| 352 | } |
| 353 | } catch { |
no test coverage detected