diff options
Diffstat (limited to 'server/models/video/video-source.ts')
-rw-r--r-- | server/models/video/video-source.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/server/models/video/video-source.ts b/server/models/video/video-source.ts new file mode 100644 index 000000000..e306b160d --- /dev/null +++ b/server/models/video/video-source.ts | |||
@@ -0,0 +1,55 @@ | |||
1 | import { Op } from 'sequelize' | ||
2 | import { | ||
3 | AllowNull, | ||
4 | BelongsTo, | ||
5 | Column, | ||
6 | CreatedAt, | ||
7 | ForeignKey, | ||
8 | Model, | ||
9 | Table, | ||
10 | UpdatedAt | ||
11 | } from 'sequelize-typescript' | ||
12 | import { AttributesOnly } from '@shared/typescript-utils' | ||
13 | import { VideoModel } from './video' | ||
14 | |||
15 | @Table({ | ||
16 | tableName: 'videoSource', | ||
17 | indexes: [ | ||
18 | { | ||
19 | fields: [ 'videoId' ], | ||
20 | where: { | ||
21 | videoId: { | ||
22 | [Op.ne]: null | ||
23 | } | ||
24 | } | ||
25 | } | ||
26 | ] | ||
27 | }) | ||
28 | export class VideoSourceModel extends Model<Partial<AttributesOnly<VideoSourceModel>>> { | ||
29 | @CreatedAt | ||
30 | createdAt: Date | ||
31 | |||
32 | @UpdatedAt | ||
33 | updatedAt: Date | ||
34 | |||
35 | @AllowNull(false) | ||
36 | @Column | ||
37 | filename: string | ||
38 | |||
39 | @ForeignKey(() => VideoModel) | ||
40 | @Column | ||
41 | videoId: number | ||
42 | |||
43 | @BelongsTo(() => VideoModel) | ||
44 | Video: VideoModel | ||
45 | |||
46 | static loadByVideoId (videoId) { | ||
47 | return VideoSourceModel.findOne({ where: { videoId } }) | ||
48 | } | ||
49 | |||
50 | toFormattedJSON () { | ||
51 | return { | ||
52 | filename: this.filename | ||
53 | } | ||
54 | } | ||
55 | } | ||