- const newVideoFileName = matches[1] + '-original.' + matches[2]
- const p = renamePromise(join(videoFileDir, videoFile), join(videoFileDir, newVideoFileName))
+ const uuid = matches[1]
+ const ext = matches[2]
+
+ const p = getVideoFileResolution(join(videoFileDir, videoFile))
+ .then(height => {
+ 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 +
+ ' WHERE "videoId" = (SELECT "id" FROM "Videos" WHERE "uuid" = \'' + uuid + '\')'
+ return utils.sequelize.query(query)
+ })
+