aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-file.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-08-25 11:36:23 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-08-25 11:36:23 +0200
commit93e1258c7cbc0d1235ca6d2a1f7c1875985328b8 (patch)
treeb0a1f77af7ab54dc5f58f569fcd1e9d84b04c533 /server/models/video/video-file.ts
parent69f224587e99d56008e1fa129d0641840a486620 (diff)
downloadPeerTube-93e1258c7cbc0d1235ca6d2a1f7c1875985328b8.tar.gz
PeerTube-93e1258c7cbc0d1235ca6d2a1f7c1875985328b8.tar.zst
PeerTube-93e1258c7cbc0d1235ca6d2a1f7c1875985328b8.zip
Move video file metadata in their own table
Will be used for user video quotas and multiple video resolutions
Diffstat (limited to 'server/models/video/video-file.ts')
-rw-r--r--server/models/video/video-file.ts89
1 files changed, 89 insertions, 0 deletions
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts
new file mode 100644
index 000000000..09a30d7e0
--- /dev/null
+++ b/server/models/video/video-file.ts
@@ -0,0 +1,89 @@
1import * as Sequelize from 'sequelize'
2import { values } from 'lodash'
3
4import { CONSTRAINTS_FIELDS } from '../../initializers'
5import {
6 isVideoFileResolutionValid,
7 isVideoFileSizeValid,
8 isVideoFileInfoHashValid
9} from '../../helpers'
10
11import { addMethodsToModel } from '../utils'
12import {
13 VideoFileInstance,
14 VideoFileAttributes
15} from './video-file-interface'
16
17let VideoFile: Sequelize.Model<VideoFileInstance, VideoFileAttributes>
18
19export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
20 VideoFile = sequelize.define<VideoFileInstance, VideoFileAttributes>('VideoFile',
21 {
22 resolution: {
23 type: DataTypes.INTEGER,
24 allowNull: false,
25 validate: {
26 resolutionValid: value => {
27 const res = isVideoFileResolutionValid(value)
28 if (res === false) throw new Error('Video file resolution is not valid.')
29 }
30 }
31 },
32 size: {
33 type: DataTypes.INTEGER,
34 allowNull: false,
35 validate: {
36 sizeValid: value => {
37 const res = isVideoFileSizeValid(value)
38 if (res === false) throw new Error('Video file size is not valid.')
39 }
40 }
41 },
42 extname: {
43 type: DataTypes.ENUM(values(CONSTRAINTS_FIELDS.VIDEOS.EXTNAME)),
44 allowNull: false
45 },
46 infoHash: {
47 type: DataTypes.STRING,
48 allowNull: false,
49 validate: {
50 infoHashValid: value => {
51 const res = isVideoFileInfoHashValid(value)
52 if (res === false) throw new Error('Video file info hash is not valid.')
53 }
54 }
55 }
56 },
57 {
58 indexes: [
59 {
60 fields: [ 'videoId' ]
61 },
62 {
63 fields: [ 'infoHash' ]
64 }
65 ]
66 }
67 )
68
69 const classMethods = [
70 associate
71 ]
72 addMethodsToModel(VideoFile, classMethods)
73
74 return VideoFile
75}
76
77// ------------------------------ STATICS ------------------------------
78
79function associate (models) {
80 VideoFile.belongsTo(models.Video, {
81 foreignKey: {
82 name: 'videoId',
83 allowNull: false
84 },
85 onDelete: 'CASCADE'
86 })
87}
88
89// ------------------------------ METHODS ------------------------------