aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers')
-rw-r--r--server/initializers/constants.ts14
-rw-r--r--server/initializers/database.ts2
-rw-r--r--server/initializers/migrations/0060-video-file.ts34
-rw-r--r--server/initializers/migrations/0065-video-file-size.ts46
-rw-r--r--server/initializers/migrator.ts19
5 files changed, 105 insertions, 10 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 314a05ab7..50a939083 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -15,7 +15,7 @@ import {
15 15
16// --------------------------------------------------------------------------- 16// ---------------------------------------------------------------------------
17 17
18const LAST_MIGRATION_VERSION = 55 18const LAST_MIGRATION_VERSION = 65
19 19
20// --------------------------------------------------------------------------- 20// ---------------------------------------------------------------------------
21 21
@@ -114,7 +114,8 @@ const CONSTRAINTS_FIELDS = {
114 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes 114 THUMBNAIL_DATA: { min: 0, max: 20000 }, // Bytes
115 VIEWS: { min: 0 }, 115 VIEWS: { min: 0 },
116 LIKES: { min: 0 }, 116 LIKES: { min: 0 },
117 DISLIKES: { min: 0 } 117 DISLIKES: { min: 0 },
118 FILE_SIZE: { min: 10, max: 1024 * 1024 * 1024 * 3 /* 3Go */ }
118 }, 119 },
119 VIDEO_EVENTS: { 120 VIDEO_EVENTS: {
120 COUNT: { min: 0 } 121 COUNT: { min: 0 }
@@ -176,6 +177,14 @@ const VIDEO_LANGUAGES = {
176 14: 'Italien' 177 14: 'Italien'
177} 178}
178 179
180const VIDEO_FILE_RESOLUTIONS = {
181 0: 'original',
182 1: '360p',
183 2: '480p',
184 3: '720p',
185 4: '1080p'
186}
187
179// --------------------------------------------------------------------------- 188// ---------------------------------------------------------------------------
180 189
181// Score a pod has when we create it as a friend 190// Score a pod has when we create it as a friend
@@ -362,6 +371,7 @@ export {
362 THUMBNAILS_SIZE, 371 THUMBNAILS_SIZE,
363 USER_ROLES, 372 USER_ROLES,
364 VIDEO_CATEGORIES, 373 VIDEO_CATEGORIES,
374 VIDEO_FILE_RESOLUTIONS,
365 VIDEO_LANGUAGES, 375 VIDEO_LANGUAGES,
366 VIDEO_LICENCES, 376 VIDEO_LICENCES,
367 VIDEO_RATE_TYPES 377 VIDEO_RATE_TYPES
diff --git a/server/initializers/database.ts b/server/initializers/database.ts
index 9e691bf1d..c0df2b63a 100644
--- a/server/initializers/database.ts
+++ b/server/initializers/database.ts
@@ -23,6 +23,7 @@ import {
23 UserVideoRateModel, 23 UserVideoRateModel,
24 VideoAbuseModel, 24 VideoAbuseModel,
25 BlacklistedVideoModel, 25 BlacklistedVideoModel,
26 VideoFileModel,
26 VideoTagModel, 27 VideoTagModel,
27 VideoModel 28 VideoModel
28} from '../models' 29} from '../models'
@@ -49,6 +50,7 @@ const database: {
49 UserVideoRate?: UserVideoRateModel, 50 UserVideoRate?: UserVideoRateModel,
50 User?: UserModel, 51 User?: UserModel,
51 VideoAbuse?: VideoAbuseModel, 52 VideoAbuse?: VideoAbuseModel,
53 VideoFile?: VideoFileModel,
52 BlacklistedVideo?: BlacklistedVideoModel, 54 BlacklistedVideo?: BlacklistedVideoModel,
53 VideoTag?: VideoTagModel, 55 VideoTag?: VideoTagModel,
54 Video?: VideoModel 56 Video?: VideoModel
diff --git a/server/initializers/migrations/0060-video-file.ts b/server/initializers/migrations/0060-video-file.ts
new file mode 100644
index 000000000..c362cf71a
--- /dev/null
+++ b/server/initializers/migrations/0060-video-file.ts
@@ -0,0 +1,34 @@
1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird'
3
4function up (utils: {
5 transaction: Sequelize.Transaction,
6 queryInterface: Sequelize.QueryInterface,
7 sequelize: Sequelize.Sequelize,
8 db: any
9}): Promise<void> {
10 const q = utils.queryInterface
11
12 const query = 'INSERT INTO "VideoFiles" ("videoId", "resolution", "size", "extname", "infoHash", "createdAt", "updatedAt") ' +
13 'SELECT "id" AS "videoId", 0 AS "resolution", 0 AS "size", ' +
14 '"extname"::"text"::"enum_VideoFiles_extname" as "extname", "infoHash", "createdAt", "updatedAt" ' +
15 'FROM "Videos"'
16
17 return utils.db.VideoFile.sync()
18 .then(() => utils.sequelize.query(query))
19 .then(() => {
20 return q.removeColumn('Videos', 'extname')
21 })
22 .then(() => {
23 return q.removeColumn('Videos', 'infoHash')
24 })
25}
26
27function down (options) {
28 throw new Error('Not implemented.')
29}
30
31export {
32 up,
33 down
34}
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 @@
1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird'
3import { stat } from 'fs'
4
5import { VideoInstance } from '../../models'
6
7function 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
39function down (options) {
40 throw new Error('Not implemented.')
41}
42
43export {
44 up,
45 down
46}
diff --git a/server/initializers/migrator.ts b/server/initializers/migrator.ts
index 71a656c59..7b535aea9 100644
--- a/server/initializers/migrator.ts
+++ b/server/initializers/migrator.ts
@@ -64,14 +64,16 @@ function getMigrationScripts () {
64 script: string 64 script: string
65 }[] = [] 65 }[] = []
66 66
67 files.forEach(file => { 67 files
68 // Filename is something like 'version-blabla.js' 68 .filter(file => file.endsWith('.js.map') === false)
69 const version = file.split('-')[0] 69 .forEach(file => {
70 filesToMigrate.push({ 70 // Filename is something like 'version-blabla.js'
71 version, 71 const version = file.split('-')[0]
72 script: file 72 filesToMigrate.push({
73 version,
74 script: file
75 })
73 }) 76 })
74 })
75 77
76 return filesToMigrate 78 return filesToMigrate
77 }) 79 })
@@ -93,7 +95,8 @@ function executeMigration (actualVersion: number, entity: { version: string, scr
93 const options = { 95 const options = {
94 transaction: t, 96 transaction: t,
95 queryInterface: db.sequelize.getQueryInterface(), 97 queryInterface: db.sequelize.getQueryInterface(),
96 sequelize: db.sequelize 98 sequelize: db.sequelize,
99 db
97 } 100 }
98 101
99 return migrationScript.up(options) 102 return migrationScript.up(options)