fix: preserve blocklist on media deletion & optimise watchlist-sync (#2478)
This commit is contained in:
@@ -206,6 +206,19 @@ class Media {
|
|||||||
Object.assign(this, init);
|
Object.assign(this, init);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public resetServiceData(): void {
|
||||||
|
this.serviceId = null;
|
||||||
|
this.serviceId4k = null;
|
||||||
|
this.externalServiceId = null;
|
||||||
|
this.externalServiceId4k = null;
|
||||||
|
this.externalServiceSlug = null;
|
||||||
|
this.externalServiceSlug4k = null;
|
||||||
|
this.ratingKey = null;
|
||||||
|
this.ratingKey4k = null;
|
||||||
|
this.jellyfinMediaId = null;
|
||||||
|
this.jellyfinMediaId4k = null;
|
||||||
|
}
|
||||||
|
|
||||||
@AfterLoad()
|
@AfterLoad()
|
||||||
public setPlexUrls(): void {
|
public setPlexUrls(): void {
|
||||||
const { machineId, webAppUrl } = getSettings().plex;
|
const { machineId, webAppUrl } = getSettings().plex;
|
||||||
|
|||||||
@@ -70,13 +70,33 @@ class WatchlistSync {
|
|||||||
response.items.map((i) => i.tmdbId)
|
response.items.map((i) => i.tmdbId)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const watchlistTmdbIds = response.items.map((i) => i.tmdbId);
|
||||||
|
|
||||||
|
const requestRepository = getRepository(MediaRequest);
|
||||||
|
const existingAutoRequests = await requestRepository
|
||||||
|
.createQueryBuilder('request')
|
||||||
|
.leftJoinAndSelect('request.media', 'media')
|
||||||
|
.where('request.requestedBy = :userId', { userId: user.id })
|
||||||
|
.andWhere('request.isAutoRequest = true')
|
||||||
|
.andWhere('media.tmdbId IN (:...tmdbIds)', { tmdbIds: watchlistTmdbIds })
|
||||||
|
.getMany();
|
||||||
|
|
||||||
|
const autoRequestedTmdbIds = new Set(
|
||||||
|
existingAutoRequests
|
||||||
|
.filter((r) => r.media != null)
|
||||||
|
.map((r) => `${r.media.mediaType}:${r.media.tmdbId}`)
|
||||||
|
);
|
||||||
|
|
||||||
const unavailableItems = response.items.filter(
|
const unavailableItems = response.items.filter(
|
||||||
// If we can find watchlist items in our database that are also available, we should exclude them
|
|
||||||
(i) =>
|
(i) =>
|
||||||
|
!autoRequestedTmdbIds.has(
|
||||||
|
`${i.type === 'show' ? MediaType.TV : MediaType.MOVIE}:${i.tmdbId}`
|
||||||
|
) &&
|
||||||
!mediaItems.find(
|
!mediaItems.find(
|
||||||
(m) =>
|
(m) =>
|
||||||
m.tmdbId === i.tmdbId &&
|
m.tmdbId === i.tmdbId &&
|
||||||
((m.status !== MediaStatus.UNKNOWN && m.mediaType === 'movie') ||
|
(m.status === MediaStatus.BLOCKLISTED ||
|
||||||
|
(m.status !== MediaStatus.UNKNOWN && m.mediaType === 'movie') ||
|
||||||
(m.mediaType === 'tv' && m.status === MediaStatus.AVAILABLE))
|
(m.mediaType === 'tv' && m.status === MediaStatus.AVAILABLE))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -174,7 +174,12 @@ mediaRoutes.delete(
|
|||||||
where: { id: Number(req.params.id) },
|
where: { id: Number(req.params.id) },
|
||||||
});
|
});
|
||||||
|
|
||||||
await mediaRepository.remove(media);
|
if (media.status === MediaStatus.BLOCKLISTED) {
|
||||||
|
media.resetServiceData();
|
||||||
|
await mediaRepository.save(media);
|
||||||
|
} else {
|
||||||
|
await mediaRepository.remove(media);
|
||||||
|
}
|
||||||
|
|
||||||
return res.status(204).send();
|
return res.status(204).send();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user