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/controllers/api/videos/index.ts | 13 +++++++++++++ server/controllers/api/videos/upload.ts | 7 +++++++ 2 files changed, 20 insertions(+) (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index be233722c..d4e08293e 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -26,6 +26,7 @@ import { setDefaultVideosSort, videosCustomGetValidator, videosGetValidator, + videoSourceGetValidator, videosRemoveValidator, videosSortValidator } from '../../../middlewares' @@ -96,6 +97,14 @@ videosRouter.get('/:id/description', asyncMiddleware(videosGetValidator), asyncMiddleware(getVideoDescription) ) + +videosRouter.get('/:id/source', + openapiOperationDoc({ operationId: 'getVideoSource' }), + authenticate, + asyncMiddleware(videoSourceGetValidator), + getVideoSource +) + videosRouter.get('/:id', openapiOperationDoc({ operationId: 'getVideo' }), optionalAuthenticate, @@ -155,6 +164,10 @@ async function getVideoDescription (req: express.Request, res: express.Response) return res.json({ description }) } +function getVideoSource (req: express.Request, res: express.Response) { + return res.json(res.locals.videoSource.toFormattedJSON()) +} + async function listVideos (req: express.Request, res: express.Response) { const serverActor = await getServerActor() diff --git a/server/controllers/api/videos/upload.ts b/server/controllers/api/videos/upload.ts index 3afbedbb2..c5890691e 100644 --- a/server/controllers/api/videos/upload.ts +++ b/server/controllers/api/videos/upload.ts @@ -44,6 +44,7 @@ import { import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' import { VideoModel } from '../../../models/video/video' import { VideoFileModel } from '../../../models/video/video-file' +import { VideoSourceModel } from '@server/models/video/video-source' const lTags = loggerTagsFactory('api', 'video') const auditLogger = auditLoggerFactory('videos') @@ -151,6 +152,7 @@ async function addVideo (options: { video.url = getLocalVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object const videoFile = await buildNewFile(videoPhysicalFile) + const originalFilename = videoPhysicalFile.originalname // Move physical file const destination = VideoPathManager.Instance.getFSVideoFileOutputPath(video, videoFile) @@ -181,6 +183,11 @@ async function addVideo (options: { video.VideoFiles = [ videoFile ] + await VideoSourceModel.create({ + filename: originalFilename, + videoId: video.id + }, { transaction: t }) + await setVideoTags({ video, tags: videoInfo.tags, transaction: t }) // Schedule an update in the future? -- cgit v1.2.3