aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/users')
-rw-r--r--server/controllers/api/users/index.ts2
-rw-r--r--server/controllers/api/users/my-video-playlists.ts47
2 files changed, 49 insertions, 0 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index 5758c8227..f7edbddf3 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -38,6 +38,7 @@ import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../h
38import { meRouter } from './me' 38import { meRouter } from './me'
39import { deleteUserToken } from '../../../lib/oauth-model' 39import { deleteUserToken } from '../../../lib/oauth-model'
40import { myBlocklistRouter } from './my-blocklist' 40import { myBlocklistRouter } from './my-blocklist'
41import { myVideoPlaylistsRouter } from './my-video-playlists'
41import { myVideosHistoryRouter } from './my-history' 42import { myVideosHistoryRouter } from './my-history'
42import { myNotificationsRouter } from './my-notifications' 43import { myNotificationsRouter } from './my-notifications'
43import { Notifier } from '../../../lib/notifier' 44import { Notifier } from '../../../lib/notifier'
@@ -60,6 +61,7 @@ usersRouter.use('/', myNotificationsRouter)
60usersRouter.use('/', mySubscriptionsRouter) 61usersRouter.use('/', mySubscriptionsRouter)
61usersRouter.use('/', myBlocklistRouter) 62usersRouter.use('/', myBlocklistRouter)
62usersRouter.use('/', myVideosHistoryRouter) 63usersRouter.use('/', myVideosHistoryRouter)
64usersRouter.use('/', myVideoPlaylistsRouter)
63usersRouter.use('/', meRouter) 65usersRouter.use('/', meRouter)
64 66
65usersRouter.get('/autocomplete', 67usersRouter.get('/autocomplete',
diff --git a/server/controllers/api/users/my-video-playlists.ts b/server/controllers/api/users/my-video-playlists.ts
new file mode 100644
index 000000000..1ec175f64
--- /dev/null
+++ b/server/controllers/api/users/my-video-playlists.ts
@@ -0,0 +1,47 @@
1import * as express from 'express'
2import { asyncMiddleware, authenticate } from '../../../middlewares'
3import { UserModel } from '../../../models/account/user'
4import { doVideosInPlaylistExistValidator } from '../../../middlewares/validators/videos/video-playlists'
5import { VideoPlaylistModel } from '../../../models/video/video-playlist'
6import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'
7
8const myVideoPlaylistsRouter = express.Router()
9
10myVideoPlaylistsRouter.get('/me/video-playlists/videos-exist',
11 authenticate,
12 doVideosInPlaylistExistValidator,
13 asyncMiddleware(doVideosInPlaylistExist)
14)
15
16// ---------------------------------------------------------------------------
17
18export {
19 myVideoPlaylistsRouter
20}
21
22// ---------------------------------------------------------------------------
23
24async function doVideosInPlaylistExist (req: express.Request, res: express.Response) {
25 const videoIds = req.query.videoIds as number[]
26 const user = res.locals.oauth.token.User as UserModel
27
28 const results = await VideoPlaylistModel.listPlaylistIdsOf(user.Account.id, videoIds)
29
30 const existObject: VideoExistInPlaylist = {}
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 playlistId: result.id,
40 startTimestamp: element.startTimestamp,
41 stopTimestamp: element.stopTimestamp
42 })
43 }
44 }
45
46 return res.json(existObject)
47}