🎬 火宝短剧 - 基于AI的一站式短剧生成平台 《一句话生成完整短剧,从剧本到成片全自动化》 Huobao Drama - An AI-Powered End-to-End Short Drama Generator "One Sentence to Complete Drama: Fully Automated from Script to Final Video"
TypeScript
feat: replace fixed `setTimeout` calls with a new polling mechanism for image generation status updates in drama management.
awsless80ca0608683f
diff --git a/application/services/prompt_i18n.go b/application/services/prompt_i18n.goindex 9aa7838..aa18437 100644--- a/application/services/prompt_i18n.go+++ b/application/services/prompt_i18n.go@@ -390,7 +390,7 @@ Requirements:- appearance: Physical appearance description (150-300 words)- personality: Personality traits (100-200 words)- description: Background story and character relationships (100-200 words)-3. Appearance must be detailed enough for AI image generation, including: gender, age, body type, facial features, hairstyle, clothing style, etc.+3. Appearance must be detailed enough for AI image generation, including: gender, age, body type, facial features, hairstyle, clothing style, etc. but do not include any scene, background, environment information4. Main characters require more detailed descriptions, supporting characters can be simplified- **Style Requirement**: %s- **Image Ratio**: %s@@ -411,7 +411,7 @@ Each element is a character object containing the above fields.`, style, imageRa- appearance: 外貌描述(150-300字)- personality: 性格特点(100-200字)- description: 背景故事和角色关系(100-200字)-3. 外貌描述要足够详细,适合AI生成图片,包括:性别、年龄、体型、面部特征、发型、服装风格等+3. 外貌描述要足够详细,适合AI生成图片,包括:性别、年龄、体型、面部特征、发型、服装风格等,但不要包含任何场景、背景、环境等信息4. 主要角色需要更详细的描述,次要角色可以简化- **风格要求**:%s- **图片比例**:%sdiff --git a/web/src/views/drama/DramaManagement.vue b/web/src/views/drama/DramaManagement.vueindex 8ecab18..b5f49f0 100644--- a/web/src/views/drama/DramaManagement.vue+++ b/web/src/views/drama/DramaManagement.vue@@ -804,6 +804,8 @@ const drama = ref<Drama>();const activeTab = ref((route.query.tab as string) || "overview");const scenes = ref<any[]>([]);+let pollingTimer: any = null; // Add polling timer definition+const addCharacterDialogVisible = ref(false);const addSceneDialogVisible = ref(false);const addPropDialogVisible = ref(false);@@ -851,6 +853,31 @@ const sortedEpisodes = computed(() => {);});+// Helper for polling+const startPolling = (+ callback: () => Promise<void>,+ maxAttempts = 20,+ interval = 3000,+) => {+ if (pollingTimer) clearInterval(pollingTimer);++ let attempts = 0;+ pollingTimer = setInterval(async () => {+ attempts++;+ await callback();+ if (attempts >= maxAttempts) {+ if (pollingTimer) clearInterval(pollingTimer);+ pollingTimer = null;+ }+ }, interval);+};++// Clear timer on unmount+import { onUnmounted } from "vue";+onUnmounted(() => {+ if (pollingTimer) clearInterval(pollingTimer);+});+const loadDramaData = async () => {try {const data = await dramaAPI.get(route.params.id as string);@@ -1011,9 +1038,7 @@ const generateCharacterImage = async (character: any) => {try {await characterLibraryAPI.generateCharacterImage(character.id);ElMessage.success("图片生成任务已提交");- setTimeout(() => {- loadDramaData();- }, 3000);+ startPolling(loadDramaData);} catch (error: any) {ElMessage.error(error.message || "生成失败");}@@ -1052,9 +1077,7 @@ const generateSceneImage = async (scene: any) => {try {await dramaAPI.generateSceneImage({ scene_id: scene.id });ElMessage.success("图片生成任务已提交");- setTimeout(() => {- loadScenes();- }, 3000);+ startPolling(loadScenes);} catch (error: any) {ElMessage.error(error.message || "生成失败");}@@ -1377,10 +1400,7 @@ const generatePropImage = async (prop: any) => {try {await propAPI.generateImage(prop.id);ElMessage.success("图片生成任务已提交");- // 简单起见,3秒后刷新一次,实际应该轮询- setTimeout(() => {- loadDramaData();- }, 3000);+ startPolling(loadDramaData);} catch (error: any) {ElMessage.error(error.message || "生成失败");}