refactor: reuse director file-key segment lookup

This commit is contained in:
OpenClaw Agent
2026-07-09 15:09:50 +00:00
parent a1a4be4fc3
commit 268e543210

View File

@@ -1570,9 +1570,7 @@ class TimelineEditor {
for (let i = 0; i < numFrames; i++) { for (let i = 0; i < numFrames; i++) {
// Check if the file/segment is still active in the current timeline // Check if the file/segment is still active in the current timeline
const exists = this.timeline.segments.find(s => s.imageFile === fileKey || s.videoFile === fileKey || s._blobUrl === fileKey) || const exists = this._getSegmentsByFileKey(fileKey).length > 0;
this.timeline.motionSegments.find(s => s.imageFile === fileKey || s.videoFile === fileKey || s._blobUrl === fileKey) ||
(this.timeline.retakeVideo && (this.timeline.retakeVideo.imageFile === fileKey || this.timeline.retakeVideo._blobUrl === fileKey));
if (!exists) break; if (!exists) break;
const time = (i / numFrames) * duration; const time = (i / numFrames) * duration;
@@ -1593,13 +1591,7 @@ class TimelineEditor {
thumbs.push({ time, img }); thumbs.push({ time, img });
// Propagate the partial progress live to all active segments sharing this file // Propagate the partial progress live to all active segments sharing this file
const matchingSegs = [ const matchingSegs = this._getSegmentsByFileKey(fileKey);
...this.timeline.segments.filter(s => s.imageFile === fileKey || s.videoFile === fileKey || s._blobUrl === fileKey),
...(this.timeline.motionSegments || []).filter(s => s.imageFile === fileKey || s.videoFile === fileKey || s._blobUrl === fileKey)
];
if (this.timeline.retakeVideo && (this.timeline.retakeVideo.imageFile === fileKey || this.timeline.retakeVideo._blobUrl === fileKey)) {
matchingSegs.push(this.timeline.retakeVideo);
}
for (const ms of matchingSegs) { for (const ms of matchingSegs) {
ms.thumbnails = thumbs; ms.thumbnails = thumbs;
} }
@@ -1627,13 +1619,7 @@ class TimelineEditor {
const thumbs = await extractPromise; const thumbs = await extractPromise;
this._thumbnailCache.set(fileKey, thumbs); this._thumbnailCache.set(fileKey, thumbs);
const matchingSegs = [ const matchingSegs = this._getSegmentsByFileKey(fileKey);
...this.timeline.segments.filter(s => s.imageFile === fileKey || s.videoFile === fileKey || s._blobUrl === fileKey),
...(this.timeline.motionSegments || []).filter(s => s.imageFile === fileKey || s.videoFile === fileKey || s._blobUrl === fileKey)
];
if (this.timeline.retakeVideo && (this.timeline.retakeVideo.imageFile === fileKey || this.timeline.retakeVideo._blobUrl === fileKey)) {
matchingSegs.push(this.timeline.retakeVideo);
}
for (const ms of matchingSegs) { for (const ms of matchingSegs) {
ms.thumbnails = thumbs; ms.thumbnails = thumbs;
ms._extractingThumbs = false; ms._extractingThumbs = false;
@@ -1648,13 +1634,7 @@ class TimelineEditor {
} }
} catch (err) { } catch (err) {
console.error("Extraction error:", err); console.error("Extraction error:", err);
const matchingSegs = [ const matchingSegs = this._getSegmentsByFileKey(fileKey);
...this.timeline.segments.filter(s => s.imageFile === fileKey || s.videoFile === fileKey || s._blobUrl === fileKey),
...(this.timeline.motionSegments || []).filter(s => s.imageFile === fileKey || s.videoFile === fileKey || s._blobUrl === fileKey)
];
if (this.timeline.retakeVideo && (this.timeline.retakeVideo.imageFile === fileKey || this.timeline.retakeVideo._blobUrl === fileKey)) {
matchingSegs.push(this.timeline.retakeVideo);
}
for (const ms of matchingSegs) { for (const ms of matchingSegs) {
ms._extractingThumbs = false; ms._extractingThumbs = false;
} }
@@ -1960,6 +1940,21 @@ class TimelineEditor {
return api.apiURL(`/view?filename=${encodeURIComponent(filename)}&type=input&subfolder=${encodeURIComponent(subfolder)}`); return api.apiURL(`/view?filename=${encodeURIComponent(filename)}&type=input&subfolder=${encodeURIComponent(subfolder)}`);
} }
_segmentMatchesFileKey(seg, fileKey) {
return !!seg && (seg.imageFile === fileKey || seg.videoFile === fileKey || seg._blobUrl === fileKey);
}
_getSegmentsByFileKey(fileKey) {
const matches = [
...(this.timeline.segments || []).filter(s => this._segmentMatchesFileKey(s, fileKey)),
...(this.timeline.motionSegments || []).filter(s => this._segmentMatchesFileKey(s, fileKey)),
];
if (this._segmentMatchesFileKey(this.timeline.retakeVideo, fileKey)) {
matches.push(this.timeline.retakeVideo);
}
return matches;
}
async _decodeBase64Audio(audioB64) { async _decodeBase64Audio(audioB64) {
const binaryString = window.atob(audioB64); const binaryString = window.atob(audioB64);
const len = binaryString.length; const len = binaryString.length;