import * as Sequelize from 'sequelize'
import { join } from 'path'
import { CONFIG } from '../../initializers/config'
-import { getVideoFileResolution } from '../../helpers/ffmpeg-utils'
+import { getVideoFileResolution } from '../../helpers/ffprobe-utils'
import { readdir, rename } from 'fs-extra'
function up (utils: {
- transaction: Sequelize.Transaction,
- queryInterface: Sequelize.QueryInterface,
- sequelize: Sequelize.Sequelize,
+ transaction: Sequelize.Transaction
+ queryInterface: Sequelize.QueryInterface
+ sequelize: Sequelize.Sequelize
db: any
}): Promise<void> {
const torrentDir = CONFIG.STORAGE.TORRENTS_DIR
const ext = matches[2]
const p = getVideoFileResolution(join(videoFileDir, videoFile))
- .then(height => {
+ .then(async ({ resolution }) => {
const oldTorrentName = uuid + '.torrent'
- const newTorrentName = uuid + '-' + height + '.torrent'
- return rename(join(torrentDir, oldTorrentName), join(torrentDir, newTorrentName)).then(() => height)
- })
- .then(height => {
- const newVideoFileName = uuid + '-' + height + '.' + ext
- return rename(join(videoFileDir, videoFile), join(videoFileDir, newVideoFileName)).then(() => height)
- })
- .then(height => {
- const query = 'UPDATE "VideoFiles" SET "resolution" = ' + height +
+ const newTorrentName = uuid + '-' + resolution + '.torrent'
+ await rename(join(torrentDir, oldTorrentName), join(torrentDir, newTorrentName)).then(() => resolution)
+
+ const newVideoFileName = uuid + '-' + resolution + '.' + ext
+ await rename(join(videoFileDir, videoFile), join(videoFileDir, newVideoFileName)).then(() => resolution)
+
+ const query = 'UPDATE "VideoFiles" SET "resolution" = ' + resolution +
' WHERE "videoId" = (SELECT "id" FROM "Videos" WHERE "uuid" = \'' + uuid + '\')'
return utils.sequelize.query(query)
})