mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Update P2P media loader peer version
This commit is contained in:
@@ -23,6 +23,7 @@ import { throwIfNotValid } from '../utils'
|
||||
import { VideoModel } from './video'
|
||||
import * as Sequelize from 'sequelize'
|
||||
import { VideoRedundancyModel } from '../redundancy/video-redundancy'
|
||||
import { VideoStreamingPlaylistModel } from './video-streaming-playlist'
|
||||
|
||||
@Table({
|
||||
tableName: 'videoFile',
|
||||
@@ -120,6 +121,29 @@ export class VideoFileModel extends Model<VideoFileModel> {
|
||||
return VideoFileModel.findByPk(id, options)
|
||||
}
|
||||
|
||||
static listByStreamingPlaylist (streamingPlaylistId: number, transaction: Sequelize.Transaction) {
|
||||
const query = {
|
||||
include: [
|
||||
{
|
||||
model: VideoModel.unscoped(),
|
||||
required: true,
|
||||
include: [
|
||||
{
|
||||
model: VideoStreamingPlaylistModel.unscoped(),
|
||||
required: true,
|
||||
where: {
|
||||
id: streamingPlaylistId
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
transaction
|
||||
}
|
||||
|
||||
return VideoFileModel.findAll(query)
|
||||
}
|
||||
|
||||
static async getStats () {
|
||||
let totalLocalVideoFilesSize = await VideoFileModel.sum('size', {
|
||||
include: [
|
||||
|
||||
@@ -6,7 +6,7 @@ import * as Sequelize from 'sequelize'
|
||||
import { VideoRedundancyModel } from '../redundancy/video-redundancy'
|
||||
import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
|
||||
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
|
||||
import { CONSTRAINTS_FIELDS, STATIC_PATHS } from '../../initializers'
|
||||
import { CONSTRAINTS_FIELDS, STATIC_PATHS, P2P_MEDIA_LOADER_PEER_VERSION } from '../../initializers'
|
||||
import { VideoFileModel } from './video-file'
|
||||
import { join } from 'path'
|
||||
import { sha1 } from '../../helpers/core-utils'
|
||||
@@ -49,6 +49,10 @@ export class VideoStreamingPlaylistModel extends Model<VideoStreamingPlaylistMod
|
||||
@Column(DataType.ARRAY(DataType.STRING))
|
||||
p2pMediaLoaderInfohashes: string[]
|
||||
|
||||
@AllowNull(false)
|
||||
@Column
|
||||
p2pMediaLoaderPeerVersion: number
|
||||
|
||||
@AllowNull(false)
|
||||
@Is('VideoStreamingSegmentsSha256Url', value => throwIfNotValid(value, isActivityPubUrlValid, 'segments sha256 url'))
|
||||
@Column
|
||||
@@ -92,14 +96,26 @@ export class VideoStreamingPlaylistModel extends Model<VideoStreamingPlaylistMod
|
||||
static buildP2PMediaLoaderInfoHashes (playlistUrl: string, videoFiles: VideoFileModel[]) {
|
||||
const hashes: string[] = []
|
||||
|
||||
// https://github.com/Novage/p2p-media-loader/blob/master/p2p-media-loader-core/lib/p2p-media-manager.ts#L97
|
||||
// https://github.com/Novage/p2p-media-loader/blob/master/p2p-media-loader-core/lib/p2p-media-manager.ts#L115
|
||||
for (let i = 0; i < videoFiles.length; i++) {
|
||||
hashes.push(sha1(`1${playlistUrl}+V${i}`))
|
||||
hashes.push(sha1(`${P2P_MEDIA_LOADER_PEER_VERSION}${playlistUrl}+V${i}`))
|
||||
}
|
||||
|
||||
return hashes
|
||||
}
|
||||
|
||||
static listByIncorrectPeerVersion () {
|
||||
const query = {
|
||||
where: {
|
||||
p2pMediaLoaderPeerVersion: {
|
||||
[Sequelize.Op.ne]: P2P_MEDIA_LOADER_PEER_VERSION
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return VideoStreamingPlaylistModel.findAll(query)
|
||||
}
|
||||
|
||||
static loadWithVideo (id: number) {
|
||||
const options = {
|
||||
include: [
|
||||
|
||||
Reference in New Issue
Block a user