diff options
Diffstat (limited to 'server/initializers/migrations/0065-video-file-size.ts')
-rw-r--r-- | server/initializers/migrations/0065-video-file-size.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/server/initializers/migrations/0065-video-file-size.ts b/server/initializers/migrations/0065-video-file-size.ts new file mode 100644 index 000000000..58f8f3bcc --- /dev/null +++ b/server/initializers/migrations/0065-video-file-size.ts | |||
@@ -0,0 +1,46 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import * as Promise from 'bluebird' | ||
3 | import { stat } from 'fs' | ||
4 | |||
5 | import { VideoInstance } from '../../models' | ||
6 | |||
7 | function 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: VideoInstance[]) => { | ||
15 | const tasks: Promise<any>[] = [] | ||
16 | |||
17 | videos.forEach(video => { | ||
18 | video.VideoFiles.forEach(videoFile => { | ||
19 | const p = new Promise((res, rej) => { | ||
20 | stat(video.getVideoFilePath(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 | |||
39 | function down (options) { | ||
40 | throw new Error('Not implemented.') | ||
41 | } | ||
42 | |||
43 | export { | ||
44 | up, | ||
45 | down | ||
46 | } | ||