forked from Fallenbagel/jellyseerr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: blacklist items from Discover page (Fallenbagel#632)
* feat: blacklist media items re Fallenbagel#490 * feat: blacklist media items * feat: blacklist media items * style: formatting * refactor: close the manage slide-over when the media item is removed from the blacklist * fix: fix media data in the db when blacklisting an item * refactor: refactor component to accept show boolean * refactor: hide watchlist button in the media page when it's blacklisted. Also add a blacklist button * style: formatting --------- Co-authored-by: JoaquinOlivero <[email protected]>
- Loading branch information
Showing
30 changed files
with
1,939 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ export enum MediaStatus { | |
PROCESSING, | ||
PARTIALLY_AVAILABLE, | ||
AVAILABLE, | ||
BLACKLISTED, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { MediaStatus, type MediaType } from '@server/constants/media'; | ||
import { getRepository } from '@server/datasource'; | ||
import Media from '@server/entity/Media'; | ||
import { User } from '@server/entity/User'; | ||
import type { BlacklistItem } from '@server/interfaces/api/blacklistInterfaces'; | ||
import { | ||
Column, | ||
CreateDateColumn, | ||
Entity, | ||
Index, | ||
JoinColumn, | ||
ManyToOne, | ||
OneToOne, | ||
PrimaryGeneratedColumn, | ||
Unique, | ||
} from 'typeorm'; | ||
import type { ZodNumber, ZodOptional, ZodString } from 'zod'; | ||
|
||
@Entity() | ||
@Unique(['tmdbId']) | ||
export class Blacklist implements BlacklistItem { | ||
@PrimaryGeneratedColumn() | ||
public id: number; | ||
|
||
@Column({ type: 'varchar' }) | ||
public mediaType: MediaType; | ||
|
||
@Column({ nullable: true, type: 'varchar' }) | ||
title?: string; | ||
|
||
@Column() | ||
@Index() | ||
public tmdbId: number; | ||
|
||
@ManyToOne(() => User, (user) => user.id, { | ||
eager: true, | ||
}) | ||
user: User; | ||
|
||
@OneToOne(() => Media, (media) => media.blacklist, { | ||
onDelete: 'CASCADE', | ||
}) | ||
@JoinColumn() | ||
public media: Media; | ||
|
||
@CreateDateColumn() | ||
public createdAt: Date; | ||
|
||
constructor(init?: Partial<Blacklist>) { | ||
Object.assign(this, init); | ||
} | ||
|
||
public static async addToBlacklist({ | ||
blacklistRequest, | ||
}: { | ||
blacklistRequest: { | ||
mediaType: MediaType; | ||
title?: ZodOptional<ZodString>['_output']; | ||
tmdbId: ZodNumber['_output']; | ||
}; | ||
}): Promise<void> { | ||
const blacklist = new this({ | ||
...blacklistRequest, | ||
}); | ||
|
||
const mediaRepository = getRepository(Media); | ||
let media = await mediaRepository.findOne({ | ||
where: { | ||
tmdbId: blacklistRequest.tmdbId, | ||
}, | ||
}); | ||
|
||
const blacklistRepository = getRepository(this); | ||
|
||
await blacklistRepository.save(blacklist); | ||
|
||
if (!media) { | ||
media = new Media({ | ||
tmdbId: blacklistRequest.tmdbId, | ||
status: MediaStatus.BLACKLISTED, | ||
status4k: MediaStatus.BLACKLISTED, | ||
mediaType: blacklistRequest.mediaType, | ||
blacklist: blacklist, | ||
}); | ||
|
||
await mediaRepository.save(media); | ||
} else { | ||
media.blacklist = blacklist; | ||
media.status = MediaStatus.BLACKLISTED; | ||
media.status4k = MediaStatus.BLACKLISTED; | ||
|
||
await mediaRepository.save(media); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { User } from '@server/entity/User'; | ||
import type { PaginatedResponse } from '@server/interfaces/api/common'; | ||
|
||
export interface BlacklistItem { | ||
tmdbId: number; | ||
mediaType: 'movie' | 'tv'; | ||
title?: string; | ||
createdAt?: Date; | ||
user: User; | ||
} | ||
|
||
export interface BlacklistResultsResponse extends PaginatedResponse { | ||
results: BlacklistItem[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AddBlacklist1699901142442 implements MigrationInterface { | ||
name = 'AddBlacklist1699901142442'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TABLE "blacklist" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "mediaType" varchar NOT NULL, "title" varchar, "tmdbId" integer NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')),"userId" integer, "mediaId" integer,CONSTRAINT "UQ_6bbafa28411e6046421991ea21c" UNIQUE ("tmdbId", "userId"))` | ||
); | ||
|
||
await queryRunner.query( | ||
`CREATE INDEX "IDX_6bbafa28411e6046421991ea21" ON "blacklist" ("tmdbId") ` | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP TABLE "blacklist"`); | ||
await queryRunner.query(`DROP INDEX "IDX_6bbafa28411e6046421991ea21"`); | ||
} | ||
} |
Oops, something went wrong.