Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

Merge pull request #319 from Mijaelx/codex/issue-298-local-subtitles

Leggett3dfabd84f09d
diff --cc apps/daemon/src/creator/krillin/cli-runner.ts
index 90026cd1,6b764613..fa43d12d
--- a/apps/daemon/src/creator/krillin/cli-runner.ts
+++ b/apps/daemon/src/creator/krillin/cli-runner.ts
@@@ -224,9 -216,12 +224,12 @@@ export function buildKrillinCliCommandA
const command = krillinCliStageId(stage.stageRun.stageId);
const common = ['--workdir', stage.workdir, '--task-id', stage.stageRun.id];
if (command === 'subtitle') {
- const source = resolveKrillinCliSource(artifacts, options);
+ const source = sourceOverride ?? resolveKrillinCliSource(artifacts, options);
if (!source) throw new CreatorExecutorError('creator_stage_input_missing', 'Subtitle input video or URL is required');
const sourceOnly = booleanOption(options, 'sourceOnly', false);
+ const importedTarget = artifactPath(artifacts, 'target_subtitle');
+ const importedSource = artifactPath(artifacts, 'source_subtitle');
+ const imported = importedTarget ?? importedSource;
return [
'subtitle',
source,
diff --cc apps/daemon/src/creator/service.ts
index 94f3ed98,89162c9f..0abbcfef
--- a/apps/daemon/src/creator/service.ts
+++ b/apps/daemon/src/creator/service.ts
@@@ -1262,7 -1312,7 +1330,8 @@@ function dependentArtifacts(artifacts:
}
function summarizeAction(action: string, input: Record<string, CreatorJson>): string {
+ if (action === 'select-result-version') return `选择项目结果 V${String(input.version)}`;
+ if (action === 'import-subtitle') return '导入本地字幕并保留旧版本';
if (action === 'edit-subtitle') return '更新字幕并保留下游旧版本';
if (action === 'commit-version') return '保存项目版本设置';
if (action === 'run-stage') return `启动阶段 ${String(input.stageId ?? '')}`.trim();
diff --cc apps/web/e2e/web-desktop-parity.spec.ts
index 08221fda,8784ba6b..78a2e115
--- a/apps/web/e2e/web-desktop-parity.spec.ts
+++ b/apps/web/e2e/web-desktop-parity.spec.ts
@@@ -1,70 -1,34 +1,98 @@@
- import type { CreatorYtDlpStatusResponse } from '@opencreator/protocol';
+ import type { CreatorServicesCapabilitiesResponse, CreatorYtDlpStatusResponse } from '@opencreator/protocol';
import { test, expect } from './fixtures/runtime.js';
+import { dirname, join } from 'node:path';
+import { writeFileSync } from 'node:fs';
+import { openRuntimeDatabase } from '../../daemon/src/storage/database.js';
+import { createCreatorRepository } from '../../daemon/src/creator/repository.js';
+import { appendCreatorResultSnapshot } from '../../daemon/src/creator/result-snapshots.js';
+
+test('Artifact 历史选择和来源在 Browser/Desktop Bridge 下保持一致并可刷新', async ({ browser, runtime }, testInfo) => {
+ test.skip(testInfo.project.name !== 'chromium-desktop', '内部使用相同内容视口');
+ const created = await runtime.api<{ job: { id: string } }>('POST', '/creator/jobs', {
+ projectId: runtime.projectId, templateId: 'image-generation', state: { prompt: '版本来源验收', currentStep: 2, furthestStep: 2 }
+ });
+ const db = openRuntimeDatabase(join(dirname(runtime.projectDir), 'runtime', 'app.sqlite'));
+ const repository = createCreatorRepository(db);
+ for (const version of [1, 2]) {
+ const path = join(runtime.projectDir, `history-${version}.png`);
+ writeFileSync(path, Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIHWP4z8DwHwAFgAI/ScLbtAAAAABJRU5ErkJggg==', 'base64'));
+ const artifact = repository.insertArtifact({ jobId: created.job.id, kind: 'generated_image', path, status: version === 1 ? 'stale' : 'completed', sourceArtifactIds: [], metadata: { fileName: `history-${version}.png`, resultVersion: version } });
+ const job = repository.getJob(created.job.id)!;
+ repository.updateJob({ id: job.id, status: 'completed', revision: job.revision + 1, state: { ...job.state,
+ ...appendCreatorResultSnapshot({ job, version, changedArtifacts: [artifact], action: 'stage-succeeded', stageId: 'generate', description: `生成 ${version}` })
+ } });
+ }
+ const old = repository.getJob(created.job.id)!.artifacts.find(artifact => artifact.metadata.resultVersion === 1)!;
+ db.close();
+ const results = [];
+ for (const platform of ['browser', 'desktop'] as const) {
+ const current = await runtime.api<{ job: { revision: number } }>('GET', `/creator/jobs/${created.job.id}`);
+ await runtime.api('POST', `/creator/jobs/${created.job.id}/actions`, { action: 'select-result-version', expectedRevision: current.job.revision, input: { version: 2 } });
+ const context = await browser.newContext({ viewport: { width: 1440, height: 900 }, deviceScaleFactor: 1, reducedMotion: 'reduce' });
+ const page = await context.newPage();
+ if (platform === 'desktop') await installDesktopBridge(page);
+ try {
+ await runtime.openApp(page);
+ await page.goto(`${runtime.origin}/#/workbench?tool=image-generation&jobId=${created.job.id}`);
+ await page.getByText('产物版本与来源', { exact: true }).click();
+ const details = page.getByRole('region', { name: '产物详情' });
+ await details.getByLabel('浏览产物(不改变项目选择)').selectOption(old.id);
+ await expect(details).toContainText('已过期,非当前有效结果');
+ const requests: unknown[] = [];
+ page.on('request', request => {
+ if (request.method() === 'POST' && request.url().endsWith('/actions')) {
+ const body = request.postDataJSON();
+ if (body.action === 'select-result-version') requests.push({ action: body.action, input: body.input });
+ }
+ });
+ await details.getByRole('button', { name: '采用项目版本' }).click();
+ await expect(page.getByRole('button', { name: '项目 V1', exact: true })).toBeVisible();
+ await page.reload();
+ await expect(page.getByRole('button', { name: '项目 V1', exact: true })).toBeVisible();
+ await page.getByText('产物版本与来源', { exact: true }).click();
+ await expect(details).toContainText('已过期,非当前有效结果');
+ const downloadWork = page.waitForEvent('download');
+ await details.getByRole('button', { name: '下载 V1' }).click();
+ expect((await downloadWork).suggestedFilename()).toBe('history-1.png');
+ await details.getByRole('button', { name: '预览 V1' }).click();
+ await expect(details.getByRole('img')).toBeVisible();
+ await details.evaluate(element => { element.scrollTop = 0; });
+ results.push({ text: normalizeParityText(await details.innerText()), box: await details.boundingBox(), requests });
+ await page.screenshot({ path: testInfo.outputPath(`artifact-${platform}.png`) });
+ } finally { await context.close(); }
+ }
+ expect(results[0]).toEqual(results[1]);
+ expect(results[0]!.requests).toEqual([{ action: 'select-result-version', input: { version: 1 } }]);
+});
+ test('本地字幕导入在 Browser/Desktop Bridge 下保持相同命令和界面', async ({ browser, runtime }, testInfo) => {
+ test.skip(testInfo.project.name !== 'chromium-desktop');
+ const results: unknown[] = [];
+ for (const platform of ['browser', 'desktop']) {
+ const created = await runtime.api<{ job: { id: string } }>('POST', '/creator/jobs', {
+ projectId: runtime.projectId, templateId: 'video-translation',
+ state: { sourceUrl: 'https://www.youtube.com/watch?v=import', currentStep: 1, furthestStep: 1 }
+ });
+ const context = await browser.newContext({ viewport: { width: 1280, height: 800 }, reducedMotion: 'reduce' });
+ const page = await context.newPage();
+ if (platform === 'desktop') await installDesktopBridge(page);
+ try {
+ await runtime.openApp(page);
+ await page.goto(`${runtime.origin}/#/workbench?tool=video-translation&jobId=${created.job.id}`);
+ const group = page.getByRole('group', { name: '导入已有字幕' });
+ await group.getByRole('combobox', { name: '字幕类型' }).selectOption('target_subtitle');
+ const request = page.waitForRequest(request => request.url().endsWith('/actions') && request.postDataJSON()?.action === 'import-subtitle');
+ await group.getByLabel('UTF-8 SRT 文件').setInputFiles({ name: 'local.srt', mimeType: 'application/x-subrip', buffer: Buffer.from('1\n00:00:00,000 --> 00:00:01,000\nHello\n') });
+ const action = (await request).postDataJSON();
+ await expect(group.getByText(/本地导入 · local.srt/)).toBeVisible();
+ await expect(page.getByRole('heading', { name: '设置翻译语言' })).toBeVisible();
+ const stored = await runtime.api<{ job: { artifacts: Array<{ kind: string; metadata: unknown }> } }>('GET', `/creator/jobs/${created.job.id}`);
+ results.push({ text: await group.innerText(), box: await group.boundingBox(), input: action.input, artifacts: stored.job.artifacts.map(a => ({ kind: a.kind, metadata: a.metadata })) });
+ } finally { await context.close(); }
+ }
+ expect(results[1]).toEqual(results[0]);
+ });
+
test('通用界面设置在 Browser/Desktop Bridge 下读取并写入相同 Runtime 配置', async ({
browser,
runtime
diff --cc apps/web/src/features/dashboard/VideoTranslationWorkspace.tsx
index 614bcba2,8ee5949d..07475716
--- a/apps/web/src/features/dashboard/VideoTranslationWorkspace.tsx
+++ b/apps/web/src/features/dashboard/VideoTranslationWorkspace.tsx
@@@ -1370,8 -1371,11 +1371,13 @@@ export default function VideoTranslatio
latestVersion: latest?.value ?? null
};
setResultVersions(artifactVersions);
+ const persistedVersion = artifactVersions.find(version => version.value === persisted.resultVersion);
+ if (persistedVersion !== undefined) setResultVersion(persistedVersion.value);
+ if (creatorSession.job.status === 'draft' && readCreatorResultSnapshots(persisted.resultSnapshots).at(-1)?.action === 'import-subtitle') {
+ setDraftBaseVersion(undefined);
+ setWorkspacePhase('configure');
+ return;
+ }
if (latest !== undefined) {
if (!shouldRestoreLatestResult) return;
setCurrentStep(3);