X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo.ts;h=1037730e31ac5f38db301507c7bb2e98d4eff06d;hb=c6c0fa6cd8fe8f752463d8982c3dbcd448739c4e;hp=272bba0e1c6ee08aa187a457765d47521c966cdf;hpb=d95d15598847c7f020aa056e7e6e0c02d2bbf732;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 272bba0e1..1037730e3 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -95,7 +95,7 @@ import { MVideoWithRights } from '../../types/models' import { MThumbnail } from '../../types/models/video/thumbnail' -import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../types/models/video/video-file' +import { MVideoFile, MVideoFileRedundanciesOpt, MVideoFileStreamingPlaylistVideo } from '../../types/models/video/video-file' import { VideoAbuseModel } from '../abuse/video-abuse' import { AccountModel } from '../account/account' import { AccountVideoRateModel } from '../account/account-video-rate' @@ -549,6 +549,11 @@ export class VideoModel extends Model { @Column remote: boolean + @AllowNull(false) + @Default(false) + @Column + isLive: boolean + @AllowNull(false) @Is('VideoUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max)) @@ -803,14 +808,14 @@ export class VideoModel extends Model { static async saveEssentialDataToAbuses (instance: VideoModel, options) { const tasks: Promise[] = [] - logger.info('Saving video abuses details of video %s.', instance.url) - if (!Array.isArray(instance.VideoAbuses)) { instance.VideoAbuses = await instance.$get('VideoAbuses') if (instance.VideoAbuses.length === 0) return undefined } + logger.info('Saving video abuses details of video %s.', instance.url) + const details = instance.toFormattedDetailsJSON() for (const abuse of instance.VideoAbuses) { @@ -1472,7 +1477,8 @@ export class VideoModel extends Model { } private static buildAPIResult (rows: any[]) { - const memo: { [ id: number ]: VideoModel } = {} + const videosMemo: { [ id: number ]: VideoModel } = {} + const videoStreamingPlaylistMemo: { [ id: number ]: VideoStreamingPlaylistModel } = {} const thumbnailsDone = new Set() const historyDone = new Set() @@ -1484,6 +1490,7 @@ export class VideoModel extends Model { const actorKeys = [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ] const serverKeys = [ 'id', 'host' ] const videoFileKeys = [ 'id', 'createdAt', 'updatedAt', 'resolution', 'size', 'extname', 'infoHash', 'fps', 'videoId' ] + const videoStreamingPlaylistKeys = [ 'id' ] const videoKeys = [ 'id', 'uuid', @@ -1529,7 +1536,7 @@ export class VideoModel extends Model { } for (const row of rows) { - if (!memo[row.id]) { + if (!videosMemo[row.id]) { // Build Channel const channel = row.VideoChannel const channelModel = new VideoChannelModel(pick(channel, [ 'id', 'name', 'description', 'actorId' ])) @@ -1547,13 +1554,14 @@ export class VideoModel extends Model { videoModel.UserVideoHistories = [] videoModel.Thumbnails = [] videoModel.VideoFiles = [] + videoModel.VideoStreamingPlaylists = [] - memo[row.id] = videoModel + videosMemo[row.id] = videoModel // Don't take object value to have a sorted array videos.push(videoModel) } - const videoModel = memo[row.id] + const videoModel = videosMemo[row.id] if (row.userVideoHistory?.id && !historyDone.has(row.userVideoHistory.id)) { const historyModel = new UserVideoHistoryModel(pick(row.userVideoHistory, [ 'id', 'currentTime' ])) @@ -1575,6 +1583,31 @@ export class VideoModel extends Model { videoFilesDone.add(row.VideoFiles.id) } + + if (row.VideoFiles?.id && !videoFilesDone.has(row.VideoFiles.id)) { + const videoFileModel = new VideoFileModel(pick(row.VideoFiles, videoFileKeys)) + videoModel.VideoFiles.push(videoFileModel) + + videoFilesDone.add(row.VideoFiles.id) + } + + if (row.VideoStreamingPlaylists?.id && !videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id]) { + const streamingPlaylist = new VideoStreamingPlaylistModel(pick(row.VideoStreamingPlaylists, videoStreamingPlaylistKeys)) + streamingPlaylist.VideoFiles = [] + + videoModel.VideoStreamingPlaylists.push(streamingPlaylist) + + videoStreamingPlaylistMemo[streamingPlaylist.id] = streamingPlaylist + } + + if (row.VideoStreamingPlaylists?.VideoFiles?.id && !videoFilesDone.has(row.VideoStreamingPlaylists.VideoFiles.id)) { + const streamingPlaylist = videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id] + + const videoFileModel = new VideoFileModel(pick(row.VideoStreamingPlaylists.VideoFiles, videoFileKeys)) + streamingPlaylist.VideoFiles.push(videoFileModel) + + videoFilesDone.add(row.VideoStreamingPlaylists.VideoFiles.id) + } } return videos @@ -1717,7 +1750,17 @@ export class VideoModel extends Model { getFormattedVideoFilesJSON (): VideoFile[] { const { baseUrlHttp, baseUrlWs } = this.getBaseUrls() - return videoFilesModelToFormattedJSON(this, baseUrlHttp, baseUrlWs, this.VideoFiles) + let files: MVideoFileRedundanciesOpt[] = [] + + if (Array.isArray(this.VideoFiles)) { + files = files.concat(this.VideoFiles) + } + + for (const p of (this.VideoStreamingPlaylists || [])) { + files = files.concat(p.VideoFiles || []) + } + + return videoFilesModelToFormattedJSON(this, baseUrlHttp, baseUrlWs, files) } toActivityPubObject (this: MVideoAP): VideoTorrentObject {