]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - 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
1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird'
3import { stat } from 'fs-extra'
4import { VideoModel } from '../../models/video/video'
5import { getVideoFilePath } from '@server/lib/video-paths'
6
7function up (utils: {
8 transaction: Sequelize.Transaction
9 queryInterface: Sequelize.QueryInterface
10 sequelize: Sequelize.Sequelize
11 db: any
12}): Promise<void> {
13 return utils.db.Video.listOwnedAndPopulateAuthorAndTags()
14 .then((videos: VideoModel[]) => {
15 const tasks: Promise<any>[] = []
16
17 videos.forEach(video => {
18 video.VideoFiles.forEach(videoFile => {
19 const p = new Promise((res, rej) => {
20 stat(getVideoFilePath(video, videoFile), (err, stats) => {
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}