]>
Commit | Line | Data |
---|---|---|
93e1258c C |
1 | import * as Sequelize from 'sequelize' |
2 | import * as Promise from 'bluebird' | |
c9d5c64f | 3 | import { stat } from 'fs-extra' |
3fd3ab2d | 4 | import { VideoModel } from '../../models/video/video' |
d7a25329 | 5 | import { getVideoFilePath } from '@server/lib/video-paths' |
93e1258c C |
6 | |
7 | function 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 | ||
39 | function down (options) { | |
40 | throw new Error('Not implemented.') | |
41 | } | |
42 | ||
43 | export { | |
44 | up, | |
45 | down | |
46 | } |