Add methods to clear stale unified video library data
- Modified updateUnifiedVideoStorage to detect mismatched video counts - Added clearUnifiedVideoLibrary() to remove stale data - Added forceRefreshVideoLibrary() to clear and refresh completely - Fixed logic to force refresh when current directories don't match stored data - Should resolve issue with 60 stale videos preventing proper scanning of 18 actual videos
This commit is contained in:
parent
285bce4dac
commit
5931d643cb
|
|
@ -507,20 +507,26 @@ class DesktopFileManager {
|
|||
async updateUnifiedVideoStorage() {
|
||||
// Store all videos in a single unified list (no categories)
|
||||
|
||||
// If we have no linked directories but there are existing videos in storage,
|
||||
// don't overwrite the existing data
|
||||
if (this.externalVideoDirectories.length === 0 && this.allLinkedVideos.length === 0) {
|
||||
// Check if there are existing videos in storage
|
||||
try {
|
||||
const existingData = JSON.parse(localStorage.getItem('unifiedVideoLibrary') || '{}');
|
||||
if (existingData.allVideos && existingData.allVideos.length > 0) {
|
||||
console.log(`📹 Preserving existing unified video library: ${existingData.allVideos.length} videos`);
|
||||
// Don't overwrite - preserve existing data
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Error checking existing unified video library:', error);
|
||||
// Check if we should clear stale data - if we have current video directories/files
|
||||
// but the unified library count doesn't match, clear it
|
||||
const currentVideoCount = this.allLinkedVideos.length;
|
||||
const currentDirectoryCount = this.externalVideoDirectories.length;
|
||||
|
||||
try {
|
||||
const existingData = JSON.parse(localStorage.getItem('unifiedVideoLibrary') || '{}');
|
||||
const existingVideoCount = existingData.allVideos ? existingData.allVideos.length : 0;
|
||||
|
||||
// If we have a significant mismatch or the user has video directories but
|
||||
// unified library shows different count, force refresh
|
||||
if (currentDirectoryCount > 0 || currentVideoCount !== existingVideoCount) {
|
||||
console.log(`📹 Forcing refresh - Current: ${currentVideoCount} videos, ${currentDirectoryCount} directories. Stored: ${existingVideoCount} videos`);
|
||||
} else if (this.externalVideoDirectories.length === 0 && this.allLinkedVideos.length === 0 && existingVideoCount > 0) {
|
||||
console.log(`📹 Preserving existing unified video library: ${existingVideoCount} videos`);
|
||||
// Don't overwrite - preserve existing data
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Error checking existing unified video library:', error);
|
||||
}
|
||||
|
||||
const videoData = {
|
||||
|
|
@ -530,12 +536,32 @@ class DesktopFileManager {
|
|||
};
|
||||
|
||||
localStorage.setItem('unifiedVideoLibrary', JSON.stringify(videoData));
|
||||
console.log(`📹 Updated unified video library: ${this.allLinkedVideos.length} videos from ${this.externalVideoDirectories.length} directories`);
|
||||
console.log(`📹 Updated unified video library: ${this.allLinkedVideos.length} videos from ${this.externalVideoDirectories.length} directories`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear stale unified video library data and force refresh
|
||||
*/
|
||||
clearUnifiedVideoLibrary() {
|
||||
console.log('🗑️ Clearing unified video library...');
|
||||
localStorage.removeItem('unifiedVideoLibrary');
|
||||
console.log('✅ Unified video library cleared');
|
||||
}
|
||||
|
||||
/**
|
||||
* Force refresh of all video data
|
||||
*/
|
||||
async forceRefreshVideoLibrary() {
|
||||
console.log('🔄 Force refreshing video library...');
|
||||
this.clearUnifiedVideoLibrary();
|
||||
await this.refreshAllLinkedDirectories();
|
||||
|
||||
// Trigger video manager reload if it exists
|
||||
if (window.videoPlayerManager) {
|
||||
window.videoPlayerManager.loadVideoFiles();
|
||||
}
|
||||
|
||||
console.log('✅ Video library force refresh complete');
|
||||
}
|
||||
|
||||
getDirectoryName(directoryPath) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue