- return db.Tag.findOrCreateTags(tags, t).then(tagInstances => ({ author, tagInstances }))
- })
- .then(({ author, tagInstances }) => {
- const videoData = {
- name: videoInfo.name,
- remote: false,
- extname: extname(videoPhysicalFile.filename),
- category: videoInfo.category,
- licence: videoInfo.licence,
- language: videoInfo.language,
- nsfw: videoInfo.nsfw,
- description: videoInfo.description,
- duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
- authorId: author.id
- }
-
- const video = db.Video.build(videoData)
- return { author, tagInstances, video }
- })
- .then(({ author, tagInstances, video }) => {
- const videoFileData = {
- extname: extname(videoPhysicalFile.filename),
- resolution: 0, // TODO: improve readability,
- size: videoPhysicalFile.size
- }
-
- const videoFile = db.VideoFile.build(videoFileData)
- return { author, tagInstances, video, videoFile }
- })
- .then(({ author, tagInstances, video, videoFile }) => {
- const videoDir = CONFIG.STORAGE.VIDEOS_DIR
- const source = join(videoDir, videoPhysicalFile.filename)
- const destination = join(videoDir, video.getVideoFilename(videoFile))
-
- return renamePromise(source, destination)
- .then(() => {
- // This is important in case if there is another attempt in the retry process
- videoPhysicalFile.filename = video.getVideoFilename(videoFile)
- return { author, tagInstances, video, videoFile }
- })
- })
- .then(({ author, tagInstances, video, videoFile }) => {
- const tasks = []
-
- tasks.push(
- video.createTorrentAndSetInfoHash(videoFile),
- video.createThumbnail(videoFile),
- video.createPreview(videoFile)
- )
-
- if (CONFIG.TRANSCODING.ENABLED === true) {
- // Put uuid because we don't have id auto incremented for now
- const dataInput = {
- videoUUID: video.uuid
- }
-
- tasks.push(
- JobScheduler.Instance.createJob(t, 'videoTranscoder', dataInput)
- )
- }
-
- return Promise.all(tasks).then(() => ({ author, tagInstances, video, videoFile }))
- })
- .then(({ author, tagInstances, video, videoFile }) => {
- const options = { transaction: t }