refactor: rename blacklist to blocklist (#2157)
Signed-off-by: 0xsysr3ll <0xsysr3ll@pm.me> Co-authored-by: fallenbagel <98979876+Fallenbagel@users.noreply.github.com> Co-authored-by: 0xsysr3ll <0xsysr3ll@pm.me> Co-authored-by: gauthier-th <mail@gauthierth.fr>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { MediaType } from '@server/constants/media';
|
||||
import { getRepository } from '@server/datasource';
|
||||
import { Blacklist } from '@server/entity/Blacklist';
|
||||
import { Blocklist } from '@server/entity/Blocklist';
|
||||
import Media from '@server/entity/Media';
|
||||
import type { BlacklistResultsResponse } from '@server/interfaces/api/blacklistInterfaces';
|
||||
import type { BlocklistResultsResponse } from '@server/interfaces/api/blocklistInterfaces';
|
||||
import { Permission } from '@server/lib/permissions';
|
||||
import logger from '@server/logger';
|
||||
import { isAuthenticated } from '@server/middleware/auth';
|
||||
@@ -10,53 +10,53 @@ import { Router } from 'express';
|
||||
import { EntityNotFoundError, QueryFailedError } from 'typeorm';
|
||||
import { z } from 'zod';
|
||||
|
||||
const blacklistRoutes = Router();
|
||||
const blocklistRoutes = Router();
|
||||
|
||||
export const blacklistAdd = z.object({
|
||||
export const blocklistAdd = z.object({
|
||||
tmdbId: z.coerce.number(),
|
||||
mediaType: z.nativeEnum(MediaType),
|
||||
title: z.coerce.string().optional(),
|
||||
user: z.coerce.number(),
|
||||
});
|
||||
|
||||
const blacklistGet = z.object({
|
||||
const blocklistGet = z.object({
|
||||
take: z.coerce.number().int().positive().default(25),
|
||||
skip: z.coerce.number().int().nonnegative().default(0),
|
||||
search: z.string().optional(),
|
||||
filter: z.enum(['all', 'manual', 'blacklistedTags']).optional(),
|
||||
filter: z.enum(['all', 'manual', 'blocklistedTags']).optional(),
|
||||
});
|
||||
|
||||
blacklistRoutes.get(
|
||||
blocklistRoutes.get(
|
||||
'/',
|
||||
isAuthenticated([Permission.MANAGE_BLACKLIST, Permission.VIEW_BLACKLIST], {
|
||||
isAuthenticated([Permission.MANAGE_BLOCKLIST, Permission.VIEW_BLOCKLIST], {
|
||||
type: 'or',
|
||||
}),
|
||||
async (req, res, next) => {
|
||||
const { take, skip, search, filter } = blacklistGet.parse(req.query);
|
||||
const { take, skip, search, filter } = blocklistGet.parse(req.query);
|
||||
|
||||
try {
|
||||
let query = getRepository(Blacklist)
|
||||
.createQueryBuilder('blacklist')
|
||||
.leftJoinAndSelect('blacklist.user', 'user')
|
||||
let query = getRepository(Blocklist)
|
||||
.createQueryBuilder('blocklist')
|
||||
.leftJoinAndSelect('blocklist.user', 'user')
|
||||
.where('1 = 1'); // Allow use of andWhere later
|
||||
|
||||
switch (filter) {
|
||||
case 'manual':
|
||||
query = query.andWhere('blacklist.blacklistedTags IS NULL');
|
||||
query = query.andWhere('blocklist.blocklistedTags IS NULL');
|
||||
break;
|
||||
case 'blacklistedTags':
|
||||
query = query.andWhere('blacklist.blacklistedTags IS NOT NULL');
|
||||
case 'blocklistedTags':
|
||||
query = query.andWhere('blocklist.blocklistedTags IS NOT NULL');
|
||||
break;
|
||||
}
|
||||
|
||||
if (search) {
|
||||
query = query.andWhere('blacklist.title like :title', {
|
||||
query = query.andWhere('blocklist.title like :title', {
|
||||
title: `%${search}%`,
|
||||
});
|
||||
}
|
||||
|
||||
const [blacklistedItems, itemsCount] = await query
|
||||
.orderBy('blacklist.createdAt', 'DESC')
|
||||
const [blocklistedItems, itemsCount] = await query
|
||||
.orderBy('blocklist.createdAt', 'DESC')
|
||||
.take(take)
|
||||
.skip(skip)
|
||||
.getManyAndCount();
|
||||
@@ -68,35 +68,35 @@ blacklistRoutes.get(
|
||||
results: itemsCount,
|
||||
page: Math.ceil(skip / take) + 1,
|
||||
},
|
||||
results: blacklistedItems,
|
||||
} as BlacklistResultsResponse);
|
||||
results: blocklistedItems,
|
||||
} as BlocklistResultsResponse);
|
||||
} catch (error) {
|
||||
logger.error('Something went wrong while retrieving blacklisted items', {
|
||||
label: 'Blacklist',
|
||||
logger.error('Something went wrong while retrieving blocklisted items', {
|
||||
label: 'Blocklist',
|
||||
errorMessage: error.message,
|
||||
});
|
||||
return next({
|
||||
status: 500,
|
||||
message: 'Unable to retrieve blacklisted items.',
|
||||
message: 'Unable to retrieve blocklisted items.',
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
blacklistRoutes.get(
|
||||
blocklistRoutes.get(
|
||||
'/:id',
|
||||
isAuthenticated([Permission.MANAGE_BLACKLIST], {
|
||||
isAuthenticated([Permission.MANAGE_BLOCKLIST], {
|
||||
type: 'or',
|
||||
}),
|
||||
async (req, res, next) => {
|
||||
try {
|
||||
const blacklisteRepository = getRepository(Blacklist);
|
||||
const blocklisteRepository = getRepository(Blocklist);
|
||||
|
||||
const blacklistItem = await blacklisteRepository.findOneOrFail({
|
||||
const blocklistItem = await blocklisteRepository.findOneOrFail({
|
||||
where: { tmdbId: Number(req.params.id) },
|
||||
});
|
||||
|
||||
return res.status(200).send(blacklistItem);
|
||||
return res.status(200).send(blocklistItem);
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
return next({
|
||||
@@ -109,17 +109,17 @@ blacklistRoutes.get(
|
||||
}
|
||||
);
|
||||
|
||||
blacklistRoutes.post(
|
||||
blocklistRoutes.post(
|
||||
'/',
|
||||
isAuthenticated([Permission.MANAGE_BLACKLIST], {
|
||||
isAuthenticated([Permission.MANAGE_BLOCKLIST], {
|
||||
type: 'or',
|
||||
}),
|
||||
async (req, res, next) => {
|
||||
try {
|
||||
const values = blacklistAdd.parse(req.body);
|
||||
const values = blocklistAdd.parse(req.body);
|
||||
|
||||
await Blacklist.addToBlacklist({
|
||||
blacklistRequest: values,
|
||||
await Blocklist.addToBlocklist({
|
||||
blocklistRequest: values,
|
||||
});
|
||||
|
||||
return res.status(201).send();
|
||||
@@ -131,12 +131,12 @@ blacklistRoutes.post(
|
||||
if (error instanceof QueryFailedError) {
|
||||
switch (error.driverError.errno) {
|
||||
case 19:
|
||||
return next({ status: 412, message: 'Item already blacklisted' });
|
||||
return next({ status: 412, message: 'Item already blocklisted' });
|
||||
default:
|
||||
logger.warn('Something wrong with data blacklist', {
|
||||
logger.warn('Something wrong with data blocklist', {
|
||||
tmdbId: req.body.tmdbId,
|
||||
mediaType: req.body.mediaType,
|
||||
label: 'Blacklist',
|
||||
label: 'Blocklist',
|
||||
});
|
||||
return next({ status: 409, message: 'Something wrong' });
|
||||
}
|
||||
@@ -147,20 +147,20 @@ blacklistRoutes.post(
|
||||
}
|
||||
);
|
||||
|
||||
blacklistRoutes.delete(
|
||||
blocklistRoutes.delete(
|
||||
'/:id',
|
||||
isAuthenticated([Permission.MANAGE_BLACKLIST], {
|
||||
isAuthenticated([Permission.MANAGE_BLOCKLIST], {
|
||||
type: 'or',
|
||||
}),
|
||||
async (req, res, next) => {
|
||||
try {
|
||||
const blacklisteRepository = getRepository(Blacklist);
|
||||
const blocklisteRepository = getRepository(Blocklist);
|
||||
|
||||
const blacklistItem = await blacklisteRepository.findOneOrFail({
|
||||
const blocklistItem = await blocklisteRepository.findOneOrFail({
|
||||
where: { tmdbId: Number(req.params.id) },
|
||||
});
|
||||
|
||||
await blacklisteRepository.remove(blacklistItem);
|
||||
await blocklisteRepository.remove(blocklistItem);
|
||||
|
||||
const mediaRepository = getRepository(Media);
|
||||
|
||||
@@ -183,4 +183,4 @@ blacklistRoutes.delete(
|
||||
}
|
||||
);
|
||||
|
||||
export default blacklistRoutes;
|
||||
export default blocklistRoutes;
|
||||
@@ -12,6 +12,7 @@ import { Permission } from '@server/lib/permissions';
|
||||
import { getSettings } from '@server/lib/settings';
|
||||
import logger from '@server/logger';
|
||||
import { checkUser, isAuthenticated } from '@server/middleware/auth';
|
||||
import deprecatedRoute from '@server/middleware/deprecation';
|
||||
import { mapProductionCompany } from '@server/models/Movie';
|
||||
import { mapNetwork } from '@server/models/Tv';
|
||||
import { mapWatchProviderDetails } from '@server/models/common';
|
||||
@@ -28,7 +29,7 @@ import restartFlag from '@server/utils/restartFlag';
|
||||
import { isPerson } from '@server/utils/typeHelpers';
|
||||
import { Router } from 'express';
|
||||
import authRoutes from './auth';
|
||||
import blacklistRoutes from './blacklist';
|
||||
import blocklistRoutes from './blocklist';
|
||||
import collectionRoutes from './collection';
|
||||
import discoverRoutes, { createTmdbWithRegionLanguage } from './discover';
|
||||
import issueRoutes from './issue';
|
||||
@@ -151,7 +152,17 @@ router.use('/search', isAuthenticated(), searchRoutes);
|
||||
router.use('/discover', isAuthenticated(), discoverRoutes);
|
||||
router.use('/request', isAuthenticated(), requestRoutes);
|
||||
router.use('/watchlist', isAuthenticated(), watchlistRoutes);
|
||||
router.use('/blacklist', isAuthenticated(), blacklistRoutes);
|
||||
router.use('/blocklist', isAuthenticated(), blocklistRoutes);
|
||||
router.use(
|
||||
'/blacklist',
|
||||
isAuthenticated(),
|
||||
deprecatedRoute({
|
||||
oldPath: '/api/v1/blacklist',
|
||||
newPath: '/api/v1/blocklist',
|
||||
sunsetDate: '2026-06-01',
|
||||
}),
|
||||
blocklistRoutes
|
||||
);
|
||||
router.use('/movie', isAuthenticated(), movieRoutes);
|
||||
router.use('/tv', isAuthenticated(), tvRoutes);
|
||||
router.use('/media', isAuthenticated(), mediaRoutes);
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
import { getRepository } from '@server/datasource';
|
||||
import Media from '@server/entity/Media';
|
||||
import {
|
||||
BlacklistedMediaError,
|
||||
BlocklistedMediaError,
|
||||
DuplicateMediaRequestError,
|
||||
MediaRequest,
|
||||
NoSeasonsAvailableError,
|
||||
@@ -326,7 +326,7 @@ requestRoutes.post<never, MediaRequest, MediaRequestBody>(
|
||||
return next({ status: 409, message: error.message });
|
||||
case NoSeasonsAvailableError:
|
||||
return next({ status: 202, message: error.message });
|
||||
case BlacklistedMediaError:
|
||||
case BlocklistedMediaError:
|
||||
return next({ status: 403, message: error.message });
|
||||
default:
|
||||
return next({ status: 500, message: error.message });
|
||||
|
||||
Reference in New Issue
Block a user