aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/video/video-file.ts24
-rw-r--r--server/models/video/video-streaming-playlist.ts22
2 files changed, 43 insertions, 3 deletions
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts
index b861b0704..c14d96bc5 100644
--- a/server/models/video/video-file.ts
+++ b/server/models/video/video-file.ts
@@ -23,6 +23,7 @@ import { throwIfNotValid } from '../utils'
23import { VideoModel } from './video' 23import { VideoModel } from './video'
24import * as Sequelize from 'sequelize' 24import * as Sequelize from 'sequelize'
25import { VideoRedundancyModel } from '../redundancy/video-redundancy' 25import { VideoRedundancyModel } from '../redundancy/video-redundancy'
26import { VideoStreamingPlaylistModel } from './video-streaming-playlist'
26 27
27@Table({ 28@Table({
28 tableName: 'videoFile', 29 tableName: 'videoFile',
@@ -120,6 +121,29 @@ export class VideoFileModel extends Model<VideoFileModel> {
120 return VideoFileModel.findByPk(id, options) 121 return VideoFileModel.findByPk(id, options)
121 } 122 }
122 123
124 static listByStreamingPlaylist (streamingPlaylistId: number, transaction: Sequelize.Transaction) {
125 const query = {
126 include: [
127 {
128 model: VideoModel.unscoped(),
129 required: true,
130 include: [
131 {
132 model: VideoStreamingPlaylistModel.unscoped(),
133 required: true,
134 where: {
135 id: streamingPlaylistId
136 }
137 }
138 ]
139 }
140 ],
141 transaction
142 }
143
144 return VideoFileModel.findAll(query)
145 }
146
123 static async getStats () { 147 static async getStats () {
124 let totalLocalVideoFilesSize = await VideoFileModel.sum('size', { 148 let totalLocalVideoFilesSize = await VideoFileModel.sum('size', {
125 include: [ 149 include: [
diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts
index b147aca36..0333755c5 100644
--- a/server/models/video/video-streaming-playlist.ts
+++ b/server/models/video/video-streaming-playlist.ts
@@ -6,7 +6,7 @@ import * as Sequelize from 'sequelize'
6import { VideoRedundancyModel } from '../redundancy/video-redundancy' 6import { VideoRedundancyModel } from '../redundancy/video-redundancy'
7import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' 7import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
8import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 8import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
9import { CONSTRAINTS_FIELDS, STATIC_PATHS } from '../../initializers' 9import { CONSTRAINTS_FIELDS, STATIC_PATHS, P2P_MEDIA_LOADER_PEER_VERSION } from '../../initializers'
10import { VideoFileModel } from './video-file' 10import { VideoFileModel } from './video-file'
11import { join } from 'path' 11import { join } from 'path'
12import { sha1 } from '../../helpers/core-utils' 12import { sha1 } from '../../helpers/core-utils'
@@ -50,6 +50,10 @@ export class VideoStreamingPlaylistModel extends Model<VideoStreamingPlaylistMod
50 p2pMediaLoaderInfohashes: string[] 50 p2pMediaLoaderInfohashes: string[]
51 51
52 @AllowNull(false) 52 @AllowNull(false)
53 @Column
54 p2pMediaLoaderPeerVersion: number
55
56 @AllowNull(false)
53 @Is('VideoStreamingSegmentsSha256Url', value => throwIfNotValid(value, isActivityPubUrlValid, 'segments sha256 url')) 57 @Is('VideoStreamingSegmentsSha256Url', value => throwIfNotValid(value, isActivityPubUrlValid, 'segments sha256 url'))
54 @Column 58 @Column
55 segmentsSha256Url: string 59 segmentsSha256Url: string
@@ -92,14 +96,26 @@ export class VideoStreamingPlaylistModel extends Model<VideoStreamingPlaylistMod
92 static buildP2PMediaLoaderInfoHashes (playlistUrl: string, videoFiles: VideoFileModel[]) { 96 static buildP2PMediaLoaderInfoHashes (playlistUrl: string, videoFiles: VideoFileModel[]) {
93 const hashes: string[] = [] 97 const hashes: string[] = []
94 98
95 // https://github.com/Novage/p2p-media-loader/blob/master/p2p-media-loader-core/lib/p2p-media-manager.ts#L97 99 // https://github.com/Novage/p2p-media-loader/blob/master/p2p-media-loader-core/lib/p2p-media-manager.ts#L115
96 for (let i = 0; i < videoFiles.length; i++) { 100 for (let i = 0; i < videoFiles.length; i++) {
97 hashes.push(sha1(`1${playlistUrl}+V${i}`)) 101 hashes.push(sha1(`${P2P_MEDIA_LOADER_PEER_VERSION}${playlistUrl}+V${i}`))
98 } 102 }
99 103
100 return hashes 104 return hashes
101 } 105 }
102 106
107 static listByIncorrectPeerVersion () {
108 const query = {
109 where: {
110 p2pMediaLoaderPeerVersion: {
111 [Sequelize.Op.ne]: P2P_MEDIA_LOADER_PEER_VERSION
112 }
113 }
114 }
115
116 return VideoStreamingPlaylistModel.findAll(query)
117 }
118
103 static loadWithVideo (id: number) { 119 static loadWithVideo (id: number) {
104 const options = { 120 const options = {
105 include: [ 121 include: [