aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
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
parent1735c825726edaa0af5035cb6cbb0cc0db502c6d (diff)
downloadPeerTube-3acc50844047a37698f0618fa235c138e386a053.tar.gz
PeerTube-3acc50844047a37698f0618fa235c138e386a053.tar.zst
PeerTube-3acc50844047a37698f0618fa235c138e386a053.zip
Upgrade sequelize
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/video-playlist.ts20
-rw-r--r--server/controllers/api/videos/import.ts16
-rw-r--r--server/controllers/api/videos/index.ts31
3 files changed, 23 insertions, 44 deletions
diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts
index 99325aa9d..6a1d23529 100644
--- a/server/controllers/api/video-playlist.ts
+++ b/server/controllers/api/video-playlist.ts
@@ -41,7 +41,7 @@ import { VideoPlaylistReorder } from '../../../shared/models/videos/playlist/vid
41import { JobQueue } from '../../lib/job-queue' 41import { JobQueue } from '../../lib/job-queue'
42import { CONFIG } from '../../initializers/config' 42import { CONFIG } from '../../initializers/config'
43import { sequelizeTypescript } from '../../initializers/database' 43import { sequelizeTypescript } from '../../initializers/database'
44import { createPlaylistThumbnailFromExisting } from '../../lib/thumbnail' 44import { createPlaylistMiniatureFromExisting } from '../../lib/thumbnail'
45 45
46const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR }) 46const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR })
47 47
@@ -174,16 +174,13 @@ async function addVideoPlaylist (req: express.Request, res: express.Response) {
174 174
175 const thumbnailField = req.files['thumbnailfile'] 175 const thumbnailField = req.files['thumbnailfile']
176 const thumbnailModel = thumbnailField 176 const thumbnailModel = thumbnailField
177 ? await createPlaylistThumbnailFromExisting(thumbnailField[0].path, videoPlaylist) 177 ? await createPlaylistMiniatureFromExisting(thumbnailField[0].path, videoPlaylist)
178 : undefined 178 : undefined
179 179
180 const videoPlaylistCreated: VideoPlaylistModel = await sequelizeTypescript.transaction(async t => { 180 const videoPlaylistCreated: VideoPlaylistModel = await sequelizeTypescript.transaction(async t => {
181 const videoPlaylistCreated = await videoPlaylist.save({ transaction: t }) 181 const videoPlaylistCreated = await videoPlaylist.save({ transaction: t })
182 182
183 if (thumbnailModel) { 183 if (thumbnailModel) await videoPlaylistCreated.setAndSaveThumbnail(thumbnailModel, t)
184 thumbnailModel.videoPlaylistId = videoPlaylistCreated.id
185 videoPlaylistCreated.setThumbnail(await thumbnailModel.save({ transaction: t }))
186 }
187 184
188 // We need more attributes for the federation 185 // We need more attributes for the federation
189 videoPlaylistCreated.OwnerAccount = await AccountModel.load(user.Account.id, t) 186 videoPlaylistCreated.OwnerAccount = await AccountModel.load(user.Account.id, t)
@@ -210,7 +207,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response)
210 207
211 const thumbnailField = req.files['thumbnailfile'] 208 const thumbnailField = req.files['thumbnailfile']
212 const thumbnailModel = thumbnailField 209 const thumbnailModel = thumbnailField
213 ? await createPlaylistThumbnailFromExisting(thumbnailField[0].path, videoPlaylistInstance) 210 ? await createPlaylistMiniatureFromExisting(thumbnailField[0].path, videoPlaylistInstance)
214 : undefined 211 : undefined
215 212
216 try { 213 try {
@@ -239,10 +236,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response)
239 236
240 const playlistUpdated = await videoPlaylistInstance.save(sequelizeOptions) 237 const playlistUpdated = await videoPlaylistInstance.save(sequelizeOptions)
241 238
242 if (thumbnailModel) { 239 if (thumbnailModel) await playlistUpdated.setAndSaveThumbnail(thumbnailModel, t)
243 thumbnailModel.videoPlaylistId = playlistUpdated.id
244 playlistUpdated.setThumbnail(await thumbnailModel.save({ transaction: t }))
245 }
246 240
247 const isNewPlaylist = wasPrivatePlaylist && playlistUpdated.privacy !== VideoPlaylistPrivacy.PRIVATE 241 const isNewPlaylist = wasPrivatePlaylist && playlistUpdated.privacy !== VideoPlaylistPrivacy.PRIVATE
248 242
@@ -313,8 +307,8 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response)
313 if (playlistElement.position === 1 && videoPlaylist.hasThumbnail() === false) { 307 if (playlistElement.position === 1 && videoPlaylist.hasThumbnail() === false) {
314 logger.info('Generating default thumbnail to playlist %s.', videoPlaylist.url) 308 logger.info('Generating default thumbnail to playlist %s.', videoPlaylist.url)
315 309
316 const inputPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnail().filename) 310 const inputPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getMiniature().filename)
317 const thumbnailModel = await createPlaylistThumbnailFromExisting(inputPath, videoPlaylist, true) 311 const thumbnailModel = await createPlaylistMiniatureFromExisting(inputPath, videoPlaylist, true)
318 312
319 thumbnailModel.videoPlaylistId = videoPlaylist.id 313 thumbnailModel.videoPlaylistId = videoPlaylist.id
320 314
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) {