jobPayloads.push({ uri: fetchedVideo.comments, videoId: video.id, type: 'video-comments' as 'video-comments' })
}
- await Bluebird.map(jobPayloads, payload => JobQueue.Instance.createJob({ type: 'activitypub-http-fetcher', payload }))
+ await Bluebird.map(jobPayloads, payload => JobQueue.Instance.createJobWithPromise({ type: 'activitypub-http-fetcher', payload }))
}
function getOrCreateVideoAndAccountAndChannel (options: {
- videoObject: { id: string } | string,
- syncParam?: SyncParam,
- fetchType?: 'all',
+ videoObject: { id: string } | string
+ syncParam?: SyncParam
+ fetchType?: 'all'
allowRefresh?: boolean
}): Promise<{ video: MVideoAccountLightBlacklistAllFiles, created: boolean, autoBlacklisted?: boolean }>
function getOrCreateVideoAndAccountAndChannel (options: {
- videoObject: { id: string } | string,
- syncParam?: SyncParam,
- fetchType?: VideoFetchByUrlType,
+ videoObject: { id: string } | string
+ syncParam?: SyncParam
+ fetchType?: VideoFetchByUrlType
allowRefresh?: boolean
}): Promise<{ video: MVideoAccountLightBlacklistAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }>
async function getOrCreateVideoAndAccountAndChannel (options: {
- videoObject: { id: string } | string,
- syncParam?: SyncParam,
- fetchType?: VideoFetchByUrlType,
+ videoObject: { id: string } | string
+ syncParam?: SyncParam
+ fetchType?: VideoFetchByUrlType
allowRefresh?: boolean // true by default
}): Promise<{ video: MVideoAccountLightBlacklistAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }> {
// Default params
syncParam
}
- if (syncParam.refreshVideo === true) videoFromDatabase = await refreshVideoIfNeeded(refreshOptions)
- else await JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: videoFromDatabase.url } })
+ if (syncParam.refreshVideo === true) {
+ videoFromDatabase = await refreshVideoIfNeeded(refreshOptions)
+ } else {
+ await JobQueue.Instance.createJobWithPromise({
+ type: 'activitypub-refresher',
+ payload: { type: 'video', url: videoFromDatabase.url }
+ })
+ }
}
return { video: videoFromDatabase, created: false }
}
async function updateVideoFromAP (options: {
- video: MVideoAccountLightBlacklistAllFiles,
- videoObject: VideoTorrentObject,
- account: MAccountIdActor,
- channel: MChannelDefault,
+ video: MVideoAccountLightBlacklistAllFiles
+ videoObject: VideoTorrentObject
+ account: MAccountIdActor
+ channel: MChannelDefault
overrideTo?: string[]
}) {
const { video, videoObject, account, channel, overrideTo } = options
throw new Error('Account ' + account.Actor.url + ' does not own video channel ' + videoChannel.Actor.url)
}
- const to = overrideTo ? overrideTo : videoObject.to
+ const to = overrideTo || videoObject.to
const videoData = await videoActivityObjectToDBAttributes(channel, videoObject, to)
video.name = videoData.name
video.uuid = videoData.uuid
}
async function refreshVideoIfNeeded (options: {
- video: MVideoThumbnail,
- fetchedType: VideoFetchByUrlType,
+ video: MVideoThumbnail
+ fetchedType: VideoFetchByUrlType
syncParam: SyncParam
}): Promise<MVideoThumbnail> {
if (!options.video.isOutdated()) return options.video
thumbnailModel = videoCreated.id
return thumbnailModel.save()
- })
+ }).catch(err => logger.error('Cannot create miniature from url.', { err }))
}
return { autoBlacklisted, videoCreated }
}
-async function videoActivityObjectToDBAttributes (videoChannel: MChannelId, videoObject: VideoTorrentObject, to: string[] = []) {
+function videoActivityObjectToDBAttributes (videoChannel: MChannelId, videoObject: VideoTorrentObject, to: string[] = []) {
const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPrivacy.PUBLIC : VideoPrivacy.UNLISTED
const duration = videoObject.duration.replace(/[^\d]+/, '')
const mediaType = fileUrl.mediaType
const attribute = {
- extname: MIMETYPES.VIDEO.MIMETYPE_EXT[ mediaType ],
+ extname: MIMETYPES.VIDEO.MIMETYPE_EXT[mediaType],
infoHash: parsed.infoHash,
resolution: fileUrl.height,
size: fileUrl.size,