]>
Commit | Line | Data |
---|---|---|
892211e8 | 1 | import { Transaction } from 'sequelize' |
e12a0092 | 2 | import { VideoPrivacy } from '../../../shared/models/videos' |
da854ddd | 3 | import { getServerActor } from '../../helpers/utils' |
3fd3ab2d | 4 | import { VideoModel } from '../../models/video/video' |
3fd3ab2d | 5 | import { VideoShareModel } from '../../models/video/video-share' |
07197db4 | 6 | import { sendVideoAnnounce } from './send' |
4ba3b8ea | 7 | import { getAnnounceActivityPubUrl } from './url' |
892211e8 | 8 | |
a7d647c4 | 9 | async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) { |
54b38063 | 10 | if (video.privacy === VideoPrivacy.PRIVATE) return undefined |
e12a0092 | 11 | |
50d6de9c | 12 | const serverActor = await getServerActor() |
892211e8 | 13 | |
4ba3b8ea | 14 | const serverShareUrl = getAnnounceActivityPubUrl(video.url, serverActor) |
a7977280 C |
15 | const serverSharePromise = VideoShareModel.findOrCreate({ |
16 | defaults: { | |
17 | actorId: serverActor.id, | |
18 | videoId: video.id, | |
19 | url: serverShareUrl | |
20 | }, | |
21 | where: { | |
22 | url: serverShareUrl | |
23 | }, | |
24 | transaction: t | |
25 | }).then(([ serverShare, created ]) => { | |
07197db4 | 26 | if (created) return sendVideoAnnounce(serverActor, serverShare, video, t) |
a7977280 C |
27 | |
28 | return undefined | |
29 | }) | |
892211e8 | 30 | |
4ba3b8ea | 31 | const videoChannelShareUrl = getAnnounceActivityPubUrl(video.url, video.VideoChannel.Actor) |
a7977280 C |
32 | const videoChannelSharePromise = VideoShareModel.findOrCreate({ |
33 | defaults: { | |
34 | actorId: video.VideoChannel.actorId, | |
35 | videoId: video.id, | |
36 | url: videoChannelShareUrl | |
37 | }, | |
38 | where: { | |
39 | url: videoChannelShareUrl | |
40 | }, | |
41 | transaction: t | |
42 | }).then(([ videoChannelShare, created ]) => { | |
07197db4 | 43 | if (created) return sendVideoAnnounce(serverActor, videoChannelShare, video, t) |
a7d647c4 | 44 | |
a7977280 C |
45 | return undefined |
46 | }) | |
a7d647c4 | 47 | |
4ba3b8ea | 48 | return Promise.all([ |
a7977280 C |
49 | serverSharePromise, |
50 | videoChannelSharePromise | |
4ba3b8ea | 51 | ]) |
892211e8 C |
52 | } |
53 | ||
54 | export { | |
a7d647c4 | 55 | shareVideoByServerAndChannel |
892211e8 | 56 | } |