aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/index.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-23 09:50:57 +0200
committerChocobozzz <me@florianbigard.com>2019-04-24 16:26:21 +0200
commit3acc50844047a37698f0618fa235c138e386a053 (patch)
treee33243bf7fadbcf2df616fc41814245094fd881a /server/controllers/api/videos/index.ts
parent1735c825726edaa0af5035cb6cbb0cc0db502c6d (diff)
downloadPeerTube-3acc50844047a37698f0618fa235c138e386a053.tar.gz
PeerTube-3acc50844047a37698f0618fa235c138e386a053.tar.zst
PeerTube-3acc50844047a37698f0618fa235c138e386a053.zip
Upgrade sequelize
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r--server/controllers/api/videos/index.ts31
1 files changed, 11 insertions, 20 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index ad2fe958c..5bbce11b4 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -52,7 +52,7 @@ import { Notifier } from '../../../lib/notifier'
52import { sendView } from '../../../lib/activitypub/send/send-view' 52import { sendView } from '../../../lib/activitypub/send/send-view'
53import { CONFIG } from '../../../initializers/config' 53import { CONFIG } from '../../../initializers/config'
54import { sequelizeTypescript } from '../../../initializers/database' 54import { sequelizeTypescript } from '../../../initializers/database'
55import { createVideoThumbnailFromExisting, generateVideoThumbnail } from '../../../lib/thumbnail' 55import { createVideoMiniatureFromExisting, generateVideoMiniature } from '../../../lib/thumbnail'
56import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' 56import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
57 57
58const auditLogger = auditLoggerFactory('videos') 58const auditLogger = auditLoggerFactory('videos')
@@ -214,14 +214,14 @@ async function addVideo (req: express.Request, res: express.Response) {
214 // Process thumbnail or create it from the video 214 // Process thumbnail or create it from the video
215 const thumbnailField = req.files['thumbnailfile'] 215 const thumbnailField = req.files['thumbnailfile']
216 const thumbnailModel = thumbnailField 216 const thumbnailModel = thumbnailField
217 ? await createVideoThumbnailFromExisting(thumbnailField[0].path, video, ThumbnailType.THUMBNAIL) 217 ? await createVideoMiniatureFromExisting(thumbnailField[0].path, video, ThumbnailType.MINIATURE)
218 : await generateVideoThumbnail(video, videoFile, ThumbnailType.THUMBNAIL) 218 : await generateVideoMiniature(video, videoFile, ThumbnailType.MINIATURE)
219 219
220 // Process preview or create it from the video 220 // Process preview or create it from the video
221 const previewField = req.files['previewfile'] 221 const previewField = req.files['previewfile']
222 const previewModel = previewField 222 const previewModel = previewField
223 ? await createVideoThumbnailFromExisting(previewField[0].path, video, ThumbnailType.PREVIEW) 223 ? await createVideoMiniatureFromExisting(previewField[0].path, video, ThumbnailType.PREVIEW)
224 : await generateVideoThumbnail(video, videoFile, ThumbnailType.PREVIEW) 224 : await generateVideoMiniature(video, videoFile, ThumbnailType.PREVIEW)
225 225
226 // Create the torrent file 226 // Create the torrent file
227 await video.createTorrentAndSetInfoHash(videoFile) 227 await video.createTorrentAndSetInfoHash(videoFile)
@@ -231,11 +231,8 @@ async function addVideo (req: express.Request, res: express.Response) {
231 231
232 const videoCreated = await video.save(sequelizeOptions) 232 const videoCreated = await video.save(sequelizeOptions)
233 233
234 thumbnailModel.videoId = videoCreated.id 234 await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
235 previewModel.videoId = videoCreated.id 235 await videoCreated.addAndSaveThumbnail(previewModel, t)
236
237 videoCreated.addThumbnail(await thumbnailModel.save({ transaction: t }))
238 videoCreated.addThumbnail(await previewModel.save({ transaction: t }))
239 236
240 // Do not forget to add video channel information to the created video 237 // Do not forget to add video channel information to the created video
241 videoCreated.VideoChannel = res.locals.videoChannel 238 videoCreated.VideoChannel = res.locals.videoChannel
@@ -308,11 +305,11 @@ async function updateVideo (req: express.Request, res: express.Response) {
308 305
309 // Process thumbnail or create it from the video 306 // Process thumbnail or create it from the video
310 const thumbnailModel = req.files && req.files['thumbnailfile'] 307 const thumbnailModel = req.files && req.files['thumbnailfile']
311 ? await createVideoThumbnailFromExisting(req.files['thumbnailfile'][0].path, videoInstance, ThumbnailType.THUMBNAIL) 308 ? await createVideoMiniatureFromExisting(req.files['thumbnailfile'][0].path, videoInstance, ThumbnailType.MINIATURE)
312 : undefined 309 : undefined
313 310
314 const previewModel = req.files && req.files['previewfile'] 311 const previewModel = req.files && req.files['previewfile']
315 ? await createVideoThumbnailFromExisting(req.files['previewfile'][0].path, videoInstance, ThumbnailType.PREVIEW) 312 ? await createVideoMiniatureFromExisting(req.files['previewfile'][0].path, videoInstance, ThumbnailType.PREVIEW)
316 : undefined 313 : undefined
317 314
318 try { 315 try {
@@ -346,14 +343,8 @@ async function updateVideo (req: express.Request, res: express.Response) {
346 343
347 const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) 344 const videoInstanceUpdated = await videoInstance.save(sequelizeOptions)
348 345
349 if (thumbnailModel) { 346 if (thumbnailModel) await videoInstanceUpdated.addAndSaveThumbnail(thumbnailModel, t)
350 thumbnailModel.videoId = videoInstanceUpdated.id 347 if (previewModel) await videoInstanceUpdated.addAndSaveThumbnail(previewModel, t)
351 videoInstanceUpdated.addThumbnail(await thumbnailModel.save({ transaction: t }))
352 }
353 if (previewModel) {
354 previewModel.videoId = videoInstanceUpdated.id
355 videoInstanceUpdated.addThumbnail(await previewModel.save({ transaction: t }))
356 }
357 348
358 // Video tags update? 349 // Video tags update?
359 if (videoInfoToUpdate.tags !== undefined) { 350 if (videoInfoToUpdate.tags !== undefined) {