]>
Commit | Line | Data |
---|---|---|
38a3ccc7 | 1 | import { uuidToShort } from '@shared/extra-utils' |
41fb13c3 | 2 | import express from 'express' |
4c7e60bc | 3 | import { VideosExistInPlaylists } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model' |
f0a39880 | 4 | import { asyncMiddleware, authenticate } from '../../../middlewares' |
f0a39880 C |
5 | import { doVideosInPlaylistExistValidator } from '../../../middlewares/validators/videos/video-playlists' |
6 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' | |
f0a39880 C |
7 | |
8 | const myVideoPlaylistsRouter = express.Router() | |
9 | ||
10 | myVideoPlaylistsRouter.get('/me/video-playlists/videos-exist', | |
11 | authenticate, | |
12 | doVideosInPlaylistExistValidator, | |
13 | asyncMiddleware(doVideosInPlaylistExist) | |
14 | ) | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | ||
18 | export { | |
19 | myVideoPlaylistsRouter | |
20 | } | |
21 | ||
22 | // --------------------------------------------------------------------------- | |
23 | ||
24 | async function doVideosInPlaylistExist (req: express.Request, res: express.Response) { | |
0b16f5f2 | 25 | const videoIds = req.query.videoIds.map(i => parseInt(i + '', 10)) |
dae86118 | 26 | const user = res.locals.oauth.token.User |
f0a39880 | 27 | |
38a3ccc7 | 28 | const results = await VideoPlaylistModel.listPlaylistSummariesOf(user.Account.id, videoIds) |
f0a39880 | 29 | |
51b34a11 | 30 | const existObject: VideosExistInPlaylists = {} |
f0a39880 C |
31 | |
32 | for (const videoId of videoIds) { | |
33 | existObject[videoId] = [] | |
34 | } | |
35 | ||
36 | for (const result of results) { | |
37 | for (const element of result.VideoPlaylistElements) { | |
38 | existObject[element.videoId].push({ | |
bfbd9128 | 39 | playlistElementId: element.id, |
f0a39880 | 40 | playlistId: result.id, |
38a3ccc7 | 41 | playlistDisplayName: result.name, |
42 | playlistShortUUID: uuidToShort(result.uuid), | |
f0a39880 C |
43 | startTimestamp: element.startTimestamp, |
44 | stopTimestamp: element.stopTimestamp | |
45 | }) | |
46 | } | |
47 | } | |
48 | ||
49 | return res.json(existObject) | |
50 | } |