+ return Promise.all([
+ shareByServer(video, t),
+ shareByVideoChannel(video, t)
+ ])
+}
+
+async function changeVideoChannelShare (
+ video: MVideoAccountLight,
+ oldVideoChannel: MChannelActorLight,
+ t: Transaction
+) {
+ logger.info('Updating video channel of video %s: %s -> %s.', video.uuid, oldVideoChannel.name, video.VideoChannel.name)
+
+ await undoShareByVideoChannel(video, oldVideoChannel, t)
+
+ await shareByVideoChannel(video, t)
+}
+
+async function addVideoShares (shareUrls: string[], video: MVideoId) {
+ await Bluebird.map(shareUrls, async shareUrl => {
+ try {
+ // Fetch url
+ const { body } = await doRequest({
+ uri: shareUrl,
+ json: true,
+ activityPub: true
+ })
+ if (!body || !body.actor) throw new Error('Body or body actor is invalid')
+
+ const actorUrl = getAPId(body.actor)
+ if (checkUrlsSameHost(shareUrl, actorUrl) !== true) {
+ throw new Error(`Actor url ${actorUrl} has not the same host than the share url ${shareUrl}`)
+ }
+
+ const actor = await getOrCreateActorAndServerAndModel(actorUrl)
+
+ const entry = {
+ actorId: actor.id,
+ videoId: video.id,
+ url: shareUrl
+ }
+
+ await VideoShareModel.upsert(entry)
+ } catch (err) {
+ logger.warn('Cannot add share %s.', shareUrl, { err })
+ }
+ }, { concurrency: CRAWL_REQUEST_CONCURRENCY })
+}
+
+export {
+ changeVideoChannelShare,
+ addVideoShares,
+ shareVideoByServerAndChannel
+}
+
+// ---------------------------------------------------------------------------
+
+async function shareByServer (video: MVideo, t: Transaction) {