aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/accounts.ts5
-rw-r--r--server/controllers/api/users/index.ts6
-rw-r--r--server/controllers/api/video-channel.ts7
-rw-r--r--server/controllers/api/video-playlist.ts25
4 files changed, 35 insertions, 8 deletions
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts
index 03c831092..e24545de8 100644
--- a/server/controllers/api/accounts.ts
+++ b/server/controllers/api/accounts.ts
@@ -18,6 +18,7 @@ import { JobQueue } from '../../lib/job-queue'
18import { logger } from '../../helpers/logger' 18import { logger } from '../../helpers/logger'
19import { VideoPlaylistModel } from '../../models/video/video-playlist' 19import { VideoPlaylistModel } from '../../models/video/video-playlist'
20import { UserModel } from '../../models/account/user' 20import { UserModel } from '../../models/account/user'
21import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists'
21 22
22const accountsRouter = express.Router() 23const accountsRouter = express.Router()
23 24
@@ -57,6 +58,7 @@ accountsRouter.get('/:accountName/video-playlists',
57 videoPlaylistsSortValidator, 58 videoPlaylistsSortValidator,
58 setDefaultSort, 59 setDefaultSort,
59 setDefaultPagination, 60 setDefaultPagination,
61 commonVideoPlaylistFiltersValidator,
60 asyncMiddleware(listAccountPlaylists) 62 asyncMiddleware(listAccountPlaylists)
61) 63)
62 64
@@ -106,7 +108,8 @@ async function listAccountPlaylists (req: express.Request, res: express.Response
106 count: req.query.count, 108 count: req.query.count,
107 sort: req.query.sort, 109 sort: req.query.sort,
108 accountId: res.locals.account.id, 110 accountId: res.locals.account.id,
109 privateAndUnlisted 111 privateAndUnlisted,
112 type: req.query.playlistType
110 }) 113 })
111 114
112 return res.json(getFormattedObjects(resultList.data, resultList.total)) 115 return res.json(getFormattedObjects(resultList.data, resultList.total))
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index 407f32ac0..5758c8227 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -6,7 +6,7 @@ import { getFormattedObjects } from '../../../helpers/utils'
6import { CONFIG, RATES_LIMIT, sequelizeTypescript } from '../../../initializers' 6import { CONFIG, RATES_LIMIT, sequelizeTypescript } from '../../../initializers'
7import { Emailer } from '../../../lib/emailer' 7import { Emailer } from '../../../lib/emailer'
8import { Redis } from '../../../lib/redis' 8import { Redis } from '../../../lib/redis'
9import { createUserAccountAndChannel } from '../../../lib/user' 9import { createUserAccountAndChannelAndPlaylist } from '../../../lib/user'
10import { 10import {
11 asyncMiddleware, 11 asyncMiddleware,
12 asyncRetryTransactionMiddleware, 12 asyncRetryTransactionMiddleware,
@@ -174,7 +174,7 @@ async function createUser (req: express.Request, res: express.Response) {
174 videoQuotaDaily: body.videoQuotaDaily 174 videoQuotaDaily: body.videoQuotaDaily
175 }) 175 })
176 176
177 const { user, account } = await createUserAccountAndChannel(userToCreate) 177 const { user, account } = await createUserAccountAndChannelAndPlaylist(userToCreate)
178 178
179 auditLogger.create(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON())) 179 auditLogger.create(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()))
180 logger.info('User %s with its channel and account created.', body.username) 180 logger.info('User %s with its channel and account created.', body.username)
@@ -205,7 +205,7 @@ async function registerUser (req: express.Request, res: express.Response) {
205 emailVerified: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION ? false : null 205 emailVerified: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION ? false : null
206 }) 206 })
207 207
208 const { user } = await createUserAccountAndChannel(userToCreate) 208 const { user } = await createUserAccountAndChannelAndPlaylist(userToCreate)
209 209
210 auditLogger.create(body.username, new UserAuditView(user.toFormattedJSON())) 210 auditLogger.create(body.username, new UserAuditView(user.toFormattedJSON()))
211 logger.info('User %s with its channel and account registered.', body.username) 211 logger.info('User %s with its channel and account registered.', body.username)
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts
index 534cc8d7b..c13aed4dc 100644
--- a/server/controllers/api/video-channel.ts
+++ b/server/controllers/api/video-channel.ts
@@ -33,6 +33,7 @@ import { resetSequelizeInstance } from '../../helpers/database-utils'
33import { UserModel } from '../../models/account/user' 33import { UserModel } from '../../models/account/user'
34import { JobQueue } from '../../lib/job-queue' 34import { JobQueue } from '../../lib/job-queue'
35import { VideoPlaylistModel } from '../../models/video/video-playlist' 35import { VideoPlaylistModel } from '../../models/video/video-playlist'
36import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists'
36 37
37const auditLogger = auditLoggerFactory('channels') 38const auditLogger = auditLoggerFactory('channels')
38const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR }) 39const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR })
@@ -85,6 +86,7 @@ videoChannelRouter.get('/:nameWithHost/video-playlists',
85 videoPlaylistsSortValidator, 86 videoPlaylistsSortValidator,
86 setDefaultSort, 87 setDefaultSort,
87 setDefaultPagination, 88 setDefaultPagination,
89 commonVideoPlaylistFiltersValidator,
88 asyncMiddleware(listVideoChannelPlaylists) 90 asyncMiddleware(listVideoChannelPlaylists)
89) 91)
90 92
@@ -197,6 +199,8 @@ async function removeVideoChannel (req: express.Request, res: express.Response)
197 const videoChannelInstance: VideoChannelModel = res.locals.videoChannel 199 const videoChannelInstance: VideoChannelModel = res.locals.videoChannel
198 200
199 await sequelizeTypescript.transaction(async t => { 201 await sequelizeTypescript.transaction(async t => {
202 await VideoPlaylistModel.resetPlaylistsOfChannel(videoChannelInstance.id, t)
203
200 await videoChannelInstance.destroy({ transaction: t }) 204 await videoChannelInstance.destroy({ transaction: t })
201 205
202 auditLogger.delete(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannelInstance.toFormattedJSON())) 206 auditLogger.delete(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannelInstance.toFormattedJSON()))
@@ -225,7 +229,8 @@ async function listVideoChannelPlaylists (req: express.Request, res: express.Res
225 start: req.query.start, 229 start: req.query.start,
226 count: req.query.count, 230 count: req.query.count,
227 sort: req.query.sort, 231 sort: req.query.sort,
228 videoChannelId: res.locals.videoChannel.id 232 videoChannelId: res.locals.videoChannel.id,
233 type: req.query.playlistType
229 }) 234 })
230 235
231 return res.json(getFormattedObjects(resultList.data, resultList.total)) 236 return res.json(getFormattedObjects(resultList.data, resultList.total))
diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts
index e026b4d16..8605f3dfc 100644
--- a/server/controllers/api/video-playlist.ts
+++ b/server/controllers/api/video-playlist.ts
@@ -17,6 +17,7 @@ import { logger } from '../../helpers/logger'
17import { resetSequelizeInstance } from '../../helpers/database-utils' 17import { resetSequelizeInstance } from '../../helpers/database-utils'
18import { VideoPlaylistModel } from '../../models/video/video-playlist' 18import { VideoPlaylistModel } from '../../models/video/video-playlist'
19import { 19import {
20 commonVideoPlaylistFiltersValidator,
20 videoPlaylistsAddValidator, 21 videoPlaylistsAddValidator,
21 videoPlaylistsAddVideoValidator, 22 videoPlaylistsAddVideoValidator,
22 videoPlaylistsDeleteValidator, 23 videoPlaylistsDeleteValidator,
@@ -45,6 +46,7 @@ import { VideoPlaylistElementModel } from '../../models/video/video-playlist-ele
45import { VideoPlaylistElementCreate } from '../../../shared/models/videos/playlist/video-playlist-element-create.model' 46import { VideoPlaylistElementCreate } from '../../../shared/models/videos/playlist/video-playlist-element-create.model'
46import { VideoPlaylistElementUpdate } from '../../../shared/models/videos/playlist/video-playlist-element-update.model' 47import { VideoPlaylistElementUpdate } from '../../../shared/models/videos/playlist/video-playlist-element-update.model'
47import { copy, pathExists } from 'fs-extra' 48import { copy, pathExists } from 'fs-extra'
49import { AccountModel } from '../../models/account/account'
48 50
49const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR }) 51const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR })
50 52
@@ -55,6 +57,7 @@ videoPlaylistRouter.get('/',
55 videoPlaylistsSortValidator, 57 videoPlaylistsSortValidator,
56 setDefaultSort, 58 setDefaultSort,
57 setDefaultPagination, 59 setDefaultPagination,
60 commonVideoPlaylistFiltersValidator,
58 asyncMiddleware(listVideoPlaylists) 61 asyncMiddleware(listVideoPlaylists)
59) 62)
60 63
@@ -130,7 +133,8 @@ async function listVideoPlaylists (req: express.Request, res: express.Response)
130 followerActorId: serverActor.id, 133 followerActorId: serverActor.id,
131 start: req.query.start, 134 start: req.query.start,
132 count: req.query.count, 135 count: req.query.count,
133 sort: req.query.sort 136 sort: req.query.sort,
137 type: req.query.type
134 }) 138 })
135 139
136 return res.json(getFormattedObjects(resultList.data, resultList.total)) 140 return res.json(getFormattedObjects(resultList.data, resultList.total))
@@ -171,7 +175,8 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) {
171 const videoPlaylistCreated: VideoPlaylistModel = await sequelizeTypescript.transaction(async t => { 175 const videoPlaylistCreated: VideoPlaylistModel = await sequelizeTypescript.transaction(async t => {
172 const videoPlaylistCreated = await videoPlaylist.save({ transaction: t }) 176 const videoPlaylistCreated = await videoPlaylist.save({ transaction: t })
173 177
174 videoPlaylistCreated.OwnerAccount = user.Account 178 // We need more attributes for the federation
179 videoPlaylistCreated.OwnerAccount = await AccountModel.load(user.Account.id, t)
175 await sendCreateVideoPlaylist(videoPlaylistCreated, t) 180 await sendCreateVideoPlaylist(videoPlaylistCreated, t)
176 181
177 return videoPlaylistCreated 182 return videoPlaylistCreated
@@ -216,6 +221,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response)
216 const videoChannel = res.locals.videoChannel as VideoChannelModel 221 const videoChannel = res.locals.videoChannel as VideoChannelModel
217 222
218 videoPlaylistInstance.videoChannelId = videoChannel.id 223 videoPlaylistInstance.videoChannelId = videoChannel.id
224 videoPlaylistInstance.VideoChannel = videoChannel
219 } 225 }
220 } 226 }
221 227
@@ -227,6 +233,8 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response)
227 } 233 }
228 234
229 const playlistUpdated = await videoPlaylistInstance.save(sequelizeOptions) 235 const playlistUpdated = await videoPlaylistInstance.save(sequelizeOptions)
236 // We need more attributes for the federation
237 playlistUpdated.OwnerAccount = await AccountModel.load(playlistUpdated.OwnerAccount.id, t)
230 238
231 const isNewPlaylist = wasPrivatePlaylist && playlistUpdated.privacy !== VideoPlaylistPrivacy.PRIVATE 239 const isNewPlaylist = wasPrivatePlaylist && playlistUpdated.privacy !== VideoPlaylistPrivacy.PRIVATE
232 240
@@ -290,11 +298,15 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response)
290 const playlistThumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, videoPlaylist.getThumbnailName()) 298 const playlistThumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, videoPlaylist.getThumbnailName())
291 299
292 if (await pathExists(playlistThumbnailPath) === false) { 300 if (await pathExists(playlistThumbnailPath) === false) {
301 logger.info('Generating default thumbnail to playlist %s.', videoPlaylist.url)
302
293 const videoThumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName()) 303 const videoThumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName())
294 await copy(videoThumbnailPath, playlistThumbnailPath) 304 await copy(videoThumbnailPath, playlistThumbnailPath)
295 } 305 }
296 } 306 }
297 307
308 // We need more attributes for the federation
309 videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t)
298 await sendUpdateVideoPlaylist(videoPlaylist, t) 310 await sendUpdateVideoPlaylist(videoPlaylist, t)
299 311
300 return playlistElement 312 return playlistElement
@@ -320,6 +332,8 @@ async function updateVideoPlaylistElement (req: express.Request, res: express.Re
320 332
321 const element = await videoPlaylistElement.save({ transaction: t }) 333 const element = await videoPlaylistElement.save({ transaction: t })
322 334
335 // We need more attributes for the federation
336 videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t)
323 await sendUpdateVideoPlaylist(videoPlaylist, t) 337 await sendUpdateVideoPlaylist(videoPlaylist, t)
324 338
325 return element 339 return element
@@ -341,6 +355,8 @@ async function removeVideoFromPlaylist (req: express.Request, res: express.Respo
341 // Decrease position of the next elements 355 // Decrease position of the next elements
342 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, positionToDelete, null, -1, t) 356 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, positionToDelete, null, -1, t)
343 357
358 // We need more attributes for the federation
359 videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t)
344 await sendUpdateVideoPlaylist(videoPlaylist, t) 360 await sendUpdateVideoPlaylist(videoPlaylist, t)
345 361
346 logger.info('Video playlist element %d of playlist %s deleted.', videoPlaylistElement.position, videoPlaylist.uuid) 362 logger.info('Video playlist element %d of playlist %s deleted.', videoPlaylistElement.position, videoPlaylist.uuid)
@@ -382,6 +398,8 @@ async function reorderVideosPlaylist (req: express.Request, res: express.Respons
382 // Decrease positions of elements after the old position of our ordered elements (decrease) 398 // Decrease positions of elements after the old position of our ordered elements (decrease)
383 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, oldPosition, null, -reorderLength, t) 399 await VideoPlaylistElementModel.increasePositionOf(videoPlaylist.id, oldPosition, null, -reorderLength, t)
384 400
401 // We need more attributes for the federation
402 videoPlaylist.OwnerAccount = await AccountModel.load(videoPlaylist.OwnerAccount.id, t)
385 await sendUpdateVideoPlaylist(videoPlaylist, t) 403 await sendUpdateVideoPlaylist(videoPlaylist, t)
386 }) 404 })
387 405
@@ -415,5 +433,6 @@ async function getVideoPlaylistVideos (req: express.Request, res: express.Respon
415 user: res.locals.oauth ? res.locals.oauth.token.User : undefined 433 user: res.locals.oauth ? res.locals.oauth.token.User : undefined
416 }) 434 })
417 435
418 return res.json(getFormattedObjects(resultList.data, resultList.total)) 436 const additionalAttributes = { playlistInfo: true }
437 return res.json(getFormattedObjects(resultList.data, resultList.total, { additionalAttributes }))
419} 438}