Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions server/entity/Media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,27 @@ class Media {
@Column({ nullable: true, type: 'varchar' })
public ratingKey4k?: string | null;

@Column({
type: 'text',
nullable: true,
transformer: {
from: (value: string | null): string[] | null => {
if (value == null) {
return null;
}
try {
const parsed = JSON.parse(value);
return Array.isArray(parsed) ? parsed : null;
} catch {
return null;
}
},
to: (value: string[] | null): string | null =>
value == null ? null : JSON.stringify(value),
},
})
public plexRatingKeys?: string[] | null;

@Column({ nullable: true, type: 'varchar' })
public jellyfinMediaId?: string | null;

Expand All @@ -237,6 +258,36 @@ class Media {
Object.assign(this, init);
}

public addPlexRatingKey(ratingKey?: string | null): boolean {
if (!ratingKey) {
return false;
}

const keys = this.getPlexRatingKeys();
if (keys.includes(ratingKey)) {
if (this.plexRatingKeys != null) {
return false;
}
this.plexRatingKeys = keys;
return true;
}

this.plexRatingKeys = [...keys, ratingKey];
return true;
}

public getPlexRatingKeys(): string[] {
if (this.plexRatingKeys) {
return this.plexRatingKeys;
}

return [
...new Set(
[this.ratingKey, this.ratingKey4k].filter((key): key is string => !!key)
),
];
}

public resetServiceData(is4k?: boolean): void {
if (is4k === undefined || !is4k) {
this.serviceId = null;
Expand All @@ -252,6 +303,9 @@ class Media {
this.ratingKey4k = null;
this.jellyfinMediaId4k = null;
}
if (is4k === undefined) {
this.plexRatingKeys = null;
}
}

@AfterLoad()
Expand Down
Loading
Loading