diff options
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r-- | server/controllers/api/videos/index.ts | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index d6f513254..24721a17f 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -2,20 +2,11 @@ import * as express from 'express' | |||
2 | import { extname, join } from 'path' | 2 | import { extname, join } from 'path' |
3 | import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared' | 3 | import { VideoCreate, VideoPrivacy, VideoState, VideoUpdate } from '../../../../shared' |
4 | import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' | 4 | import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' |
5 | import { processImage } from '../../../helpers/image-utils' | ||
6 | import { logger } from '../../../helpers/logger' | 5 | import { logger } from '../../../helpers/logger' |
7 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' | 6 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' |
8 | import { getFormattedObjects, getServerActor } from '../../../helpers/utils' | 7 | import { getFormattedObjects, getServerActor } from '../../../helpers/utils' |
9 | import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' | 8 | import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' |
10 | import { | 9 | import { MIMETYPES, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers/constants' |
11 | MIMETYPES, | ||
12 | PREVIEWS_SIZE, | ||
13 | THUMBNAILS_SIZE, | ||
14 | VIDEO_CATEGORIES, | ||
15 | VIDEO_LANGUAGES, | ||
16 | VIDEO_LICENCES, | ||
17 | VIDEO_PRIVACIES | ||
18 | } from '../../../initializers/constants' | ||
19 | import { | 10 | import { |
20 | changeVideoChannelShare, | 11 | changeVideoChannelShare, |
21 | federateVideoIfNeeded, | 12 | federateVideoIfNeeded, |
@@ -61,6 +52,8 @@ import { Notifier } from '../../../lib/notifier' | |||
61 | import { sendView } from '../../../lib/activitypub/send/send-view' | 52 | import { sendView } from '../../../lib/activitypub/send/send-view' |
62 | import { CONFIG } from '../../../initializers/config' | 53 | import { CONFIG } from '../../../initializers/config' |
63 | import { sequelizeTypescript } from '../../../initializers/database' | 54 | import { sequelizeTypescript } from '../../../initializers/database' |
55 | import { createVideoThumbnailFromExisting, generateVideoThumbnail } from '../../../lib/thumbnail' | ||
56 | import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' | ||
64 | 57 | ||
65 | const auditLogger = auditLoggerFactory('videos') | 58 | const auditLogger = auditLoggerFactory('videos') |
66 | const videosRouter = express.Router() | 59 | const videosRouter = express.Router() |
@@ -220,21 +213,15 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
220 | 213 | ||
221 | // Process thumbnail or create it from the video | 214 | // Process thumbnail or create it from the video |
222 | const thumbnailField = req.files['thumbnailfile'] | 215 | const thumbnailField = req.files['thumbnailfile'] |
223 | if (thumbnailField) { | 216 | const thumbnailModel = thumbnailField |
224 | const thumbnailPhysicalFile = thumbnailField[0] | 217 | ? await createVideoThumbnailFromExisting(thumbnailField[0].path, video, ThumbnailType.THUMBNAIL) |
225 | await processImage(thumbnailPhysicalFile, join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName()), THUMBNAILS_SIZE) | 218 | : await generateVideoThumbnail(video, videoFile, ThumbnailType.THUMBNAIL) |
226 | } else { | ||
227 | await video.createThumbnail(videoFile) | ||
228 | } | ||
229 | 219 | ||
230 | // Process preview or create it from the video | 220 | // Process preview or create it from the video |
231 | const previewField = req.files['previewfile'] | 221 | const previewField = req.files['previewfile'] |
232 | if (previewField) { | 222 | const previewModel = previewField |
233 | const previewPhysicalFile = previewField[0] | 223 | ? await createVideoThumbnailFromExisting(previewField[0].path, video, ThumbnailType.PREVIEW) |
234 | await processImage(previewPhysicalFile, join(CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName()), PREVIEWS_SIZE) | 224 | : await generateVideoThumbnail(video, videoFile, ThumbnailType.PREVIEW) |
235 | } else { | ||
236 | await video.createPreview(videoFile) | ||
237 | } | ||
238 | 225 | ||
239 | // Create the torrent file | 226 | // Create the torrent file |
240 | await video.createTorrentAndSetInfoHash(videoFile) | 227 | await video.createTorrentAndSetInfoHash(videoFile) |
@@ -243,6 +230,13 @@ async function addVideo (req: express.Request, res: express.Response) { | |||
243 | const sequelizeOptions = { transaction: t } | 230 | const sequelizeOptions = { transaction: t } |
244 | 231 | ||
245 | const videoCreated = await video.save(sequelizeOptions) | 232 | const videoCreated = await video.save(sequelizeOptions) |
233 | |||
234 | thumbnailModel.videoId = videoCreated.id | ||
235 | previewModel.videoId = videoCreated.id | ||
236 | |||
237 | videoCreated.addThumbnail(await thumbnailModel.save({ transaction: t })) | ||
238 | videoCreated.addThumbnail(await previewModel.save({ transaction: t })) | ||
239 | |||
246 | // Do not forget to add video channel information to the created video | 240 | // Do not forget to add video channel information to the created video |
247 | videoCreated.VideoChannel = res.locals.videoChannel | 241 | videoCreated.VideoChannel = res.locals.videoChannel |
248 | 242 | ||
@@ -313,16 +307,13 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
313 | const wasUnlistedVideo = videoInstance.privacy === VideoPrivacy.UNLISTED | 307 | const wasUnlistedVideo = videoInstance.privacy === VideoPrivacy.UNLISTED |
314 | 308 | ||
315 | // Process thumbnail or create it from the video | 309 | // Process thumbnail or create it from the video |
316 | if (req.files && req.files['thumbnailfile']) { | 310 | const thumbnailModel = req.files && req.files['thumbnailfile'] |
317 | const thumbnailPhysicalFile = req.files['thumbnailfile'][0] | 311 | ? await createVideoThumbnailFromExisting(req.files['thumbnailfile'][0].path, videoInstance, ThumbnailType.THUMBNAIL) |
318 | await processImage(thumbnailPhysicalFile, join(CONFIG.STORAGE.THUMBNAILS_DIR, videoInstance.getThumbnailName()), THUMBNAILS_SIZE) | 312 | : undefined |
319 | } | ||
320 | 313 | ||
321 | // Process preview or create it from the video | 314 | const previewModel = req.files && req.files['previewfile'] |
322 | if (req.files && req.files['previewfile']) { | 315 | ? await createVideoThumbnailFromExisting(req.files['previewfile'][0].path, videoInstance, ThumbnailType.PREVIEW) |
323 | const previewPhysicalFile = req.files['previewfile'][0] | 316 | : undefined |
324 | await processImage(previewPhysicalFile, join(CONFIG.STORAGE.PREVIEWS_DIR, videoInstance.getPreviewName()), PREVIEWS_SIZE) | ||
325 | } | ||
326 | 317 | ||
327 | try { | 318 | try { |
328 | const videoInstanceUpdated = await sequelizeTypescript.transaction(async t => { | 319 | const videoInstanceUpdated = await sequelizeTypescript.transaction(async t => { |
@@ -355,6 +346,15 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
355 | 346 | ||
356 | const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) | 347 | const videoInstanceUpdated = await videoInstance.save(sequelizeOptions) |
357 | 348 | ||
349 | if (thumbnailModel) { | ||
350 | thumbnailModel.videoId = videoInstanceUpdated.id | ||
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 | |||
358 | // Video tags update? | 358 | // Video tags update? |
359 | if (videoInfoToUpdate.tags !== undefined) { | 359 | if (videoInfoToUpdate.tags !== undefined) { |
360 | const tagInstances = await TagModel.findOrCreateTags(videoInfoToUpdate.tags, t) | 360 | const tagInstances = await TagModel.findOrCreateTags(videoInfoToUpdate.tags, t) |