diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-09 11:06:13 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-09 11:17:36 +0200 |
commit | 14d3270f363245d2c83fcc2ac109e39743b5627e (patch) | |
tree | 22a1d40675d372d53c35a4d7adf1fc1b4ceb1799 /server/initializers/migrations/0075-video-resolutions.ts | |
parent | aa8b6df4a51c82eb91e6fd71a090b2128098af6b (diff) | |
download | PeerTube-14d3270f363245d2c83fcc2ac109e39743b5627e.tar.gz PeerTube-14d3270f363245d2c83fcc2ac109e39743b5627e.tar.zst PeerTube-14d3270f363245d2c83fcc2ac109e39743b5627e.zip |
Change how we handle resolution
It was an enum before, now we just use video height
Diffstat (limited to 'server/initializers/migrations/0075-video-resolutions.ts')
-rw-r--r-- | server/initializers/migrations/0075-video-resolutions.ts | 43 |
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 | ||
5 | import { readdirPromise, renamePromise } from '../../helpers/core-utils' | 5 | import { readdirPromise, renamePromise } from '../../helpers/core-utils' |
6 | import { CONFIG } from '../../initializers/constants' | 6 | import { CONFIG } from '../../initializers/constants' |
7 | import { getVideoFileHeight } from '../../helpers/ffmpeg-utils' | ||
7 | 8 | ||
8 | function up (utils: { | 9 | function 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 | ||