diff options
Diffstat (limited to 'server/lib/activitypub/videos.ts')
-rw-r--r-- | server/lib/activitypub/videos.ts | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 9e43caa20..7d8296e45 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -68,7 +68,7 @@ import { | |||
68 | MVideoAPWithoutCaption, | 68 | MVideoAPWithoutCaption, |
69 | MVideoFile, | 69 | MVideoFile, |
70 | MVideoFullLight, | 70 | MVideoFullLight, |
71 | MVideoId, | 71 | MVideoId, MVideoImmutable, |
72 | MVideoThumbnail | 72 | MVideoThumbnail |
73 | } from '../../typings/models' | 73 | } from '../../typings/models' |
74 | import { MThumbnail } from '../../typings/models/video/thumbnail' | 74 | import { MThumbnail } from '../../typings/models/video/thumbnail' |
@@ -200,24 +200,41 @@ async function syncVideoExternalAttributes (video: MVideo, fetchedVideo: VideoTo | |||
200 | await Bluebird.map(jobPayloads, payload => JobQueue.Instance.createJobWithPromise({ type: 'activitypub-http-fetcher', payload })) | 200 | await Bluebird.map(jobPayloads, payload => JobQueue.Instance.createJobWithPromise({ type: 'activitypub-http-fetcher', payload })) |
201 | } | 201 | } |
202 | 202 | ||
203 | function getOrCreateVideoAndAccountAndChannel (options: { | 203 | type GetVideoResult <T> = Promise<{ |
204 | video: T | ||
205 | created: boolean | ||
206 | autoBlacklisted?: boolean | ||
207 | }> | ||
208 | |||
209 | type GetVideoParamAll = { | ||
204 | videoObject: { id: string } | string | 210 | videoObject: { id: string } | string |
205 | syncParam?: SyncParam | 211 | syncParam?: SyncParam |
206 | fetchType?: 'all' | 212 | fetchType?: 'all' |
207 | allowRefresh?: boolean | 213 | allowRefresh?: boolean |
208 | }): Promise<{ video: MVideoAccountLightBlacklistAllFiles, created: boolean, autoBlacklisted?: boolean }> | 214 | } |
209 | function getOrCreateVideoAndAccountAndChannel (options: { | 215 | |
216 | type GetVideoParamImmutable = { | ||
210 | videoObject: { id: string } | string | 217 | videoObject: { id: string } | string |
211 | syncParam?: SyncParam | 218 | syncParam?: SyncParam |
212 | fetchType?: VideoFetchByUrlType | 219 | fetchType: 'only-immutable-attributes' |
213 | allowRefresh?: boolean | 220 | allowRefresh: false |
214 | }): Promise<{ video: MVideoAccountLightBlacklistAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }> | 221 | } |
215 | async function getOrCreateVideoAndAccountAndChannel (options: { | 222 | |
223 | type GetVideoParamOther = { | ||
216 | videoObject: { id: string } | string | 224 | videoObject: { id: string } | string |
217 | syncParam?: SyncParam | 225 | syncParam?: SyncParam |
218 | fetchType?: VideoFetchByUrlType | 226 | fetchType?: 'all' | 'only-video' |
219 | allowRefresh?: boolean // true by default | 227 | allowRefresh?: boolean |
220 | }): Promise<{ video: MVideoAccountLightBlacklistAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }> { | 228 | } |
229 | |||
230 | function getOrCreateVideoAndAccountAndChannel (options: GetVideoParamAll): GetVideoResult<MVideoAccountLightBlacklistAllFiles> | ||
231 | function getOrCreateVideoAndAccountAndChannel (options: GetVideoParamImmutable): GetVideoResult<MVideoImmutable> | ||
232 | function getOrCreateVideoAndAccountAndChannel ( | ||
233 | options: GetVideoParamOther | ||
234 | ): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail> | ||
235 | async function getOrCreateVideoAndAccountAndChannel ( | ||
236 | options: GetVideoParamAll | GetVideoParamImmutable | GetVideoParamOther | ||
237 | ): GetVideoResult<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> { | ||
221 | // Default params | 238 | // Default params |
222 | const syncParam = options.syncParam || { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true, refreshVideo: false } | 239 | const syncParam = options.syncParam || { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true, refreshVideo: false } |
223 | const fetchType = options.fetchType || 'all' | 240 | const fetchType = options.fetchType || 'all' |
@@ -225,12 +242,13 @@ async function getOrCreateVideoAndAccountAndChannel (options: { | |||
225 | 242 | ||
226 | // Get video url | 243 | // Get video url |
227 | const videoUrl = getAPId(options.videoObject) | 244 | const videoUrl = getAPId(options.videoObject) |
228 | |||
229 | let videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType) | 245 | let videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType) |
246 | |||
230 | if (videoFromDatabase) { | 247 | if (videoFromDatabase) { |
231 | if (videoFromDatabase.isOutdated() && allowRefresh === true) { | 248 | // If allowRefresh is true, we could not call this function using 'only-immutable-attributes' fetch type |
249 | if (allowRefresh === true && (videoFromDatabase as MVideoThumbnail).isOutdated()) { | ||
232 | const refreshOptions = { | 250 | const refreshOptions = { |
233 | video: videoFromDatabase, | 251 | video: videoFromDatabase as MVideoThumbnail, |
234 | fetchedType: fetchType, | 252 | fetchedType: fetchType, |
235 | syncParam | 253 | syncParam |
236 | } | 254 | } |