Skip to content

Commit

Permalink
fix(rules): Fixed an issue where the 'Plex - present in amount of oth…
Browse files Browse the repository at this point in the history
…er collections' rule wouldn't work with custom collections

* fix(rules): Fixed an issue where the 'Plex - present in amount of other collections' rule wouldn't work with custom collections

* chore: Update import
  • Loading branch information
jorenn92 authored Jan 27, 2024
1 parent b721d20 commit 493a3ea
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions server/src/modules/api/lib/plexApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class PlexApi extends NodePlexAPI {
this.cache = cacheManager.getCache('plexguid');
}

async query<T>(options): Promise<T> {
return this.queryWithCache(options, true);
async query<T>(options, docache: boolean = true): Promise<T> {
return this.queryWithCache(options, docache);
}

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ class PlexApi extends NodePlexAPI {
return result as unknown as T;
}

async queryWithCache<T>(options, doCache: boolean): Promise<T> {
async queryWithCache<T>(options, doCache: boolean = true): Promise<T> {
if (typeof options === 'string') {
options = {
uri: options,
Expand Down
11 changes: 11 additions & 0 deletions server/src/modules/api/plex-api/plex-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { EPlexDataType } from './enums/plex-data-type-enum';
import axios from 'axios';
import PlexApi from '../lib/plexApi';
import PlexTvApi from '../lib/plextvApi';
import cacheManager from '../../api/lib/cache';

@Injectable()
export class PlexApiService {
Expand Down Expand Up @@ -237,6 +238,7 @@ export class PlexApiService {
public async getMetadata(
key: string,
options: { includeChildren?: boolean } = {},
useCache: boolean = true,
): Promise<PlexMetadata> {
try {
const response = await this.plexClient.query<PlexMetadataResponse>(
Expand All @@ -245,6 +247,7 @@ export class PlexApiService {
? '?includeChildren=1&includeExternalMedia=1&asyncAugmentMetadata=1&asyncCheckFiles=1&asyncRefreshAnalysis=1'
: ''
}`,
useCache,
);
if (response) {
return response.MediaContainer.Metadata[0];
Expand All @@ -260,6 +263,14 @@ export class PlexApiService {
}
}

public resetMetadataCache(mediaId: string) {
cacheManager.getCache('plexguid').data.del(
JSON.stringify({
uri: `/library/metadata/${mediaId}`,
}),
);
}

public async getDiscoverDataUserState(
metaDataRatingKey: string,
): Promise<any> {
Expand Down
4 changes: 2 additions & 2 deletions server/src/modules/rules/getter/plex-getter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export class PlexGetterService {
? metadata.Collection.filter(
(el) =>
el.tag.toLowerCase().trim() !==
(ruleGroup.manualCollectionName
? ruleGroup.manualCollectionName
(ruleGroup?.collection?.manualCollection
? ruleGroup.collection.manualCollectionName
: ruleGroup.name
)
.toLowerCase()
Expand Down
1 change: 1 addition & 0 deletions server/src/modules/rules/rules.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ export class RulesService {
rulegroupId: number,
mediaId: string,
): Promise<any> {
this.plexApi.resetMetadataCache(mediaId);
const mediaResp = await this.plexApi.getMetadata(mediaId);
const group = await this.getRuleGroupById(rulegroupId);
if (group && mediaResp) {
Expand Down

0 comments on commit 493a3ea

Please sign in to comment.