mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
fix: handle Plex library settings migration failure gracefully (#2254)
* fix: handle Plex library settings migration failure gracefully * fix: handle failure in syncLibraries() instead
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import NodePlexAPI from 'plex-api';
|
import NodePlexAPI from 'plex-api';
|
||||||
import { getSettings, Library, PlexSettings } from '../lib/settings';
|
import { getSettings, Library, PlexSettings } from '../lib/settings';
|
||||||
|
import logger from '../logger';
|
||||||
|
|
||||||
export interface PlexLibraryItem {
|
export interface PlexLibraryItem {
|
||||||
ratingKey: string;
|
ratingKey: string;
|
||||||
@@ -145,28 +146,40 @@ class PlexAPI {
|
|||||||
public async syncLibraries(): Promise<void> {
|
public async syncLibraries(): Promise<void> {
|
||||||
const settings = getSettings();
|
const settings = getSettings();
|
||||||
|
|
||||||
const libraries = await this.getLibraries();
|
try {
|
||||||
|
const libraries = await this.getLibraries();
|
||||||
|
|
||||||
const newLibraries: Library[] = libraries
|
const newLibraries: Library[] = libraries
|
||||||
// Remove libraries that are not movie or show
|
// Remove libraries that are not movie or show
|
||||||
.filter((library) => library.type === 'movie' || library.type === 'show')
|
.filter(
|
||||||
// Remove libraries that do not have a metadata agent set (usually personal video libraries)
|
(library) => library.type === 'movie' || library.type === 'show'
|
||||||
.filter((library) => library.agent !== 'com.plexapp.agents.none')
|
)
|
||||||
.map((library) => {
|
// Remove libraries that do not have a metadata agent set (usually personal video libraries)
|
||||||
const existing = settings.plex.libraries.find(
|
.filter((library) => library.agent !== 'com.plexapp.agents.none')
|
||||||
(l) => l.id === library.key && l.name === library.title
|
.map((library) => {
|
||||||
);
|
const existing = settings.plex.libraries.find(
|
||||||
|
(l) => l.id === library.key && l.name === library.title
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: library.key,
|
id: library.key,
|
||||||
name: library.title,
|
name: library.title,
|
||||||
enabled: existing?.enabled ?? false,
|
enabled: existing?.enabled ?? false,
|
||||||
type: library.type,
|
type: library.type,
|
||||||
lastScan: existing?.lastScan,
|
lastScan: existing?.lastScan,
|
||||||
};
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
settings.plex.libraries = newLibraries;
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('Failed to fetch Plex libraries', {
|
||||||
|
label: 'Plex API',
|
||||||
|
message: e.message,
|
||||||
});
|
});
|
||||||
|
|
||||||
settings.plex.libraries = newLibraries;
|
settings.plex.libraries = [];
|
||||||
|
}
|
||||||
|
|
||||||
settings.save();
|
settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -63,11 +63,12 @@ app
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (admin) {
|
if (admin) {
|
||||||
const plexapi = new PlexAPI({ plexToken: admin.plexToken });
|
logger.info('Migrating Plex libraries to include media type', {
|
||||||
await plexapi.syncLibraries();
|
|
||||||
logger.info('Migrating libraries to include media type', {
|
|
||||||
label: 'Settings',
|
label: 'Settings',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const plexapi = new PlexAPI({ plexToken: admin.plexToken });
|
||||||
|
await plexapi.syncLibraries();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user