2019-03-07 17:06:00 +01:00
|
|
|
import * as express from 'express'
|
|
|
|
import { asyncMiddleware, authenticate } from '../../../middlewares'
|
|
|
|
import { doVideosInPlaylistExistValidator } from '../../../middlewares/validators/videos/video-playlists'
|
|
|
|
import { VideoPlaylistModel } from '../../../models/video/video-playlist'
|
2020-01-06 13:06:13 +01:00
|
|
|
import { VideosExistInPlaylists } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'
|
2019-03-07 17:06:00 +01:00
|
|
|
|
|
|
|
const myVideoPlaylistsRouter = express.Router()
|
|
|
|
|
|
|
|
myVideoPlaylistsRouter.get('/me/video-playlists/videos-exist',
|
|
|
|
authenticate,
|
|
|
|
doVideosInPlaylistExistValidator,
|
|
|
|
asyncMiddleware(doVideosInPlaylistExist)
|
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
myVideoPlaylistsRouter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
async function doVideosInPlaylistExist (req: express.Request, res: express.Response) {
|
2019-03-13 16:03:03 +01:00
|
|
|
const videoIds = req.query.videoIds.map(i => parseInt(i + '', 10))
|
2019-03-19 10:35:15 +01:00
|
|
|
const user = res.locals.oauth.token.User
|
2019-03-07 17:06:00 +01:00
|
|
|
|
|
|
|
const results = await VideoPlaylistModel.listPlaylistIdsOf(user.Account.id, videoIds)
|
|
|
|
|
2020-01-06 13:06:13 +01:00
|
|
|
const existObject: VideosExistInPlaylists = {}
|
2019-03-07 17:06:00 +01:00
|
|
|
|
|
|
|
for (const videoId of videoIds) {
|
|
|
|
existObject[videoId] = []
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const result of results) {
|
|
|
|
for (const element of result.VideoPlaylistElements) {
|
|
|
|
existObject[element.videoId].push({
|
2019-07-31 15:57:32 +02:00
|
|
|
playlistElementId: element.id,
|
2019-03-07 17:06:00 +01:00
|
|
|
playlistId: result.id,
|
|
|
|
startTimestamp: element.startTimestamp,
|
|
|
|
stopTimestamp: element.stopTimestamp
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.json(existObject)
|
|
|
|
}
|