]>
Commit | Line | Data |
---|---|---|
1 | import { uuidToShort } from '@shared/extra-utils' | |
2 | import express from 'express' | |
3 | import { VideosExistInPlaylists } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model' | |
4 | import { asyncMiddleware, authenticate } from '../../../middlewares' | |
5 | import { doVideosInPlaylistExistValidator } from '../../../middlewares/validators/videos/video-playlists' | |
6 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' | |
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) { | |
25 | const videoIds = req.query.videoIds.map(i => parseInt(i + '', 10)) | |
26 | const user = res.locals.oauth.token.User | |
27 | ||
28 | const results = await VideoPlaylistModel.listPlaylistSummariesOf(user.Account.id, videoIds) | |
29 | ||
30 | const existObject: VideosExistInPlaylists = {} | |
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({ | |
39 | playlistElementId: element.id, | |
40 | playlistId: result.id, | |
41 | playlistDisplayName: result.name, | |
42 | playlistShortUUID: uuidToShort(result.uuid), | |
43 | startTimestamp: element.startTimestamp, | |
44 | stopTimestamp: element.stopTimestamp | |
45 | }) | |
46 | } | |
47 | } | |
48 | ||
49 | return res.json(existObject) | |
50 | } |