From 9567011bf01f36c7f796ac1e0f1fb12c71635e53 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 30 Oct 2017 10:16:27 +0100 Subject: Add lazy description on server --- server/controllers/api/remote/videos.ts | 4 ++-- server/controllers/api/videos/index.ts | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'server/controllers') diff --git a/server/controllers/api/remote/videos.ts b/server/controllers/api/remote/videos.ts index d0febdd4b..3ecc62ada 100644 --- a/server/controllers/api/remote/videos.ts +++ b/server/controllers/api/remote/videos.ts @@ -258,7 +258,7 @@ async function addRemoteVideo (videoToCreateData: RemoteVideoCreateData, fromPod licence: videoToCreateData.licence, language: videoToCreateData.language, nsfw: videoToCreateData.nsfw, - description: videoToCreateData.description, + description: videoToCreateData.truncatedDescription, channelId: videoChannel.id, duration: videoToCreateData.duration, createdAt: videoToCreateData.createdAt, @@ -327,7 +327,7 @@ async function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData videoInstance.set('licence', videoAttributesToUpdate.licence) videoInstance.set('language', videoAttributesToUpdate.language) videoInstance.set('nsfw', videoAttributesToUpdate.nsfw) - videoInstance.set('description', videoAttributesToUpdate.description) + videoInstance.set('description', videoAttributesToUpdate.truncatedDescription) videoInstance.set('duration', videoAttributesToUpdate.duration) videoInstance.set('createdAt', videoAttributesToUpdate.createdAt) videoInstance.set('updatedAt', videoAttributesToUpdate.updatedAt) diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 9e233a8cc..49f0e4630 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -16,7 +16,8 @@ import { quickAndDirtyUpdateVideoToFriends, addVideoToFriends, updateVideoToFriends, - JobScheduler + JobScheduler, + fetchRemoteDescription } from '../../../lib' import { authenticate, @@ -102,6 +103,11 @@ videosRouter.post('/upload', videosAddValidator, asyncMiddleware(addVideoRetryWrapper) ) + +videosRouter.get('/:id/description', + videosGetValidator, + asyncMiddleware(getVideoDescription) +) videosRouter.get('/:id', videosGetValidator, getVideo @@ -328,6 +334,19 @@ function getVideo (req: express.Request, res: express.Response) { return res.json(videoInstance.toFormattedDetailsJSON()) } +async function getVideoDescription (req: express.Request, res: express.Response) { + const videoInstance = res.locals.video + let description = '' + + if (videoInstance.isOwned()) { + description = videoInstance.description + } else { + description = await fetchRemoteDescription(videoInstance) + } + + return res.json({ description }) +} + async function listVideos (req: express.Request, res: express.Response, next: express.NextFunction) { const resultList = await db.Video.listForApi(req.query.start, req.query.count, req.query.sort) -- cgit v1.2.3