refactor: reuse director file-key segment lookup
This commit is contained in:
@@ -1570,9 +1570,7 @@ class TimelineEditor {
|
||||
|
||||
for (let i = 0; i < numFrames; i++) {
|
||||
// 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) ||
|
||||
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));
|
||||
const exists = this._getSegmentsByFileKey(fileKey).length > 0;
|
||||
if (!exists) break;
|
||||
|
||||
const time = (i / numFrames) * duration;
|
||||
@@ -1593,13 +1591,7 @@ class TimelineEditor {
|
||||
thumbs.push({ time, img });
|
||||
|
||||
// Propagate the partial progress live to all active segments sharing this file
|
||||
const matchingSegs = [
|
||||
...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);
|
||||
}
|
||||
const matchingSegs = this._getSegmentsByFileKey(fileKey);
|
||||
for (const ms of matchingSegs) {
|
||||
ms.thumbnails = thumbs;
|
||||
}
|
||||
@@ -1627,13 +1619,7 @@ class TimelineEditor {
|
||||
const thumbs = await extractPromise;
|
||||
this._thumbnailCache.set(fileKey, thumbs);
|
||||
|
||||
const matchingSegs = [
|
||||
...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);
|
||||
}
|
||||
const matchingSegs = this._getSegmentsByFileKey(fileKey);
|
||||
for (const ms of matchingSegs) {
|
||||
ms.thumbnails = thumbs;
|
||||
ms._extractingThumbs = false;
|
||||
@@ -1648,13 +1634,7 @@ class TimelineEditor {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Extraction error:", err);
|
||||
const matchingSegs = [
|
||||
...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);
|
||||
}
|
||||
const matchingSegs = this._getSegmentsByFileKey(fileKey);
|
||||
for (const ms of matchingSegs) {
|
||||
ms._extractingThumbs = false;
|
||||
}
|
||||
@@ -1960,6 +1940,21 @@ class TimelineEditor {
|
||||
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) {
|
||||
const binaryString = window.atob(audioB64);
|
||||
const len = binaryString.length;
|
||||
|
||||
Reference in New Issue
Block a user