aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers/migrations')
-rw-r--r--server/initializers/migrations/0075-video-resolutions.ts43
1 files changed, 21 insertions, 22 deletions
diff --git a/server/initializers/migrations/0075-video-resolutions.ts b/server/initializers/migrations/0075-video-resolutions.ts
index 6bc1e72ab..e1d9fdacb 100644
--- a/server/initializers/migrations/0075-video-resolutions.ts
+++ b/server/initializers/migrations/0075-video-resolutions.ts
@@ -4,6 +4,7 @@ import { join } from 'path'
4 4
5import { readdirPromise, renamePromise } from '../../helpers/core-utils' 5import { readdirPromise, renamePromise } from '../../helpers/core-utils'
6import { CONFIG } from '../../initializers/constants' 6import { CONFIG } from '../../initializers/constants'
7import { getVideoFileHeight } from '../../helpers/ffmpeg-utils'
7 8
8function up (utils: { 9function up (utils: {
9 transaction: Sequelize.Transaction, 10 transaction: Sequelize.Transaction,
@@ -14,26 +15,7 @@ function up (utils: {
14 const torrentDir = CONFIG.STORAGE.TORRENTS_DIR 15 const torrentDir = CONFIG.STORAGE.TORRENTS_DIR
15 const videoFileDir = CONFIG.STORAGE.VIDEOS_DIR 16 const videoFileDir = CONFIG.STORAGE.VIDEOS_DIR
16 17
17 return readdirPromise(torrentDir) 18 return readdirPromise(videoFileDir)
18 .then(torrentFiles => {
19 const tasks: Promise<any>[] = []
20 for (const torrentFile of torrentFiles) {
21 const matches = /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.torrent/.exec(torrentFile)
22 if (matches === null) {
23 console.log('Invalid torrent file name %s.', torrentFile)
24 continue
25 }
26
27 const newTorrentName = matches[1] + '-original.torrent'
28 const p = renamePromise(join(torrentDir, torrentFile), join(torrentDir, newTorrentName))
29 tasks.push(p)
30 }
31
32 return Promise.all(tasks)
33 })
34 .then(() => {
35 return readdirPromise(videoFileDir)
36 })
37 .then(videoFiles => { 19 .then(videoFiles => {
38 const tasks: Promise<any>[] = [] 20 const tasks: Promise<any>[] = []
39 for (const videoFile of videoFiles) { 21 for (const videoFile of videoFiles) {
@@ -43,8 +25,25 @@ function up (utils: {
43 continue 25 continue
44 } 26 }
45 27
46 const newVideoFileName = matches[1] + '-original.' + matches[2] 28 const uuid = matches[1]
47 const p = renamePromise(join(videoFileDir, videoFile), join(videoFileDir, newVideoFileName)) 29 const ext = matches[2]
30
31 const p = getVideoFileHeight(join(videoFileDir, videoFile))
32 .then(height => {
33 const oldTorrentName = uuid + '.torrent'
34 const newTorrentName = uuid + '-' + height + '.torrent'
35 return renamePromise(join(torrentDir, oldTorrentName), join(torrentDir, newTorrentName)).then(() => height)
36 })
37 .then(height => {
38 const newVideoFileName = uuid + '-' + height + '.' + ext
39 return renamePromise(join(videoFileDir, videoFile), join(videoFileDir, newVideoFileName)).then(() => height)
40 })
41 .then(height => {
42 const query = 'UPDATE "VideoFiles" SET "resolution" = ' + height +
43 ' WHERE "videoId" = (SELECT "id" FROM "Videos" WHERE "uuid" = \'' + uuid + '\')'
44 return utils.sequelize.query(query)
45 })
46
48 tasks.push(p) 47 tasks.push(p)
49 } 48 }
50 49