diff options
Diffstat (limited to 'server/lib/activitypub/videos')
-rw-r--r-- | server/lib/activitypub/videos/refresh.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/videos/shared/abstract-builder.ts | 12 | ||||
-rw-r--r-- | server/lib/activitypub/videos/shared/object-to-model-attributes.ts | 13 |
3 files changed, 14 insertions, 13 deletions
diff --git a/server/lib/activitypub/videos/refresh.ts b/server/lib/activitypub/videos/refresh.ts index a7b82f286..3af08acf4 100644 --- a/server/lib/activitypub/videos/refresh.ts +++ b/server/lib/activitypub/videos/refresh.ts | |||
@@ -4,7 +4,7 @@ import { ActorFollowScoreCache } from '@server/lib/files-cache' | |||
4 | import { VideoLoadByUrlType } from '@server/lib/model-loaders' | 4 | import { VideoLoadByUrlType } from '@server/lib/model-loaders' |
5 | import { VideoModel } from '@server/models/video/video' | 5 | import { VideoModel } from '@server/models/video/video' |
6 | import { MVideoAccountLightBlacklistAllFiles, MVideoThumbnail } from '@server/types/models' | 6 | import { MVideoAccountLightBlacklistAllFiles, MVideoThumbnail } from '@server/types/models' |
7 | import { HttpStatusCode } from '@shared/core-utils' | 7 | import { HttpStatusCode } from '@shared/models' |
8 | import { fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared' | 8 | import { fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared' |
9 | import { APVideoUpdater } from './updater' | 9 | import { APVideoUpdater } from './updater' |
10 | 10 | ||
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 @@ | |||
1 | import { Transaction } from 'sequelize/types' | 1 | import { Transaction } from 'sequelize/types' |
2 | import { checkUrlsSameHost } from '@server/helpers/activitypub' | 2 | import { checkUrlsSameHost } from '@server/helpers/activitypub' |
3 | import { deleteNonExistingModels } from '@server/helpers/database-utils' | 3 | import { deleteAllModels, filterNonExistingModels } from '@server/helpers/database-utils' |
4 | import { logger, LoggerTagsFn } from '@server/helpers/logger' | 4 | import { logger, LoggerTagsFn } from '@server/helpers/logger' |
5 | import { updatePlaceholderThumbnail, updateVideoMiniatureFromUrl } from '@server/lib/thumbnail' | 5 | import { updatePlaceholderThumbnail, updateVideoMiniatureFromUrl } from '@server/lib/thumbnail' |
6 | import { setVideoTags } from '@server/lib/video' | 6 | import { setVideoTags } from '@server/lib/video' |
@@ -111,8 +111,7 @@ export abstract class APVideoAbstractBuilder { | |||
111 | const newVideoFiles = videoFileAttributes.map(a => new VideoFileModel(a)) | 111 | const newVideoFiles = videoFileAttributes.map(a => new VideoFileModel(a)) |
112 | 112 | ||
113 | // Remove video files that do not exist anymore | 113 | // Remove video files that do not exist anymore |
114 | const destroyTasks = deleteNonExistingModels(video.VideoFiles || [], newVideoFiles, t) | 114 | await deleteAllModels(filterNonExistingModels(video.VideoFiles || [], newVideoFiles), t) |
115 | await Promise.all(destroyTasks) | ||
116 | 115 | ||
117 | // Update or add other one | 116 | // Update or add other one |
118 | const upsertTasks = newVideoFiles.map(f => VideoFileModel.customUpsert(f, 'video', t)) | 117 | const upsertTasks = newVideoFiles.map(f => VideoFileModel.customUpsert(f, 'video', t)) |
@@ -124,13 +123,11 @@ export abstract class APVideoAbstractBuilder { | |||
124 | const newStreamingPlaylists = streamingPlaylistAttributes.map(a => new VideoStreamingPlaylistModel(a)) | 123 | const newStreamingPlaylists = streamingPlaylistAttributes.map(a => new VideoStreamingPlaylistModel(a)) |
125 | 124 | ||
126 | // Remove video playlists that do not exist anymore | 125 | // Remove video playlists that do not exist anymore |
127 | const destroyTasks = deleteNonExistingModels(video.VideoStreamingPlaylists || [], newStreamingPlaylists, t) | 126 | await deleteAllModels(filterNonExistingModels(video.VideoStreamingPlaylists || [], newStreamingPlaylists), t) |
128 | await Promise.all(destroyTasks) | ||
129 | 127 | ||
130 | video.VideoStreamingPlaylists = [] | 128 | video.VideoStreamingPlaylists = [] |
131 | 129 | ||
132 | for (const playlistAttributes of streamingPlaylistAttributes) { | 130 | for (const playlistAttributes of streamingPlaylistAttributes) { |
133 | |||
134 | const streamingPlaylistModel = await this.insertOrReplaceStreamingPlaylist(playlistAttributes, t) | 131 | const streamingPlaylistModel = await this.insertOrReplaceStreamingPlaylist(playlistAttributes, t) |
135 | streamingPlaylistModel.Video = video | 132 | streamingPlaylistModel.Video = video |
136 | 133 | ||
@@ -163,8 +160,7 @@ export abstract class APVideoAbstractBuilder { | |||
163 | 160 | ||
164 | const newVideoFiles: MVideoFile[] = getFileAttributesFromUrl(playlistModel, tagObjects).map(a => new VideoFileModel(a)) | 161 | const newVideoFiles: MVideoFile[] = getFileAttributesFromUrl(playlistModel, tagObjects).map(a => new VideoFileModel(a)) |
165 | 162 | ||
166 | const destroyTasks = deleteNonExistingModels(oldStreamingPlaylistFiles, newVideoFiles, t) | 163 | await deleteAllModels(filterNonExistingModels(oldStreamingPlaylistFiles, newVideoFiles), t) |
167 | await Promise.all(destroyTasks) | ||
168 | 164 | ||
169 | // Update or add other one | 165 | // Update or add other one |
170 | const upsertTasks = newVideoFiles.map(f => VideoFileModel.customUpsert(f, 'streaming-playlist', t)) | 166 | 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' | |||
7 | import { getExtFromMimetype } from '@server/helpers/video' | 7 | import { getExtFromMimetype } from '@server/helpers/video' |
8 | import { ACTIVITY_PUB, MIMETYPES, P2P_MEDIA_LOADER_PEER_VERSION, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '@server/initializers/constants' | 8 | import { ACTIVITY_PUB, MIMETYPES, P2P_MEDIA_LOADER_PEER_VERSION, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '@server/initializers/constants' |
9 | import { generateTorrentFileName } from '@server/lib/video-paths' | 9 | import { generateTorrentFileName } from '@server/lib/video-paths' |
10 | import { VideoCaptionModel } from '@server/models/video/video-caption' | ||
10 | import { VideoFileModel } from '@server/models/video/video-file' | 11 | import { VideoFileModel } from '@server/models/video/video-file' |
11 | import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' | 12 | import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist' |
12 | import { FilteredModelAttributes } from '@server/types' | 13 | import { FilteredModelAttributes } from '@server/types' |
13 | import { MChannelId, MStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoId } from '@server/types/models' | 14 | import { isStreamingPlaylist, MChannelId, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoId } from '@server/types/models' |
14 | import { | 15 | import { |
15 | ActivityHashTagObject, | 16 | ActivityHashTagObject, |
16 | ActivityMagnetUrlObject, | 17 | ActivityMagnetUrlObject, |
@@ -23,7 +24,6 @@ import { | |||
23 | VideoPrivacy, | 24 | VideoPrivacy, |
24 | VideoStreamingPlaylistType | 25 | VideoStreamingPlaylistType |
25 | } from '@shared/models' | 26 | } from '@shared/models' |
26 | import { VideoCaptionModel } from '@server/models/video/video-caption' | ||
27 | 27 | ||
28 | function getThumbnailFromIcons (videoObject: VideoObject) { | 28 | function getThumbnailFromIcons (videoObject: VideoObject) { |
29 | let validIcons = videoObject.icon.filter(i => i.width > THUMBNAILS_SIZE.minWidth) | 29 | let validIcons = videoObject.icon.filter(i => i.width > THUMBNAILS_SIZE.minWidth) |
@@ -80,8 +80,8 @@ function getFileAttributesFromUrl ( | |||
80 | 80 | ||
81 | const extname = getExtFromMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT, fileUrl.mediaType) | 81 | const extname = getExtFromMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT, fileUrl.mediaType) |
82 | const resolution = fileUrl.height | 82 | const resolution = fileUrl.height |
83 | const videoId = (videoOrPlaylist as MStreamingPlaylist).playlistUrl ? null : videoOrPlaylist.id | 83 | const videoId = isStreamingPlaylist(videoOrPlaylist) ? null : videoOrPlaylist.id |
84 | const videoStreamingPlaylistId = (videoOrPlaylist as MStreamingPlaylist).playlistUrl ? videoOrPlaylist.id : null | 84 | const videoStreamingPlaylistId = isStreamingPlaylist(videoOrPlaylist) ? videoOrPlaylist.id : null |
85 | 85 | ||
86 | const attribute = { | 86 | const attribute = { |
87 | extname, | 87 | extname, |
@@ -130,8 +130,13 @@ function getStreamingPlaylistAttributesFromObject (video: MVideoId, videoObject: | |||
130 | 130 | ||
131 | const attribute = { | 131 | const attribute = { |
132 | type: VideoStreamingPlaylistType.HLS, | 132 | type: VideoStreamingPlaylistType.HLS, |
133 | |||
134 | playlistFilename: basename(playlistUrlObject.href), | ||
133 | playlistUrl: playlistUrlObject.href, | 135 | playlistUrl: playlistUrlObject.href, |
136 | |||
137 | segmentsSha256Filename: basename(segmentsSha256UrlObject.href), | ||
134 | segmentsSha256Url: segmentsSha256UrlObject.href, | 138 | segmentsSha256Url: segmentsSha256UrlObject.href, |
139 | |||
135 | p2pMediaLoaderInfohashes: VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlistUrlObject.href, files), | 140 | p2pMediaLoaderInfohashes: VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlistUrlObject.href, files), |
136 | p2pMediaLoaderPeerVersion: P2P_MEDIA_LOADER_PEER_VERSION, | 141 | p2pMediaLoaderPeerVersion: P2P_MEDIA_LOADER_PEER_VERSION, |
137 | videoId: video.id, | 142 | videoId: video.id, |