Files
Genarrative/src/components/image-editor/ImageCanvasProjectCoverSnapshotModel.test.ts
T
k88936 a03f13d0a5
Project CI / Repository checks (push) Successful in 1m28s
Project CI / Frontend tests (push) Successful in 3m19s
Project CI / Backend tests (push) Successful in 4m3s
Project CI / Native shell tests (push) Successful in 13m58s
Fix/动作 前端展示下载+后端数据结构+精选 的问题 (#117)
原问题

```
历史角色动作是一个兼容例外:
后端允许它没有 editor_project_resource 资源行,只要布局自身保存了完整图片序列帧。
```

- 把生成动作的原视频asstetkind改为 video, 只把图片序列作为action
- db asset新增字段image_sequence_frames_json image_seq_duration_ms等, (原来动作的这些数据存在generation-input中,并不合适)
修改了externaljob,把这部分数据正确填写到数据库中。
- 为避免到处fallback,做了数据库迁移, 脚本: `scripts/spacetime-normalize-editor-character-actions.mjs`   手动进行过画布+素材库中动作序列帧+原始视频 迁移的测试

- 移除preview_video_path字段,  reason:
>preview video
    → separate resource/asset with assetKind="video"
  final transparent action
    → assetKind="character-animation"
    → source_resource_id points to the preview-video resource
    → image_sequence_frames_json contains the actual playable result
>
> So preview_video_path on the final action duplicates the source video resource’s image_src.
- 移除每个frame的index字段 原因: 这个只用于后端内部处理时有一个并发请求, 每个赋一个index方便收集, 后续没有再用到,且与数组本身重复

- 清除副产品preview video的generation_input_json,  因为会影响改造功能, 迁移后预览视频不提供改造(参数), 只有序列帧动作有改造

仍存在的共性问题: #134

- 导出:
下载改为完整序列帧, 封面不再作为fallback, 部分帧读取失败时行为:仍生成 ZIP,并记录失败帧, 不变

画布放置:
before:
![shotmd-1785207959-compressed.webp](/attachments/e56454f0-49a3-4a8a-951f-c21960975f99)
after:
![shotmd-1785231365-compressed.webp](/attachments/886f07df-c25b-4ecc-acc9-160e1795a991)
精选模块: 主页展示, 审核部分UI:
![shotmd-1785500046-compressed.webp](/attachments/9ec3b679-0045-494a-9f20-134f7e73fecf)
![shotmd-1785499780-compressed.webp](/attachments/42396e63-5f26-4853-a367-0f3c15111add)
这两处序列帧们的加载设计为惰式的, 只有hover和单独preview才会全部加载

Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/117
Reviewed-by: 段舒康 <kdletters@qq.com>
Co-authored-by: 王德宇 <kvtodev@outlook.com>
Co-committed-by: 王德宇 <kvtodev@outlook.com>
2026-08-06 16:57:38 +08:00

131 lines
3.8 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import type { CanvasLayer } from './ImageCanvasEditorTypes';
import {
buildProjectCoverSnapshotSignature,
normalizeProjectCoverSnapshotViewport,
resolveProjectCoverDrawableLayers,
resolveProjectCoverSnapshotFrame,
} from './ImageCanvasProjectCoverSnapshotModel';
function layer(overrides: Partial<CanvasLayer> = {}): CanvasLayer {
return {
id: 'layer-a',
resourceId: 'resource-a',
title: '图层',
src: '/generated/layer-a.png',
x: 10,
y: 20,
width: 320,
height: 240,
originalWidth: 320,
originalHeight: 240,
zIndex: 2,
sourceType: 'generated',
...overrides,
};
}
describe('ImageCanvasProjectCoverSnapshotModel', () => {
it('uses at least a centered 1280 by 960 viewport while preserving larger viewports', () => {
expect(
normalizeProjectCoverSnapshotViewport({
viewport: { x: 12, y: -8, scale: 0.5 },
viewportSize: { width: 900, height: 640 },
}),
).toEqual({
viewport: { x: 202, y: 152, scale: 0.5 },
viewportSize: { width: 1280, height: 960 },
});
expect(
normalizeProjectCoverSnapshotViewport({
viewport: { x: 12, y: -8, scale: 0.5 },
viewportSize: { width: 1920, height: 1080 },
}),
).toEqual({
viewport: { x: 12, y: -8, scale: 0.5 },
viewportSize: { width: 1920, height: 1080 },
});
});
it('builds a stable cover signature from visible drawable layers', () => {
const signature = buildProjectCoverSnapshotSignature({
viewport: { x: 12, y: -8, scale: 0.75 },
viewportSize: { width: 900, height: 640 },
backgroundColor: '#f8fafc',
layers: [
layer({ id: 'hidden', hidden: true }),
layer({
id: 'audio',
mediaType: 'audio',
src: '/generated/audio.mp3',
}),
layer({
id: 'front',
objectKey: 'generated/front.png',
zIndex: 5,
}),
layer({
id: 'back',
src: '/generated/back.png',
zIndex: 1,
}),
],
});
expect(signature).toContain('"scale":0.75');
expect(signature).toContain('"width":900');
expect(signature).toContain('"backgroundColor":"#f8fafc"');
expect(signature).toContain('"id":"back"');
expect(signature).toContain('"id":"front"');
expect(signature).not.toContain('"id":"hidden"');
expect(signature).not.toContain('"id":"audio"');
});
it('center-crops the live canvas viewport to fill the 4:3 cover', () => {
const landscapeFrame = resolveProjectCoverSnapshotFrame({
viewport: { x: -260, y: 70, scale: 0.5 },
viewportSize: { width: 900, height: 640 },
});
expect(landscapeFrame.renderScale).toBe(0.5);
expect(landscapeFrame.frameScale).toBeCloseTo(0.375);
expect(landscapeFrame.offsetX).toBeCloseTo(-8.75);
expect(landscapeFrame.offsetY).toBeCloseTo(0);
const portraitFrame = resolveProjectCoverSnapshotFrame({
viewport: { x: 30, y: -40, scale: 1.25 },
viewportSize: { width: 640, height: 900 },
});
expect(portraitFrame.renderScale).toBe(1.25);
expect(portraitFrame.frameScale).toBeCloseTo(0.5);
expect(portraitFrame.offsetX).toBeCloseTo(0);
expect(portraitFrame.offsetY).toBeCloseTo(-105);
});
it('uses the first image-sequence frame as the drawable source', () => {
expect(
resolveProjectCoverDrawableLayers([
layer({
mediaType: 'image-sequence',
imageSequenceFrames: [
{
imageSrc: '/generated/frame-1.png',
objectKey: 'generated/frame-1.png',
width: 320,
height: 240,
},
],
}),
]),
).toMatchObject([
{
src: '/generated/frame-1.png',
objectKey: 'generated/frame-1.png',
},
]);
});
});