diff options
Diffstat (limited to 'server/controllers/api/users')
-rw-r--r-- | server/controllers/api/users/index.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/users/my-video-playlists.ts | 47 |
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 | |||
38 | import { meRouter } from './me' | 38 | import { meRouter } from './me' |
39 | import { deleteUserToken } from '../../../lib/oauth-model' | 39 | import { deleteUserToken } from '../../../lib/oauth-model' |
40 | import { myBlocklistRouter } from './my-blocklist' | 40 | import { myBlocklistRouter } from './my-blocklist' |
41 | import { myVideoPlaylistsRouter } from './my-video-playlists' | ||
41 | import { myVideosHistoryRouter } from './my-history' | 42 | import { myVideosHistoryRouter } from './my-history' |
42 | import { myNotificationsRouter } from './my-notifications' | 43 | import { myNotificationsRouter } from './my-notifications' |
43 | import { Notifier } from '../../../lib/notifier' | 44 | import { Notifier } from '../../../lib/notifier' |
@@ -60,6 +61,7 @@ usersRouter.use('/', myNotificationsRouter) | |||
60 | usersRouter.use('/', mySubscriptionsRouter) | 61 | usersRouter.use('/', mySubscriptionsRouter) |
61 | usersRouter.use('/', myBlocklistRouter) | 62 | usersRouter.use('/', myBlocklistRouter) |
62 | usersRouter.use('/', myVideosHistoryRouter) | 63 | usersRouter.use('/', myVideosHistoryRouter) |
64 | usersRouter.use('/', myVideoPlaylistsRouter) | ||
63 | usersRouter.use('/', meRouter) | 65 | usersRouter.use('/', meRouter) |
64 | 66 | ||
65 | usersRouter.get('/autocomplete', | 67 | usersRouter.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 @@ | |||
1 | import * as express from 'express' | ||
2 | import { asyncMiddleware, authenticate } from '../../../middlewares' | ||
3 | import { UserModel } from '../../../models/account/user' | ||
4 | import { doVideosInPlaylistExistValidator } from '../../../middlewares/validators/videos/video-playlists' | ||
5 | import { VideoPlaylistModel } from '../../../models/video/video-playlist' | ||
6 | import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model' | ||
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 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 | } | ||