aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/video/video-file.ts4
-rw-r--r--server/models/video/video-format-utils.ts2
-rw-r--r--server/models/video/video-live.ts74
-rw-r--r--server/models/video/video-streaming-playlist.ts4
-rw-r--r--server/models/video/video.ts5
5 files changed, 86 insertions, 3 deletions
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts
index f95022383..6a321917c 100644
--- a/server/models/video/video-file.ts
+++ b/server/models/video/video-file.ts
@@ -123,8 +123,8 @@ export class VideoFileModel extends Model<VideoFileModel> {
123 @Column 123 @Column
124 extname: string 124 extname: string
125 125
126 @AllowNull(false) 126 @AllowNull(true)
127 @Is('VideoFileInfohash', value => throwIfNotValid(value, isVideoFileInfoHashValid, 'info hash')) 127 @Is('VideoFileInfohash', value => throwIfNotValid(value, isVideoFileInfoHashValid, 'info hash', true))
128 @Column 128 @Column
129 infoHash: string 129 infoHash: string
130 130
diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts
index ad512fc7f..0dbd92a43 100644
--- a/server/models/video/video-format-utils.ts
+++ b/server/models/video/video-format-utils.ts
@@ -77,6 +77,8 @@ function videoModelToFormattedJSON (video: MVideoFormattable, options?: VideoFor
77 publishedAt: video.publishedAt, 77 publishedAt: video.publishedAt,
78 originallyPublishedAt: video.originallyPublishedAt, 78 originallyPublishedAt: video.originallyPublishedAt,
79 79
80 isLive: video.isLive,
81
80 account: video.VideoChannel.Account.toFormattedSummaryJSON(), 82 account: video.VideoChannel.Account.toFormattedSummaryJSON(),
81 channel: video.VideoChannel.toFormattedSummaryJSON(), 83 channel: video.VideoChannel.toFormattedSummaryJSON(),
82 84
diff --git a/server/models/video/video-live.ts b/server/models/video/video-live.ts
new file mode 100644
index 000000000..6929b9688
--- /dev/null
+++ b/server/models/video/video-live.ts
@@ -0,0 +1,74 @@
1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, DefaultScope, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
2import { WEBSERVER } from '@server/initializers/constants'
3import { MVideoLive, MVideoLiveVideo } from '@server/types/models'
4import { VideoLive } from '@shared/models/videos/video-live.model'
5import { VideoModel } from './video'
6
7@DefaultScope(() => ({
8 include: [
9 {
10 model: VideoModel,
11 required: true
12 }
13 ]
14}))
15@Table({
16 tableName: 'videoLive',
17 indexes: [
18 {
19 fields: [ 'videoId' ],
20 unique: true
21 }
22 ]
23})
24export class VideoLiveModel extends Model<VideoLiveModel> {
25
26 @AllowNull(false)
27 @Column(DataType.STRING)
28 streamKey: string
29
30 @CreatedAt
31 createdAt: Date
32
33 @UpdatedAt
34 updatedAt: Date
35
36 @ForeignKey(() => VideoModel)
37 @Column
38 videoId: number
39
40 @BelongsTo(() => VideoModel, {
41 foreignKey: {
42 allowNull: false
43 },
44 onDelete: 'cascade'
45 })
46 Video: VideoModel
47
48 static loadByStreamKey (streamKey: string) {
49 const query = {
50 where: {
51 streamKey
52 }
53 }
54
55 return VideoLiveModel.findOne<MVideoLiveVideo>(query)
56 }
57
58 static loadByVideoId (videoId: number) {
59 const query = {
60 where: {
61 videoId
62 }
63 }
64
65 return VideoLiveModel.findOne<MVideoLive>(query)
66 }
67
68 toFormattedJSON (): VideoLive {
69 return {
70 rtmpUrl: WEBSERVER.RTMP_URL,
71 streamKey: this.streamKey
72 }
73 }
74}
diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts
index 021b9b063..b8dc7c450 100644
--- a/server/models/video/video-streaming-playlist.ts
+++ b/server/models/video/video-streaming-playlist.ts
@@ -173,7 +173,9 @@ export class VideoStreamingPlaylistModel extends Model<VideoStreamingPlaylistMod
173 return join(STATIC_PATHS.STREAMING_PLAYLISTS.HLS, videoUUID, VideoStreamingPlaylistModel.getHlsPlaylistFilename(resolution)) 173 return join(STATIC_PATHS.STREAMING_PLAYLISTS.HLS, videoUUID, VideoStreamingPlaylistModel.getHlsPlaylistFilename(resolution))
174 } 174 }
175 175
176 static getHlsSha256SegmentsStaticPath (videoUUID: string) { 176 static getHlsSha256SegmentsStaticPath (videoUUID: string, isLive: boolean) {
177 if (isLive) return join('/live', 'segments-sha256', videoUUID)
178
177 return join(STATIC_PATHS.STREAMING_PLAYLISTS.HLS, videoUUID, VideoStreamingPlaylistModel.getHlsSha256SegmentsFilename()) 179 return join(STATIC_PATHS.STREAMING_PLAYLISTS.HLS, videoUUID, VideoStreamingPlaylistModel.getHlsSha256SegmentsFilename())
178 } 180 }
179 181
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 410d71cb3..1037730e3 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -550,6 +550,11 @@ export class VideoModel extends Model<VideoModel> {
550 remote: boolean 550 remote: boolean
551 551
552 @AllowNull(false) 552 @AllowNull(false)
553 @Default(false)
554 @Column
555 isLive: boolean
556
557 @AllowNull(false)
553 @Is('VideoUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) 558 @Is('VideoUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url'))
554 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max)) 559 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max))
555 url: string 560 url: string