X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Finitializers%2Fmigrations%2F0075-video-resolutions.ts;h=6e8e47acbf04ef7d9ea286f99185b090dafa0a31;hb=c55e3d7227fe1453869e309025996b9d75256d5d;hp=e1d9fdacbd27579f2e7a72421ddb859de6ee211a;hpb=14d3270f363245d2c83fcc2ac109e39743b5627e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/initializers/migrations/0075-video-resolutions.ts b/server/initializers/migrations/0075-video-resolutions.ts index e1d9fdacb..6e8e47acb 100644 --- a/server/initializers/migrations/0075-video-resolutions.ts +++ b/server/initializers/migrations/0075-video-resolutions.ts @@ -1,21 +1,19 @@ import * as Sequelize from 'sequelize' -import * as Promise from 'bluebird' import { join } from 'path' - -import { readdirPromise, renamePromise } from '../../helpers/core-utils' -import { CONFIG } from '../../initializers/constants' -import { getVideoFileHeight } from '../../helpers/ffmpeg-utils' +import { CONFIG } from '../../initializers/config' +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 { const torrentDir = CONFIG.STORAGE.TORRENTS_DIR const videoFileDir = CONFIG.STORAGE.VIDEOS_DIR - return readdirPromise(videoFileDir) + return readdir(videoFileDir) .then(videoFiles => { const tasks: Promise[] = [] for (const videoFile of videoFiles) { @@ -28,18 +26,16 @@ function up (utils: { const uuid = matches[1] const ext = matches[2] - const p = getVideoFileHeight(join(videoFileDir, videoFile)) - .then(height => { + const p = getVideoFileResolution(join(videoFileDir, videoFile)) + .then(async ({ resolution }) => { const oldTorrentName = uuid + '.torrent' - const newTorrentName = uuid + '-' + height + '.torrent' - return renamePromise(join(torrentDir, oldTorrentName), join(torrentDir, newTorrentName)).then(() => height) - }) - .then(height => { - const newVideoFileName = uuid + '-' + height + '.' + ext - return renamePromise(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) })