aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
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
parent1735c825726edaa0af5035cb6cbb0cc0db502c6d (diff)
downloadPeerTube-3acc50844047a37698f0618fa235c138e386a053.tar.gz
PeerTube-3acc50844047a37698f0618fa235c138e386a053.tar.zst
PeerTube-3acc50844047a37698f0618fa235c138e386a053.zip
Upgrade sequelize
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/import.ts16
-rw-r--r--server/controllers/api/videos/index.ts31
2 files changed, 16 insertions, 31 deletions
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index a4ec41d44..bfb690906 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -23,7 +23,7 @@ import { move, readFile } from 'fs-extra'
23import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' 23import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist'
24import { CONFIG } from '../../../initializers/config' 24import { CONFIG } from '../../../initializers/config'
25import { sequelizeTypescript } from '../../../initializers/database' 25import { sequelizeTypescript } from '../../../initializers/database'
26import { createVideoThumbnailFromExisting } from '../../../lib/thumbnail' 26import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail'
27import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' 27import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
28import { ThumbnailModel } from '../../../models/video/thumbnail' 28import { ThumbnailModel } from '../../../models/video/thumbnail'
29 29
@@ -204,7 +204,7 @@ async function processThumbnail (req: express.Request, video: VideoModel) {
204 if (thumbnailField) { 204 if (thumbnailField) {
205 const thumbnailPhysicalFile = thumbnailField[ 0 ] 205 const thumbnailPhysicalFile = thumbnailField[ 0 ]
206 206
207 return createVideoThumbnailFromExisting(thumbnailPhysicalFile.path, video, ThumbnailType.THUMBNAIL) 207 return createVideoMiniatureFromExisting(thumbnailPhysicalFile.path, video, ThumbnailType.MINIATURE)
208 } 208 }
209 209
210 return undefined 210 return undefined
@@ -215,7 +215,7 @@ async function processPreview (req: express.Request, video: VideoModel) {
215 if (previewField) { 215 if (previewField) {
216 const previewPhysicalFile = previewField[0] 216 const previewPhysicalFile = previewField[0]
217 217
218 return createVideoThumbnailFromExisting(previewPhysicalFile.path, video, ThumbnailType.PREVIEW) 218 return createVideoMiniatureFromExisting(previewPhysicalFile.path, video, ThumbnailType.PREVIEW)
219 } 219 }
220 220
221 return undefined 221 return undefined
@@ -238,14 +238,8 @@ function insertIntoDB (parameters: {
238 const videoCreated = await video.save(sequelizeOptions) 238 const videoCreated = await video.save(sequelizeOptions)
239 videoCreated.VideoChannel = videoChannel 239 videoCreated.VideoChannel = videoChannel
240 240
241 if (thumbnailModel) { 241 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
242 thumbnailModel.videoId = videoCreated.id 242 if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t)
243 videoCreated.addThumbnail(await thumbnailModel.save({ transaction: t }))
244 }
245 if (previewModel) {
246 previewModel.videoId = videoCreated.id
247 videoCreated.addThumbnail(await previewModel.save({ transaction: t }))
248 }
249 243
250 await autoBlacklistVideoIfNeeded(video, videoChannel.Account.User, t) 244 await autoBlacklistVideoIfNeeded(video, videoChannel.Account.User, t)
251 245
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) {