From 764b1a14fc494f2cfd7ea590d2f07b01df65c7ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 23 Jul 2021 11:20:00 +0200 Subject: Use random names for VOD HLS playlists --- server/lib/activitypub/videos/shared/abstract-builder.ts | 12 ++++-------- .../activitypub/videos/shared/object-to-model-attributes.ts | 13 +++++++++---- 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'server/lib/activitypub') diff --git a/server/lib/activitypub/videos/shared/abstract-builder.ts b/server/lib/activitypub/videos/shared/abstract-builder.ts index e89c94bcd..f995fe637 100644 --- a/server/lib/activitypub/videos/shared/abstract-builder.ts +++ b/server/lib/activitypub/videos/shared/abstract-builder.ts @@ -1,6 +1,6 @@ import { Transaction } from 'sequelize/types' import { checkUrlsSameHost } from '@server/helpers/activitypub' -import { deleteNonExistingModels } from '@server/helpers/database-utils' +import { deleteAllModels, filterNonExistingModels } from '@server/helpers/database-utils' import { logger, LoggerTagsFn } from '@server/helpers/logger' import { updatePlaceholderThumbnail, updateVideoMiniatureFromUrl } from '@server/lib/thumbnail' import { setVideoTags } from '@server/lib/video' @@ -111,8 +111,7 @@ export abstract class APVideoAbstractBuilder { const newVideoFiles = videoFileAttributes.map(a => new VideoFileModel(a)) // Remove video files that do not exist anymore - const destroyTasks = deleteNonExistingModels(video.VideoFiles || [], newVideoFiles, t) - await Promise.all(destroyTasks) + await deleteAllModels(filterNonExistingModels(video.VideoFiles || [], newVideoFiles), t) // Update or add other one const upsertTasks = newVideoFiles.map(f => VideoFileModel.customUpsert(f, 'video', t)) @@ -124,13 +123,11 @@ export abstract class APVideoAbstractBuilder { const newStreamingPlaylists = streamingPlaylistAttributes.map(a => new VideoStreamingPlaylistModel(a)) // Remove video playlists that do not exist anymore - const destroyTasks = deleteNonExistingModels(video.VideoStreamingPlaylists || [], newStreamingPlaylists, t) - await Promise.all(destroyTasks) + await deleteAllModels(filterNonExistingModels(video.VideoStreamingPlaylists || [], newStreamingPlaylists), t) video.VideoStreamingPlaylists = [] for (const playlistAttributes of streamingPlaylistAttributes) { - const streamingPlaylistModel = await this.insertOrReplaceStreamingPlaylist(playlistAttributes, t) streamingPlaylistModel.Video = video @@ -163,8 +160,7 @@ export abstract class APVideoAbstractBuilder { const newVideoFiles: MVideoFile[] = getFileAttributesFromUrl(playlistModel, tagObjects).map(a => new VideoFileModel(a)) - const destroyTasks = deleteNonExistingModels(oldStreamingPlaylistFiles, newVideoFiles, t) - await Promise.all(destroyTasks) + await deleteAllModels(filterNonExistingModels(oldStreamingPlaylistFiles, newVideoFiles), t) // Update or add other one const upsertTasks = newVideoFiles.map(f => VideoFileModel.customUpsert(f, 'streaming-playlist', t)) diff --git a/server/lib/activitypub/videos/shared/object-to-model-attributes.ts b/server/lib/activitypub/videos/shared/object-to-model-attributes.ts index 85548428c..1fa16295d 100644 --- a/server/lib/activitypub/videos/shared/object-to-model-attributes.ts +++ b/server/lib/activitypub/videos/shared/object-to-model-attributes.ts @@ -7,10 +7,11 @@ import { logger } from '@server/helpers/logger' import { getExtFromMimetype } from '@server/helpers/video' import { ACTIVITY_PUB, MIMETYPES, P2P_MEDIA_LOADER_PEER_VERSION, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '@server/initializers/constants' import { generateTorrentFileName } from '@server/lib/video-paths' +import { VideoCaptionModel } from '@server/models/video/video-caption' import { VideoFileModel } from '@server/models/video/video-file' import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' import { FilteredModelAttributes } from '@server/types' -import { MChannelId, MStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoId } from '@server/types/models' +import { isStreamingPlaylist, MChannelId, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoId } from '@server/types/models' import { ActivityHashTagObject, ActivityMagnetUrlObject, @@ -23,7 +24,6 @@ import { VideoPrivacy, VideoStreamingPlaylistType } from '@shared/models' -import { VideoCaptionModel } from '@server/models/video/video-caption' function getThumbnailFromIcons (videoObject: VideoObject) { let validIcons = videoObject.icon.filter(i => i.width > THUMBNAILS_SIZE.minWidth) @@ -80,8 +80,8 @@ function getFileAttributesFromUrl ( const extname = getExtFromMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT, fileUrl.mediaType) const resolution = fileUrl.height - const videoId = (videoOrPlaylist as MStreamingPlaylist).playlistUrl ? null : videoOrPlaylist.id - const videoStreamingPlaylistId = (videoOrPlaylist as MStreamingPlaylist).playlistUrl ? videoOrPlaylist.id : null + const videoId = isStreamingPlaylist(videoOrPlaylist) ? null : videoOrPlaylist.id + const videoStreamingPlaylistId = isStreamingPlaylist(videoOrPlaylist) ? videoOrPlaylist.id : null const attribute = { extname, @@ -130,8 +130,13 @@ function getStreamingPlaylistAttributesFromObject (video: MVideoId, videoObject: const attribute = { type: VideoStreamingPlaylistType.HLS, + + playlistFilename: basename(playlistUrlObject.href), playlistUrl: playlistUrlObject.href, + + segmentsSha256Filename: basename(segmentsSha256UrlObject.href), segmentsSha256Url: segmentsSha256UrlObject.href, + p2pMediaLoaderInfohashes: VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlistUrlObject.href, files), p2pMediaLoaderPeerVersion: P2P_MEDIA_LOADER_PEER_VERSION, videoId: video.id, -- cgit v1.2.3