aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-30 10:16:27 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-10-30 10:16:27 +0100
commit9567011bf01f36c7f796ac1e0f1fb12c71635e53 (patch)
treebec3ed173767cff031ed0a84231d6dd50e792569 /server/controllers/api
parent757f0da370a992cf07afd20d3829b2748c76cc15 (diff)
downloadPeerTube-9567011bf01f36c7f796ac1e0f1fb12c71635e53.tar.gz
PeerTube-9567011bf01f36c7f796ac1e0f1fb12c71635e53.tar.zst
PeerTube-9567011bf01f36c7f796ac1e0f1fb12c71635e53.zip
Add lazy description on server
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/remote/videos.ts4
-rw-r--r--server/controllers/api/videos/index.ts21
2 files changed, 22 insertions, 3 deletions
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
258 licence: videoToCreateData.licence, 258 licence: videoToCreateData.licence,
259 language: videoToCreateData.language, 259 language: videoToCreateData.language,
260 nsfw: videoToCreateData.nsfw, 260 nsfw: videoToCreateData.nsfw,
261 description: videoToCreateData.description, 261 description: videoToCreateData.truncatedDescription,
262 channelId: videoChannel.id, 262 channelId: videoChannel.id,
263 duration: videoToCreateData.duration, 263 duration: videoToCreateData.duration,
264 createdAt: videoToCreateData.createdAt, 264 createdAt: videoToCreateData.createdAt,
@@ -327,7 +327,7 @@ async function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData
327 videoInstance.set('licence', videoAttributesToUpdate.licence) 327 videoInstance.set('licence', videoAttributesToUpdate.licence)
328 videoInstance.set('language', videoAttributesToUpdate.language) 328 videoInstance.set('language', videoAttributesToUpdate.language)
329 videoInstance.set('nsfw', videoAttributesToUpdate.nsfw) 329 videoInstance.set('nsfw', videoAttributesToUpdate.nsfw)
330 videoInstance.set('description', videoAttributesToUpdate.description) 330 videoInstance.set('description', videoAttributesToUpdate.truncatedDescription)
331 videoInstance.set('duration', videoAttributesToUpdate.duration) 331 videoInstance.set('duration', videoAttributesToUpdate.duration)
332 videoInstance.set('createdAt', videoAttributesToUpdate.createdAt) 332 videoInstance.set('createdAt', videoAttributesToUpdate.createdAt)
333 videoInstance.set('updatedAt', videoAttributesToUpdate.updatedAt) 333 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 {
16 quickAndDirtyUpdateVideoToFriends, 16 quickAndDirtyUpdateVideoToFriends,
17 addVideoToFriends, 17 addVideoToFriends,
18 updateVideoToFriends, 18 updateVideoToFriends,
19 JobScheduler 19 JobScheduler,
20 fetchRemoteDescription
20} from '../../../lib' 21} from '../../../lib'
21import { 22import {
22 authenticate, 23 authenticate,
@@ -102,6 +103,11 @@ videosRouter.post('/upload',
102 videosAddValidator, 103 videosAddValidator,
103 asyncMiddleware(addVideoRetryWrapper) 104 asyncMiddleware(addVideoRetryWrapper)
104) 105)
106
107videosRouter.get('/:id/description',
108 videosGetValidator,
109 asyncMiddleware(getVideoDescription)
110)
105videosRouter.get('/:id', 111videosRouter.get('/:id',
106 videosGetValidator, 112 videosGetValidator,
107 getVideo 113 getVideo
@@ -328,6 +334,19 @@ function getVideo (req: express.Request, res: express.Response) {
328 return res.json(videoInstance.toFormattedDetailsJSON()) 334 return res.json(videoInstance.toFormattedDetailsJSON())
329} 335}
330 336
337async function getVideoDescription (req: express.Request, res: express.Response) {
338 const videoInstance = res.locals.video
339 let description = ''
340
341 if (videoInstance.isOwned()) {
342 description = videoInstance.description
343 } else {
344 description = await fetchRemoteDescription(videoInstance)
345 }
346
347 return res.json({ description })
348}
349
331async function listVideos (req: express.Request, res: express.Response, next: express.NextFunction) { 350async function listVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
332 const resultList = await db.Video.listForApi(req.query.start, req.query.count, req.query.sort) 351 const resultList = await db.Video.listForApi(req.query.start, req.query.count, req.query.sort)
333 352