]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/migrations/0065-video-file-size.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / initializers / migrations / 0065-video-file-size.ts
CommitLineData
93e1258c
C
1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird'
c9d5c64f 3import { stat } from 'fs-extra'
3fd3ab2d 4import { VideoModel } from '../../models/video/video'
d7a25329 5import { getVideoFilePath } from '@server/lib/video-paths'
93e1258c
C
6
7function up (utils: {
a1587156
C
8 transaction: Sequelize.Transaction
9 queryInterface: Sequelize.QueryInterface
10 sequelize: Sequelize.Sequelize
93e1258c
C
11 db: any
12}): Promise<void> {
13 return utils.db.Video.listOwnedAndPopulateAuthorAndTags()
3fd3ab2d 14 .then((videos: VideoModel[]) => {
93e1258c
C
15 const tasks: Promise<any>[] = []
16
17 videos.forEach(video => {
18 video.VideoFiles.forEach(videoFile => {
19 const p = new Promise((res, rej) => {
d7a25329 20 stat(getVideoFilePath(video, videoFile), (err, stats) => {
93e1258c
C
21 if (err) return rej(err)
22
23 videoFile.size = stats.size
24 videoFile.save().then(res).catch(rej)
25 })
26 })
27
28 tasks.push(p)
29 })
30 })
31
32 return tasks
33 })
34 .then((tasks: Promise<any>[]) => {
35 return Promise.all(tasks)
36 })
37}
38
39function down (options) {
40 throw new Error('Not implemented.')
41}
42
43export {
44 up,
45 down
46}