]>
Commit | Line | Data |
---|---|---|
93e1258c | 1 | import * as Sequelize from 'sequelize' |
c9d5c64f | 2 | import { stat } from 'fs-extra' |
3fd3ab2d | 3 | import { VideoModel } from '../../models/video/video' |
d7a25329 | 4 | import { getVideoFilePath } from '@server/lib/video-paths' |
93e1258c C |
5 | |
6 | function up (utils: { | |
a1587156 C |
7 | transaction: Sequelize.Transaction |
8 | queryInterface: Sequelize.QueryInterface | |
9 | sequelize: Sequelize.Sequelize | |
93e1258c C |
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) => { | |
d7a25329 | 19 | stat(getVideoFilePath(video, videoFile), (err, stats) => { |
93e1258c C |
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 | ||
38 | function down (options) { | |
39 | throw new Error('Not implemented.') | |
40 | } | |
41 | ||
42 | export { | |
43 | up, | |
44 | down | |
45 | } |