X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fmiddlewares%2Fabuses.ts;h=c53bd9efd9af211bd45709b4ab771df7c1e39bbe;hb=f2eb23cd87cf32b8fe545178143b5f49e06a58da;hp=be8c8b449b574f166db2c3926ca64b1f2ec8d01d;hpb=17aa80ed016bafa3ccb071af3f86054033823284;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/middlewares/abuses.ts b/server/helpers/middlewares/abuses.ts index be8c8b449..c53bd9efd 100644 --- a/server/helpers/middlewares/abuses.ts +++ b/server/helpers/middlewares/abuses.ts @@ -1,35 +1,12 @@ import { Response } from 'express' import { AbuseModel } from '../../models/abuse/abuse' -import { fetchVideo } from '../video' - -// FIXME: deprecated in 2.3. Remove this function -async function doesVideoAbuseExist (abuseIdArg: number | string, videoUUID: string, res: Response) { - const abuseId = parseInt(abuseIdArg + '', 10) - let abuse = await AbuseModel.loadByIdAndVideoId(abuseId, null, videoUUID) - - if (!abuse) { - const userId = res.locals.oauth?.token.User.id - const video = await fetchVideo(videoUUID, 'all', userId) - - if (video) abuse = await AbuseModel.loadByIdAndVideoId(abuseId, video.id) - } - - if (abuse === null) { - res.status(404) - .json({ error: 'Video abuse not found' }) - - return false - } - - res.locals.abuse = abuse - return true -} +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' async function doesAbuseExist (abuseId: number | string, res: Response) { - const abuse = await AbuseModel.loadById(parseInt(abuseId + '', 10)) + const abuse = await AbuseModel.loadByIdWithReporter(parseInt(abuseId + '', 10)) if (!abuse) { - res.status(404) + res.status(HttpStatusCode.NOT_FOUND_404) .json({ error: 'Abuse not found' }) return false @@ -42,6 +19,5 @@ async function doesAbuseExist (abuseId: number | string, res: Response) { // --------------------------------------------------------------------------- export { - doesAbuseExist, - doesVideoAbuseExist + doesAbuseExist }