mirror of
https://github.com/fallenbagel/jellyseerr.git
synced 2026-01-01 04:08:45 -05:00
fix(externalapi): clear cache after a request is made (#1217)
This PR clears the Radarr/Sonarr cache after a request has been made, because the media status on Radarr/Sonarr will no longer be good. It also resolves a bug that prevented the media from being deleted after a request had been sent to Radarr/Sonarr. fix #1207
This commit is contained in:
@@ -293,6 +293,14 @@ class ExternalAPI {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected removeCache(endpoint: string, params?: Record<string, string>) {
|
||||||
|
const cacheKey = this.serializeCacheKey(endpoint, {
|
||||||
|
...this.params,
|
||||||
|
...params,
|
||||||
|
});
|
||||||
|
this.cache?.del(cacheKey);
|
||||||
|
}
|
||||||
|
|
||||||
private formatUrl(
|
private formatUrl(
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
params?: Record<string, string>,
|
params?: Record<string, string>,
|
||||||
|
|||||||
@@ -230,6 +230,23 @@ class RadarrAPI extends ServarrBase<{ movieId: number }> {
|
|||||||
throw new Error(`[Radarr] Failed to remove movie: ${e.message}`);
|
throw new Error(`[Radarr] Failed to remove movie: ${e.message}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public clearCache = ({
|
||||||
|
tmdbId,
|
||||||
|
externalId,
|
||||||
|
}: {
|
||||||
|
tmdbId?: number | null;
|
||||||
|
externalId?: number | null;
|
||||||
|
}) => {
|
||||||
|
if (tmdbId) {
|
||||||
|
this.removeCache('/movie/lookup', {
|
||||||
|
term: `tmdb:${tmdbId}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (externalId) {
|
||||||
|
this.removeCache(`/movie/${externalId}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default RadarrAPI;
|
export default RadarrAPI;
|
||||||
|
|||||||
@@ -353,6 +353,30 @@ class SonarrAPI extends ServarrBase<{
|
|||||||
throw new Error(`[Radarr] Failed to remove serie: ${e.message}`);
|
throw new Error(`[Radarr] Failed to remove serie: ${e.message}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public clearCache = ({
|
||||||
|
tvdbId,
|
||||||
|
externalId,
|
||||||
|
title,
|
||||||
|
}: {
|
||||||
|
tvdbId?: number | null;
|
||||||
|
externalId?: number | null;
|
||||||
|
title?: string | null;
|
||||||
|
}) => {
|
||||||
|
if (tvdbId) {
|
||||||
|
this.removeCache('/series/lookup', {
|
||||||
|
term: `tvdb:${tvdbId}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (externalId) {
|
||||||
|
this.removeCache(`/series/${externalId}`);
|
||||||
|
}
|
||||||
|
if (title) {
|
||||||
|
this.removeCache('/series/lookup', {
|
||||||
|
term: title,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SonarrAPI;
|
export default SonarrAPI;
|
||||||
|
|||||||
@@ -1006,6 +1006,14 @@ export class MediaRequest {
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.sendNotification(media, Notification.MEDIA_FAILED);
|
this.sendNotification(media, Notification.MEDIA_FAILED);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
radarr.clearCache({
|
||||||
|
tmdbId: movie.id,
|
||||||
|
externalId: this.is4k
|
||||||
|
? media.externalServiceId4k
|
||||||
|
: media.externalServiceId,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
logger.info('Sent request to Radarr', {
|
logger.info('Sent request to Radarr', {
|
||||||
label: 'Media Request',
|
label: 'Media Request',
|
||||||
@@ -1288,6 +1296,15 @@ export class MediaRequest {
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.sendNotification(media, Notification.MEDIA_FAILED);
|
this.sendNotification(media, Notification.MEDIA_FAILED);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
sonarr.clearCache({
|
||||||
|
tvdbId,
|
||||||
|
externalId: this.is4k
|
||||||
|
? media.externalServiceId4k
|
||||||
|
: media.externalServiceId,
|
||||||
|
title: series.name,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
logger.info('Sent request to Sonarr', {
|
logger.info('Sent request to Sonarr', {
|
||||||
label: 'Media Request',
|
label: 'Media Request',
|
||||||
|
|||||||
Reference in New Issue
Block a user