fix: clear thumbnail cache and temp dirs on new session
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -30,3 +30,7 @@ export async function extractThumbnails(
|
||||
duration,
|
||||
});
|
||||
}
|
||||
|
||||
export async function cleanupThumbnails(paths: string[]): Promise<void> {
|
||||
return invoke<void>('cleanup_thumbnails', { paths });
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ import type { VideoMetadata } from '$lib/bindings/video';
|
||||
import { startDownload } from '$lib/bindings/video';
|
||||
import type { ThumbnailSpritesheet } from '$lib/bindings/mediaAnalysis';
|
||||
import {
|
||||
cleanupThumbnails,
|
||||
extractKeyframes,
|
||||
extractThumbnails,
|
||||
extractWaveform,
|
||||
} from '$lib/bindings/mediaAnalysis';
|
||||
import { clearThumbnailCache } from '$lib/timeline/thumbnailRenderer';
|
||||
|
||||
export type SessionStatus = 'idle' | 'resolving' | 'ready' | 'error';
|
||||
export type DownloadStatus = 'idle' | 'downloading' | 'complete' | 'failed';
|
||||
@@ -112,6 +114,10 @@ async function triggerPostDownloadProcessing(filePath: string) {
|
||||
export async function beginDownload() {
|
||||
if (!session.url) return;
|
||||
|
||||
const oldThumbnailDirs = [
|
||||
...new Set(session.thumbnailSpritesheets.map((sheet) => sheet.filePath)),
|
||||
];
|
||||
clearThumbnailCache();
|
||||
session.downloadStatus = 'downloading';
|
||||
session.downloadProgress = 0;
|
||||
session.localFilePath = null;
|
||||
@@ -119,6 +125,12 @@ export async function beginDownload() {
|
||||
session.waveformPeaks = [];
|
||||
session.thumbnailSpritesheets = [];
|
||||
|
||||
if (oldThumbnailDirs.length > 0) {
|
||||
void cleanupThumbnails(oldThumbnailDirs).catch((err) => {
|
||||
console.error('Thumbnail temp dir cleanup failed:', err);
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await startDownload(
|
||||
session.url,
|
||||
|
||||
@@ -4,6 +4,10 @@ import { timeToX, type TimelineState } from './renderer';
|
||||
|
||||
const imageCache = new Map<string, HTMLImageElement>();
|
||||
|
||||
export function clearThumbnailCache(): void {
|
||||
imageCache.clear();
|
||||
}
|
||||
|
||||
const TARGET_SPACING_PX = 100;
|
||||
|
||||
function getImagePath(dir: string, frameIndex: number): string {
|
||||
|
||||
Reference in New Issue
Block a user