aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/videos/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-07-29 14:50:41 +0200
committerChocobozzz <me@florianbigard.com>2022-08-01 14:55:10 +0200
commit1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7 (patch)
treea6554ee0a3ccc2ae402665b2ecf57bb38fd0ed72 /server/lib/activitypub/videos/shared
parent12d84abeca4917d2f1e3f308010bfcd56d37cb7c (diff)
downloadPeerTube-1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7.tar.gz
PeerTube-1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7.tar.zst
PeerTube-1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7.zip
Add ability to delete a specific video file
Diffstat (limited to 'server/lib/activitypub/videos/shared')
-rw-r--r--server/lib/activitypub/videos/shared/abstract-builder.ts25
1 files changed, 17 insertions, 8 deletions
diff --git a/server/lib/activitypub/videos/shared/abstract-builder.ts b/server/lib/activitypub/videos/shared/abstract-builder.ts
index f299ba4fd..c0b92c93d 100644
--- a/server/lib/activitypub/videos/shared/abstract-builder.ts
+++ b/server/lib/activitypub/videos/shared/abstract-builder.ts
@@ -1,4 +1,4 @@
1import { Transaction } from 'sequelize/types' 1import { CreationAttributes, Transaction } from 'sequelize/types'
2import { deleteAllModels, filterNonExistingModels } from '@server/helpers/database-utils' 2import { deleteAllModels, filterNonExistingModels } from '@server/helpers/database-utils'
3import { logger, LoggerTagsFn } from '@server/helpers/logger' 3import { logger, LoggerTagsFn } from '@server/helpers/logger'
4import { updatePlaceholderThumbnail, updateVideoMiniatureFromUrl } from '@server/lib/thumbnail' 4import { updatePlaceholderThumbnail, updateVideoMiniatureFromUrl } from '@server/lib/thumbnail'
@@ -7,7 +7,15 @@ import { VideoCaptionModel } from '@server/models/video/video-caption'
7import { VideoFileModel } from '@server/models/video/video-file' 7import { VideoFileModel } from '@server/models/video/video-file'
8import { VideoLiveModel } from '@server/models/video/video-live' 8import { VideoLiveModel } from '@server/models/video/video-live'
9import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' 9import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist'
10import { MStreamingPlaylistFilesVideo, MThumbnail, MVideoCaption, MVideoFile, MVideoFullLight, MVideoThumbnail } from '@server/types/models' 10import {
11 MStreamingPlaylistFiles,
12 MStreamingPlaylistFilesVideo,
13 MThumbnail,
14 MVideoCaption,
15 MVideoFile,
16 MVideoFullLight,
17 MVideoThumbnail
18} from '@server/types/models'
11import { ActivityTagObject, ThumbnailType, VideoObject, VideoStreamingPlaylistType } from '@shared/models' 19import { ActivityTagObject, ThumbnailType, VideoObject, VideoStreamingPlaylistType } from '@shared/models'
12import { getOrCreateAPActor } from '../../actors' 20import { getOrCreateAPActor } from '../../actors'
13import { checkUrlsSameHost } from '../../url' 21import { checkUrlsSameHost } from '../../url'
@@ -125,38 +133,39 @@ export abstract class APVideoAbstractBuilder {
125 // Remove video playlists that do not exist anymore 133 // Remove video playlists that do not exist anymore
126 await deleteAllModels(filterNonExistingModels(video.VideoStreamingPlaylists || [], newStreamingPlaylists), t) 134 await deleteAllModels(filterNonExistingModels(video.VideoStreamingPlaylists || [], newStreamingPlaylists), t)
127 135
136 const oldPlaylists = video.VideoStreamingPlaylists
128 video.VideoStreamingPlaylists = [] 137 video.VideoStreamingPlaylists = []
129 138
130 for (const playlistAttributes of streamingPlaylistAttributes) { 139 for (const playlistAttributes of streamingPlaylistAttributes) {
131 const streamingPlaylistModel = await this.insertOrReplaceStreamingPlaylist(playlistAttributes, t) 140 const streamingPlaylistModel = await this.insertOrReplaceStreamingPlaylist(playlistAttributes, t)
132 streamingPlaylistModel.Video = video 141 streamingPlaylistModel.Video = video
133 142
134 await this.setStreamingPlaylistFiles(video, streamingPlaylistModel, playlistAttributes.tagAPObject, t) 143 await this.setStreamingPlaylistFiles(oldPlaylists, streamingPlaylistModel, playlistAttributes.tagAPObject, t)
135 144
136 video.VideoStreamingPlaylists.push(streamingPlaylistModel) 145 video.VideoStreamingPlaylists.push(streamingPlaylistModel)
137 } 146 }
138 } 147 }
139 148
140 private async insertOrReplaceStreamingPlaylist (attributes: VideoStreamingPlaylistModel['_creationAttributes'], t: Transaction) { 149 private async insertOrReplaceStreamingPlaylist (attributes: CreationAttributes<VideoStreamingPlaylistModel>, t: Transaction) {
141 const [ streamingPlaylist ] = await VideoStreamingPlaylistModel.upsert(attributes, { returning: true, transaction: t }) 150 const [ streamingPlaylist ] = await VideoStreamingPlaylistModel.upsert(attributes, { returning: true, transaction: t })
142 151
143 return streamingPlaylist as MStreamingPlaylistFilesVideo 152 return streamingPlaylist as MStreamingPlaylistFilesVideo
144 } 153 }
145 154
146 private getStreamingPlaylistFiles (video: MVideoFullLight, type: VideoStreamingPlaylistType) { 155 private getStreamingPlaylistFiles (oldPlaylists: MStreamingPlaylistFiles[], type: VideoStreamingPlaylistType) {
147 const playlist = video.VideoStreamingPlaylists.find(s => s.type === type) 156 const playlist = oldPlaylists.find(s => s.type === type)
148 if (!playlist) return [] 157 if (!playlist) return []
149 158
150 return playlist.VideoFiles 159 return playlist.VideoFiles
151 } 160 }
152 161
153 private async setStreamingPlaylistFiles ( 162 private async setStreamingPlaylistFiles (
154 video: MVideoFullLight, 163 oldPlaylists: MStreamingPlaylistFiles[],
155 playlistModel: MStreamingPlaylistFilesVideo, 164 playlistModel: MStreamingPlaylistFilesVideo,
156 tagObjects: ActivityTagObject[], 165 tagObjects: ActivityTagObject[],
157 t: Transaction 166 t: Transaction
158 ) { 167 ) {
159 const oldStreamingPlaylistFiles = this.getStreamingPlaylistFiles(video, playlistModel.type) 168 const oldStreamingPlaylistFiles = this.getStreamingPlaylistFiles(oldPlaylists || [], playlistModel.type)
160 169
161 const newVideoFiles: MVideoFile[] = getFileAttributesFromUrl(playlistModel, tagObjects).map(a => new VideoFileModel(a)) 170 const newVideoFiles: MVideoFile[] = getFileAttributesFromUrl(playlistModel, tagObjects).map(a => new VideoFileModel(a))
162 171