import { addVideoShares, shareVideoByServerAndChannel } from './share'
import { AccountModel } from '../../models/account/account'
import { fetchVideoByUrl, VideoFetchByUrlType } from '../../helpers/video'
-import { checkUrlsSameHost, getAPUrl } from '../../helpers/activitypub'
+import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub'
+import { Notifier } from '../notifier'
async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) {
// If the video is not private and published, we federate it
}
async function getOrCreateVideoAndAccountAndChannel (options: {
- videoObject: VideoTorrentObject | string,
+ videoObject: { id: string } | string,
syncParam?: SyncParam,
fetchType?: VideoFetchByUrlType,
allowRefresh?: boolean // true by default
const allowRefresh = options.allowRefresh !== false
// Get video url
- const videoUrl = getAPUrl(options.videoObject)
+ const videoUrl = getAPId(options.videoObject)
let videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType)
if (videoFromDatabase) {
}
if (syncParam.refreshVideo === true) videoFromDatabase = await refreshVideoIfNeeded(refreshOptions)
- else await JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', videoUrl: videoFromDatabase.url } })
+ else await JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'video', url: videoFromDatabase.url } })
}
- return { video: videoFromDatabase }
+ return { video: videoFromDatabase, created: false }
}
const { videoObject: fetchedVideo } = await fetchRemoteVideo(videoUrl)
await syncVideoExternalAttributes(video, fetchedVideo, syncParam)
- return { video }
+ return { video, created: true }
}
async function updateVideoFromAP (options: {
overrideTo?: string[]
}) {
logger.debug('Updating remote video "%s".', options.videoObject.uuid)
+
let videoFieldsSave: any
+ const wasPrivateVideo = options.video.privacy === VideoPrivacy.PRIVATE
+ const wasUnlistedVideo = options.video.privacy === VideoPrivacy.UNLISTED
try {
await sequelizeTypescript.transaction(async t => {
- const sequelizeOptions = {
- transaction: t
- }
+ const sequelizeOptions = { transaction: t }
videoFieldsSave = options.video.toJSON()
}
})
+ // Notify our users?
+ if (wasPrivateVideo || wasUnlistedVideo) {
+ Notifier.Instance.notifyOnNewVideo(options.video)
+ }
+
logger.info('Remote video with uuid %s updated', options.videoObject.uuid)
} catch (err) {
if (options.video !== undefined && videoFieldsSave !== undefined) {