Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/api/src/opendirector_api/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ def open_project(project_id: UUID, x_opendirector_session: UUID = Header()):

@router.post('/projects/{project_id}/open-canvas')
def open_project_canvas(project_id: UUID, x_opendirector_session: UUID = Header()):
# The canvas needs its reference edges on first render too. Reuse the
# The canvas needs its reference edges and text on first render too. Reuse the
# single snapshot this open read already published instead of making the
# page read the same project again through GET /canvas. The no-flag
# route above still returns a bare ProjectSnapshot.
snapshot = projects.open(project_id, str(x_opendirector_session))
return {'snapshot': snapshot, 'edges': canvas.reference_edges(project_id, snapshot)}
return {'snapshot': snapshot, 'edges': canvas.reference_edges(project_id, snapshot),
'texts': canvas.text_contents(snapshot)}

@router.put('/sessions/{session_id}')
def heartbeat(session_id: UUID, value: Session):
Expand Down
1 change: 1 addition & 0 deletions docs/development/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ node tests/browser/reference_reconnect.mjs # 参考连线删除后重连
node tests/browser/context_menu_dismissal.mjs # 右键菜单关闭
node tests/browser/mp4_export.mjs # 合成 MP4(WebCodecs + 软件 AAC)
node tests/browser/new_image_node_outputs.mjs # 新建图片节点采用所选适配器的比例与尺寸
node tests/browser/canvas_progressive_load.mjs # 画布结构先可用,节点媒体独立加载、失败重试且不改写内容
```

历史版本预览回归([#393](https://github.com/ThinkFlowLab/OpenDirector/issues/393))沿用上述隔离服务:运行 `node tests/browser/node_versions.mjs`;设置 `HISTORY_PREVIEW_PROBE=delay` 会延迟目标缩略图一秒,完整旅程应通过。设置 `HISTORY_PREVIEW_PROBE=missing` 会注入缩略图 404,预期脚本失败并输出 `History preview unavailable`、目标资产 ID、HTTP 状态和媒体提示;它是故障诊断检查,不是成功旅程。清除变量后恢复正常运行。布局断言必须等待预期资产的图片加载成功,不能以提示词出现代替预览就绪。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ def open_media(self, project_id, asset_id, *, snapshot=None):
with self.projects.local.transaction() as db:
self.projects._recover()
if snapshot is None:
path, _, records = self.projects._load(db, project_id)
snapshot = records[0].snapshot
# A head whose chain was already proven needs no replay per read.
path, manifest = self.projects._find(db, project_id)
record, validated = self.projects._current_record(db, project_id, path, manifest)
snapshot = (record if validated else self.projects._load(db, project_id)[2][0]).snapshot
else:
if snapshot.project.id != UUID(str(project_id)):
raise ProjectError('素材读取快照不属于当前工程。', 409)
Expand Down
18 changes: 18 additions & 0 deletions packages/core/src/opendirector/application/creation_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,24 @@ def check_asset(asset):

return check_asset

def text_contents(self, snapshot):
"""Text shown by canvas items, read with the snapshot that opens the canvas.

An unreadable body is left out so only that item reports it.
"""
contents = {}
for item in snapshot.canvasItems:
asset = current_asset(snapshot, item)
if asset is None or asset.kind != 'text' or str(asset.id) in contents:
continue
try:
stream, _ = self.assets.open_media(asset.projectId, asset.id, snapshot=snapshot)
with stream:
contents[str(asset.id)] = stream.read().decode('utf-8-sig', 'replace')
except (ContractError, ProjectError, OSError):
continue
return contents

def reference_edges(self, project_id, snapshot=None, check_asset=None):
"""Authoritative canvas reference states for one snapshot.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def reference_catalog(self, project_id):
for asset in snapshot.assets:
file_available = True
try:
service.reference_available(project_id, asset.id)
service.reference_available(project_id, asset.id, snapshot=snapshot)
except (ContractError, ProjectError, OSError, ValueError):
file_available = False
available = file_available and (asset.id in listed or asset.id in owners)
Expand Down
4 changes: 4 additions & 0 deletions scripts/run-browser-suite.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const workflows = [
name: "canvas switch",
script: "tests/browser/canvas_switch.mjs",
},
{
name: "canvas progressive load",
script: "tests/browser/canvas_progressive_load.mjs",
},
{
name: "structured editors",
script: "tests/browser/structured_editors.mjs",
Expand Down
17 changes: 17 additions & 0 deletions src/backend/assetSource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** A stable reference to a saved asset in a node's media fields.
*
* Object URLs depend on what this page has loaded, so they cannot describe
* project content. This value stays the same before and after the bytes arrive
* and is resolved only where media is displayed or read. */
const PREFIX = "opendirector-asset://";

export const assetSource = (projectId: string, assetId: string) =>
`${PREFIX}${projectId}/${assetId}`;

export function parseAssetSource(src: string | null | undefined) {
if (!src?.startsWith(PREFIX)) return undefined;
const [projectId, assetId, extra] = src.slice(PREFIX.length).split("/");
return projectId && assetId && extra === undefined
? { projectId, assetId }
: undefined;
}
Loading
Loading