]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/users/my-video-playlists.ts
Share playlists state
[github/Chocobozzz/PeerTube.git] / server / controllers / api / users / my-video-playlists.ts
index 1ec175f6496f4f2b0f83cc7a50b5fff9735d299c..d0bd9946323b16066006c87f1f91f7d69099674d 100644 (file)
@@ -1,9 +1,8 @@
 import * as express from 'express'
 import { asyncMiddleware, authenticate } from '../../../middlewares'
-import { UserModel } from '../../../models/account/user'
 import { doVideosInPlaylistExistValidator } from '../../../middlewares/validators/videos/video-playlists'
 import { VideoPlaylistModel } from '../../../models/video/video-playlist'
-import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'
+import { VideosExistInPlaylists } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'
 
 const myVideoPlaylistsRouter = express.Router()
 
@@ -22,12 +21,12 @@ export {
 // ---------------------------------------------------------------------------
 
 async function doVideosInPlaylistExist (req: express.Request, res: express.Response) {
-  const videoIds = req.query.videoIds as number[]
-  const user = res.locals.oauth.token.User as UserModel
+  const videoIds = req.query.videoIds.map(i => parseInt(i + '', 10))
+  const user = res.locals.oauth.token.User
 
   const results = await VideoPlaylistModel.listPlaylistIdsOf(user.Account.id, videoIds)
 
-  const existObject: VideoExistInPlaylist = {}
+  const existObject: VideosExistInPlaylists = {}
 
   for (const videoId of videoIds) {
     existObject[videoId] = []
@@ -36,6 +35,7 @@ async function doVideosInPlaylistExist (req: express.Request, res: express.Respo
   for (const result of results) {
     for (const element of result.VideoPlaylistElements) {
       existObject[element.videoId].push({
+        playlistElementId: element.id,
         playlistId: result.id,
         startTimestamp: element.startTimestamp,
         stopTimestamp: element.stopTimestamp