mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +02:00
Add to playlist dropdown
This commit is contained in:
parent
830b4faff1
commit
f0a3988066
55 changed files with 961 additions and 94 deletions
47
server/controllers/api/users/my-video-playlists.ts
Normal file
47
server/controllers/api/users/my-video-playlists.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
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'
|
||||
|
||||
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) {
|
||||
const videoIds = req.query.videoIds as number[]
|
||||
const user = res.locals.oauth.token.User as UserModel
|
||||
|
||||
const results = await VideoPlaylistModel.listPlaylistIdsOf(user.Account.id, videoIds)
|
||||
|
||||
const existObject: VideoExistInPlaylist = {}
|
||||
|
||||
for (const videoId of videoIds) {
|
||||
existObject[videoId] = []
|
||||
}
|
||||
|
||||
for (const result of results) {
|
||||
for (const element of result.VideoPlaylistElements) {
|
||||
existObject[element.videoId].push({
|
||||
playlistId: result.id,
|
||||
startTimestamp: element.startTimestamp,
|
||||
stopTimestamp: element.stopTimestamp
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return res.json(existObject)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue