aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-31 15:57:32 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-08-01 09:11:04 +0200
commitbfbd912886eba17b4aa9a40dcef2fddc685d85bf (patch)
tree85e0f22980210a8ccd0888eb5e1790b152074677 /server/controllers/api
parent85394ba22a07bde1dfccebf3f591a5d6dbe9df56 (diff)
downloadPeerTube-bfbd912886eba17b4aa9a40dcef2fddc685d85bf.tar.gz
PeerTube-bfbd912886eba17b4aa9a40dcef2fddc685d85bf.tar.zst
PeerTube-bfbd912886eba17b4aa9a40dcef2fddc685d85bf.zip
Fix broken playlist api
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/users/my-video-playlists.ts1
-rw-r--r--server/controllers/api/video-playlist.ts35
2 files changed, 14 insertions, 22 deletions
diff --git a/server/controllers/api/users/my-video-playlists.ts b/server/controllers/api/users/my-video-playlists.ts
index 15e92f4f3..735a3cbee 100644
--- a/server/controllers/api/users/my-video-playlists.ts
+++ b/server/controllers/api/users/my-video-playlists.ts
@@ -35,6 +35,7 @@ async function doVideosInPlaylistExist (req: express.Request, res: express.Respo
35 for (const result of results) { 35 for (const result of results) {
36 for (const element of result.VideoPlaylistElements) { 36 for (const element of result.VideoPlaylistElements) {
37 existObject[element.videoId].push({ 37 existObject[element.videoId].push({
38 playlistElementId: element.id,
38 playlistId: result.id, 39 playlistId: result.id,
39 startTimestamp: element.startTimestamp, 40 startTimestamp: element.startTimestamp,
40 stopTimestamp: element.stopTimestamp 41 stopTimestamp: element.stopTimestamp
diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts
index 62490e63b..540120cca 100644
--- a/server/controllers/api/video-playlist.ts
+++ b/server/controllers/api/video-playlist.ts
@@ -4,14 +4,13 @@ import {
4 asyncMiddleware, 4 asyncMiddleware,
5 asyncRetryTransactionMiddleware, 5 asyncRetryTransactionMiddleware,
6 authenticate, 6 authenticate,
7 commonVideosFiltersValidator,
8 optionalAuthenticate, 7 optionalAuthenticate,
9 paginationValidator, 8 paginationValidator,
10 setDefaultPagination, 9 setDefaultPagination,
11 setDefaultSort 10 setDefaultSort
12} from '../../middlewares' 11} from '../../middlewares'
13import { videoPlaylistsSortValidator } from '../../middlewares/validators' 12import { videoPlaylistsSortValidator } from '../../middlewares/validators'
14import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' 13import { buildNSFWFilter, createReqFiles } from '../../helpers/express-utils'
15import { MIMETYPES, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers/constants' 14import { MIMETYPES, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers/constants'
16import { logger } from '../../helpers/logger' 15import { logger } from '../../helpers/logger'
17import { resetSequelizeInstance } from '../../helpers/database-utils' 16import { resetSequelizeInstance } from '../../helpers/database-utils'
@@ -32,7 +31,6 @@ import { join } from 'path'
32import { sendCreateVideoPlaylist, sendDeleteVideoPlaylist, sendUpdateVideoPlaylist } from '../../lib/activitypub/send' 31import { sendCreateVideoPlaylist, sendDeleteVideoPlaylist, sendUpdateVideoPlaylist } from '../../lib/activitypub/send'
33import { getVideoPlaylistActivityPubUrl, getVideoPlaylistElementActivityPubUrl } from '../../lib/activitypub/url' 32import { getVideoPlaylistActivityPubUrl, getVideoPlaylistElementActivityPubUrl } from '../../lib/activitypub/url'
34import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model' 33import { VideoPlaylistUpdate } from '../../../shared/models/videos/playlist/video-playlist-update.model'
35import { VideoModel } from '../../models/video/video'
36import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element' 34import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
37import { VideoPlaylistElementCreate } from '../../../shared/models/videos/playlist/video-playlist-element-create.model' 35import { VideoPlaylistElementCreate } from '../../../shared/models/videos/playlist/video-playlist-element-create.model'
38import { VideoPlaylistElementUpdate } from '../../../shared/models/videos/playlist/video-playlist-element-update.model' 36import { VideoPlaylistElementUpdate } from '../../../shared/models/videos/playlist/video-playlist-element-update.model'
@@ -88,7 +86,6 @@ videoPlaylistRouter.get('/:playlistId/videos',
88 paginationValidator, 86 paginationValidator,
89 setDefaultPagination, 87 setDefaultPagination,
90 optionalAuthenticate, 88 optionalAuthenticate,
91 commonVideosFiltersValidator,
92 asyncMiddleware(getVideoPlaylistVideos) 89 asyncMiddleware(getVideoPlaylistVideos)
93) 90)
94 91
@@ -104,13 +101,13 @@ videoPlaylistRouter.post('/:playlistId/videos/reorder',
104 asyncRetryTransactionMiddleware(reorderVideosPlaylist) 101 asyncRetryTransactionMiddleware(reorderVideosPlaylist)
105) 102)
106 103
107videoPlaylistRouter.put('/:playlistId/videos/:videoId', 104videoPlaylistRouter.put('/:playlistId/videos/:playlistElementId',
108 authenticate, 105 authenticate,
109 asyncMiddleware(videoPlaylistsUpdateOrRemoveVideoValidator), 106 asyncMiddleware(videoPlaylistsUpdateOrRemoveVideoValidator),
110 asyncRetryTransactionMiddleware(updateVideoPlaylistElement) 107 asyncRetryTransactionMiddleware(updateVideoPlaylistElement)
111) 108)
112 109
113videoPlaylistRouter.delete('/:playlistId/videos/:videoId', 110videoPlaylistRouter.delete('/:playlistId/videos/:playlistElementId',
114 authenticate, 111 authenticate,
115 asyncMiddleware(videoPlaylistsUpdateOrRemoveVideoValidator), 112 asyncMiddleware(videoPlaylistsUpdateOrRemoveVideoValidator),
116 asyncRetryTransactionMiddleware(removeVideoFromPlaylist) 113 asyncRetryTransactionMiddleware(removeVideoFromPlaylist)
@@ -426,26 +423,20 @@ async function reorderVideosPlaylist (req: express.Request, res: express.Respons
426 423
427async function getVideoPlaylistVideos (req: express.Request, res: express.Response) { 424async function getVideoPlaylistVideos (req: express.Request, res: express.Response) {
428 const videoPlaylistInstance = res.locals.videoPlaylist 425 const videoPlaylistInstance = res.locals.videoPlaylist
429 const followerActorId = isUserAbleToSearchRemoteURI(res) ? null : undefined 426 const user = res.locals.oauth ? res.locals.oauth.token.User : undefined
427 const server = await getServerActor()
430 428
431 const resultList = await VideoModel.listForApi({ 429 const resultList = await VideoPlaylistElementModel.listForApi({
432 followerActorId,
433 start: req.query.start, 430 start: req.query.start,
434 count: req.query.count, 431 count: req.query.count,
435 sort: 'VideoPlaylistElements.position',
436 includeLocalVideos: true,
437 categoryOneOf: req.query.categoryOneOf,
438 licenceOneOf: req.query.licenceOneOf,
439 languageOneOf: req.query.languageOneOf,
440 tagsOneOf: req.query.tagsOneOf,
441 tagsAllOf: req.query.tagsAllOf,
442 filter: req.query.filter,
443 nsfw: buildNSFWFilter(res, req.query.nsfw),
444 withFiles: false,
445 videoPlaylistId: videoPlaylistInstance.id, 432 videoPlaylistId: videoPlaylistInstance.id,
446 user: res.locals.oauth ? res.locals.oauth.token.User : undefined 433 serverAccount: server.Account,
434 user
447 }) 435 })
448 436
449 const additionalAttributes = { playlistInfo: true } 437 const options = {
450 return res.json(getFormattedObjects(resultList.data, resultList.total, { additionalAttributes })) 438 displayNSFW: buildNSFWFilter(res, req.query.nsfw),
439 accountId: user ? user.Account.id : undefined
440 }
441 return res.json(getFormattedObjects(resultList.data, resultList.total, options))
451} 442}