X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-streaming-playlist.ts;h=31dc82c541109ed56a72078928e9e9aae4b9e2f6;hb=4f0f2ab228d73dbec303914dd59b52f6cdaddf46;hp=bf6f7b0c4c465ca0a07a2f7bbcd41e7edb7f9b37;hpb=4c280004ce62bf11ddb091854c28f1e1d54a54d6;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts index bf6f7b0c4..31dc82c54 100644 --- a/server/models/video/video-streaming-playlist.ts +++ b/server/models/video/video-streaming-playlist.ts @@ -1,16 +1,16 @@ -import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' +import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, HasMany, Is, Model, Table, UpdatedAt, DataType } from 'sequelize-typescript' import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' import { throwIfNotValid } from '../utils' import { VideoModel } from './video' -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/constants' import { VideoFileModel } from './video-file' import { join } from 'path' import { sha1 } from '../../helpers/core-utils' import { isArrayOf } from '../../helpers/custom-validators/misc' +import { QueryTypes, Op } from 'sequelize' @Table({ tableName: 'videoStreamingPlaylist', @@ -49,6 +49,10 @@ export class VideoStreamingPlaylistModel extends Model throwIfNotValid(value, isActivityPubUrlValid, 'segments sha256 url')) @Column @@ -78,28 +82,38 @@ export class VideoStreamingPlaylistModel extends Model { - return results.length === 1 - }) + return VideoModel.sequelize.query(query, options) + .then(results => results.length === 1) } 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: { + [Op.ne]: P2P_MEDIA_LOADER_PEER_VERSION + } + } + } + + return VideoStreamingPlaylistModel.findAll(query) + } + static loadWithVideo (id: number) { const options = { include: [ @@ -110,7 +124,7 @@ export class VideoStreamingPlaylistModel extends Model