From d95d15598847c7f020aa056e7e6e0c02d2bbf732 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 1 Jul 2020 16:05:30 +0200 Subject: Use 3 tables to represent abuses --- server/helpers/middlewares/abuses.ts | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 server/helpers/middlewares/abuses.ts (limited to 'server/helpers/middlewares/abuses.ts') diff --git a/server/helpers/middlewares/abuses.ts b/server/helpers/middlewares/abuses.ts new file mode 100644 index 000000000..3906f6760 --- /dev/null +++ b/server/helpers/middlewares/abuses.ts @@ -0,0 +1,38 @@ +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' }) + .end() + + return false + } + + res.locals.abuse = abuse + return true +} + +async function doesAbuseExist (abuseIdArg: number | string, videoUUID: string, res: Response) { + +} + +// --------------------------------------------------------------------------- + +export { + doesAbuseExist, + doesVideoAbuseExist +} -- cgit v1.2.3