From 2e401e8575decb1d491d0db48ca1ab1eba5b2a66 Mon Sep 17 00:00:00 2001 From: kontrollanten <6680299+kontrollanten@users.noreply.github.com> Date: Tue, 21 Jun 2022 15:31:25 +0200 Subject: store uploaded video filename (#4885) * store uploaded video filename closes #4731 * dont crash if videos channel exist * migration: use raw query * video source: fixes after code review * cleanup * bump migration * updates after code review * refactor: use checkUserCanManageVideo * videoSource: add openapi doc * test(check-params/video-source): fix timeout * Styling * Correctly set original filename as source Co-authored-by: Chocobozzz --- server/middlewares/validators/videos/index.ts | 1 + .../middlewares/validators/videos/video-source.ts | 37 ++++++++++++++++++++++ server/middlewares/validators/videos/videos.ts | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 server/middlewares/validators/videos/video-source.ts (limited to 'server/middlewares') diff --git a/server/middlewares/validators/videos/index.ts b/server/middlewares/validators/videos/index.ts index bd2590bc5..1dd7b5d2e 100644 --- a/server/middlewares/validators/videos/index.ts +++ b/server/middlewares/validators/videos/index.ts @@ -9,6 +9,7 @@ export * from './video-ownership-changes' export * from './video-view' export * from './video-rates' export * from './video-shares' +export * from './video-source' export * from './video-stats' export * from './video-studio' export * from './video-transcoding' diff --git a/server/middlewares/validators/videos/video-source.ts b/server/middlewares/validators/videos/video-source.ts new file mode 100644 index 000000000..31a2f16b3 --- /dev/null +++ b/server/middlewares/validators/videos/video-source.ts @@ -0,0 +1,37 @@ +import express from 'express' +import { getVideoWithAttributes } from '@server/helpers/video' +import { VideoSourceModel } from '@server/models/video/video-source' +import { MVideoFullLight } from '@server/types/models' +import { HttpStatusCode, UserRight } from '@shared/models' +import { logger } from '../../../helpers/logger' +import { areValidationErrors, checkUserCanManageVideo, doesVideoExist, isValidVideoIdParam } from '../shared' + +const videoSourceGetValidator = [ + isValidVideoIdParam('id'), + + async (req: express.Request, res: express.Response, next: express.NextFunction) => { + logger.debug('Checking videoSourceGet parameters', { parameters: req.params }) + + if (areValidationErrors(req, res)) return + if (!await doesVideoExist(req.params.id, res, 'for-api')) return + + const video = getVideoWithAttributes(res) as MVideoFullLight + + res.locals.videoSource = await VideoSourceModel.loadByVideoId(video.id) + if (!res.locals.videoSource) { + return res.fail({ + status: HttpStatusCode.NOT_FOUND_404, + message: 'Video source not found' + }) + } + + const user = res.locals.oauth.token.User + if (!checkUserCanManageVideo(user, video, UserRight.UPDATE_ANY_VIDEO, res)) return + + return next() + } +] + +export { + videoSourceGetValidator +} diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 0b6b8bfe5..c75c3640b 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -152,7 +152,7 @@ const videosAddResumableValidator = [ if (!await isVideoAccepted(req, res, file)) return cleanup() - res.locals.videoFileResumable = file + res.locals.videoFileResumable = { ...file, originalname: file.filename } return next() } -- cgit v1.2.3