aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/users/index.ts2
-rw-r--r--server/controllers/api/users/my-video-playlists.ts47
-rw-r--r--server/controllers/api/video-playlist.ts34
3 files changed, 72 insertions, 11 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}
diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts
index 145764d35..49432d3aa 100644
--- a/server/controllers/api/video-playlist.ts
+++ b/server/controllers/api/video-playlist.ts
@@ -291,23 +291,26 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response)
291 videoId: video.id 291 videoId: video.id
292 }, { transaction: t }) 292 }, { transaction: t })
293 293
294 // If the user did not set a thumbnail, automatically take the video thumbnail 294 videoPlaylist.updatedAt = new Date()
295 if (playlistElement.position === 1) { 295 await videoPlaylist.save({ transaction: t })
296 const playlistThumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, videoPlaylist.getThumbnailName())
297
298 if (await pathExists(playlistThumbnailPath) === false) {
299 logger.info('Generating default thumbnail to playlist %s.', videoPlaylist.url)
300
301 const videoThumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName())
302 await copy(videoThumbnailPath, playlistThumbnailPath)
303 }
304 }
305 296
306 await sendUpdateVideoPlaylist(videoPlaylist, t) 297 await sendUpdateVideoPlaylist(videoPlaylist, t)
307 298
308 return playlistElement 299 return playlistElement
309 }) 300 })
310 301
302 // If the user did not set a thumbnail, automatically take the video thumbnail
303 if (playlistElement.position === 1) {
304 const playlistThumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, videoPlaylist.getThumbnailName())
305
306 if (await pathExists(playlistThumbnailPath) === false) {
307 logger.info('Generating default thumbnail to playlist %s.', videoPlaylist.url)
308
309 const videoThumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName())
310 await copy(videoThumbnailPath, playlistThumbnailPath)
311 }
312 }
313
311 logger.info('Video added in playlist %s at position %d.', videoPlaylist.uuid, playlistElement.position) 314 logger.info('Video added in playlist %s at position %d.', videoPlaylist.uuid, playlistElement.position)
312 315
313 return res.json({ 316 return res.json({
@@ -328,6 +331,9 @@ async function updateVideoPlaylistElement (req: express.Request, res: express.Re
328 331
329 const element = await videoPlaylistElement.save({ transaction: t }) 332 const element = await videoPlaylistElement.save({ transaction: t })
330 333
334 videoPlaylist.updatedAt = new Date()
335 await videoPlaylist.save({ transaction: t })
336
331 await sendUpdateVideoPlaylist(videoPlaylist, t) 337 await sendUpdateVideoPlaylist(videoPlaylist, t)
332 338
333 return element 339 return element
@@ -349,6 +355,9 @@ async function removeVideoFromPlaylist (req: express.Request, res: express.Respo
349 // Decrease position of the next elements 355 // Decrease position of the next elements
350 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, positionToDelete, null, -1, t) 356 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, positionToDelete, null, -1, t)
351 357
358 videoPlaylist.updatedAt = new Date()
359 await videoPlaylist.save({ transaction: t })
360
352 await sendUpdateVideoPlaylist(videoPlaylist, t) 361 await sendUpdateVideoPlaylist(videoPlaylist, t)
353 362
354 logger.info('Video playlist element %d of playlist %s deleted.', videoPlaylistElement.position, videoPlaylist.uuid) 363 logger.info('Video playlist element %d of playlist %s deleted.', videoPlaylistElement.position, videoPlaylist.uuid)
@@ -390,6 +399,9 @@ async function reorderVideosPlaylist (req: express.Request, res: express.Respons
390 // Decrease positions of elements after the old position of our ordered elements (decrease) 399 // Decrease positions of elements after the old position of our ordered elements (decrease)
391 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, oldPosition, null, -reorderLength, t) 400 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, oldPosition, null, -reorderLength, t)
392 401
402 videoPlaylist.updatedAt = new Date()
403 await videoPlaylist.save({ transaction: t })
404
393 await sendUpdateVideoPlaylist(videoPlaylist, t) 405 await sendUpdateVideoPlaylist(videoPlaylist, t)
394 }) 406 })
395 407