]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/migrations/0065-video-file-size.ts
Add scores to follows and remove bad ones
[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'
3import { stat } from 'fs'
3fd3ab2d 4import { VideoModel } from '../../models/video/video'
93e1258c
C
5
6function up (utils: {
7 transaction: Sequelize.Transaction,
8 queryInterface: Sequelize.QueryInterface,
9 sequelize: Sequelize.Sequelize,
10 db: any
11}): Promise<void> {
12 return utils.db.Video.listOwnedAndPopulateAuthorAndTags()
3fd3ab2d 13 .then((videos: VideoModel[]) => {
93e1258c
C
14 const tasks: Promise<any>[] = []
15
16 videos.forEach(video => {
17 video.VideoFiles.forEach(videoFile => {
18 const p = new Promise((res, rej) => {
19 stat(video.getVideoFilePath(videoFile), (err, stats) => {
20 if (err) return rej(err)
21
22 videoFile.size = stats.size
23 videoFile.save().then(res).catch(rej)
24 })
25 })
26
27 tasks.push(p)
28 })
29 })
30
31 return tasks
32 })
33 .then((tasks: Promise<any>[]) => {
34 return Promise.all(tasks)
35 })
36}
37
38function down (options) {
39 throw new Error('Not implemented.')
40}
41
42export {
43 up,
44 down
45}