1
0
Fork 0
peertube/server/controllers/api/users/my-video-playlists.ts

52 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-08-27 08:32:44 -04:00
import express from 'express'
import { forceNumber } from '@shared/core-utils'
import { uuidToShort } from '@shared/extra-utils'
2021-07-16 08:27:30 -04:00
import { VideosExistInPlaylists } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'
2019-03-07 11:06:00 -05:00
import { asyncMiddleware, authenticate } from '../../../middlewares'
import { doVideosInPlaylistExistValidator } from '../../../middlewares/validators/videos/video-playlists'
import { VideoPlaylistModel } from '../../../models/video/video-playlist'
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.map(i => forceNumber(i))
2019-03-19 05:35:15 -04:00
const user = res.locals.oauth.token.User
2019-03-07 11:06:00 -05:00
const results = await VideoPlaylistModel.listPlaylistSummariesOf(user.Account.id, videoIds)
2019-03-07 11:06:00 -05:00
2020-01-06 07:06:13 -05:00
const existObject: VideosExistInPlaylists = {}
2019-03-07 11:06:00 -05: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 09:57:32 -04:00
playlistElementId: element.id,
2019-03-07 11:06:00 -05:00
playlistId: result.id,
playlistDisplayName: result.name,
playlistShortUUID: uuidToShort(result.uuid),
2019-03-07 11:06:00 -05:00
startTimestamp: element.startTimestamp,
stopTimestamp: element.stopTimestamp
})
}
}
return res.json(existObject)
}