diff --git a/overseerr-api.yml b/overseerr-api.yml index ef3ccf8b3..9e2505f48 100644 --- a/overseerr-api.yml +++ b/overseerr-api.yml @@ -4142,6 +4142,21 @@ paths: '412': description: Item has already been blacklisted /blacklist/{tmdbId}: + get: + summary: Get media from blacklist + tags: + - blacklist + parameters: + - in: path + name: tmdbId + description: tmdbId ID + required: true + example: '1' + schema: + type: string + responses: + '200': + description: Blacklist details in JSON delete: summary: Remove media from blacklist tags: diff --git a/server/routes/blacklist.ts b/server/routes/blacklist.ts index 4a07a4998..b8748a6ce 100644 --- a/server/routes/blacklist.ts +++ b/server/routes/blacklist.ts @@ -2,14 +2,13 @@ import { MediaType } from '@server/constants/media'; import { getRepository } from '@server/datasource'; import { Blacklist } from '@server/entity/Blacklist'; import Media from '@server/entity/Media'; -import { NotFoundError } from '@server/entity/Watchlist'; import type { BlacklistResultsResponse } from '@server/interfaces/api/blacklistInterfaces'; import { Permission } from '@server/lib/permissions'; import logger from '@server/logger'; import { isAuthenticated } from '@server/middleware/auth'; import { Router } from 'express'; import rateLimit from 'express-rate-limit'; -import { QueryFailedError } from 'typeorm'; +import { EntityNotFoundError, QueryFailedError } from 'typeorm'; import { z } from 'zod'; const blacklistRoutes = Router(); @@ -71,6 +70,32 @@ blacklistRoutes.get( } ); +blacklistRoutes.get( + '/:id', + isAuthenticated([Permission.MANAGE_BLACKLIST], { + type: 'or', + }), + async (req, res, next) => { + try { + const blacklisteRepository = getRepository(Blacklist); + + const blacklistItem = await blacklisteRepository.findOneOrFail({ + where: { tmdbId: Number(req.params.id) }, + }); + + return res.status(200).send(blacklistItem); + } catch (e) { + if (e instanceof EntityNotFoundError) { + return next({ + status: 401, + message: e.message, + }); + } + return next({ status: 500, message: e.message }); + } + } +); + blacklistRoutes.post( '/', isAuthenticated([Permission.MANAGE_BLACKLIST], { @@ -134,7 +159,7 @@ blacklistRoutes.delete( return res.status(204).send(); } catch (e) { - if (e instanceof NotFoundError) { + if (e instanceof EntityNotFoundError) { return next({ status: 401, message: e.message, diff --git a/src/components/BlacklistBlock/index.tsx b/src/components/BlacklistBlock/index.tsx index 0908d3735..8d619aa3c 100644 --- a/src/components/BlacklistBlock/index.tsx +++ b/src/components/BlacklistBlock/index.tsx @@ -1,5 +1,6 @@ import Badge from '@app/components/Common/Badge'; import Button from '@app/components/Common/Button'; +import LoadingSpinner from '@app/components/Common/LoadingSpinner'; import Tooltip from '@app/components/Common/Tooltip'; import { useUser } from '@app/hooks/useUser'; import globalMessages from '@app/i18n/globalMessages'; @@ -10,6 +11,7 @@ import Link from 'next/link'; import { useState } from 'react'; import { useIntl } from 'react-intl'; import { useToasts } from 'react-toast-notifications'; +import useSWR from 'swr'; const messages = defineMessages('component.BlacklistBlock', { blacklistedby: 'Blacklisted By', @@ -17,13 +19,13 @@ const messages = defineMessages('component.BlacklistBlock', { }); interface BlacklistBlockProps { - blacklistItem: Blacklist; + tmdbId: number; onUpdate?: () => void; onDelete?: () => void; } const BlacklistBlock = ({ - blacklistItem, + tmdbId, onUpdate, onDelete, }: BlacklistBlockProps) => { @@ -31,6 +33,7 @@ const BlacklistBlock = ({ const intl = useIntl(); const [isUpdating, setIsUpdating] = useState(false); const { addToast } = useToasts(); + const { data } = useSWR(`/api/v1/blacklist/${tmdbId}`); const removeFromBlacklist = async (tmdbId: number, title?: string) => { setIsUpdating(true); @@ -62,6 +65,14 @@ const BlacklistBlock = ({ setIsUpdating(false); }; + if (!data) { + return ( + <> + + + ); + } + return (
@@ -73,13 +84,13 @@ const BlacklistBlock = ({ - {blacklistItem.user.displayName} + {data.user.displayName} @@ -91,9 +102,7 @@ const BlacklistBlock = ({ >