]>
Commit | Line | Data |
---|---|---|
1 | import * as Sequelize from 'sequelize' | |
2 | import * as Promise from 'bluebird' | |
3 | import { stat } from 'fs' | |
4 | import { VideoModel } from '../../models/video/video' | |
5 | ||
6 | function 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() | |
13 | .then((videos: VideoModel[]) => { | |
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 | ||
38 | function down (options) { | |
39 | throw new Error('Not implemented.') | |
40 | } | |
41 | ||
42 | export { | |
43 | up, | |
44 | down | |
45 | } |