aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/share.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-22 16:15:35 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 09:41:54 +0200
commit1297eb5db651a230474670c5da1517862fb9cc3e (patch)
treeecad4a0ceb0bb09e3c775262691ac68e9e0aca0c /server/lib/activitypub/share.ts
parentf6eebcb336c067e160a62020a5140d8d992ba384 (diff)
downloadPeerTube-1297eb5db651a230474670c5da1517862fb9cc3e.tar.gz
PeerTube-1297eb5db651a230474670c5da1517862fb9cc3e.tar.zst
PeerTube-1297eb5db651a230474670c5da1517862fb9cc3e.zip
Add refresh video on search
Diffstat (limited to 'server/lib/activitypub/share.ts')
-rw-r--r--server/lib/activitypub/share.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/server/lib/activitypub/share.ts b/server/lib/activitypub/share.ts
index 698414867..fe3d73e9b 100644
--- a/server/lib/activitypub/share.ts
+++ b/server/lib/activitypub/share.ts
@@ -6,6 +6,11 @@ import { VideoShareModel } from '../../models/video/video-share'
6import { sendUndoAnnounce, sendVideoAnnounce } from './send' 6import { sendUndoAnnounce, sendVideoAnnounce } from './send'
7import { getAnnounceActivityPubUrl } from './url' 7import { getAnnounceActivityPubUrl } from './url'
8import { VideoChannelModel } from '../../models/video/video-channel' 8import { VideoChannelModel } from '../../models/video/video-channel'
9import * as Bluebird from 'bluebird'
10import { doRequest } from '../../helpers/requests'
11import { getOrCreateActorAndServerAndModel } from './actor'
12import { logger } from '../../helpers/logger'
13import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers'
9 14
10async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) { 15async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) {
11 if (video.privacy === VideoPrivacy.PRIVATE) return undefined 16 if (video.privacy === VideoPrivacy.PRIVATE) return undefined
@@ -22,8 +27,41 @@ async function changeVideoChannelShare (video: VideoModel, oldVideoChannel: Vide
22 await shareByVideoChannel(video, t) 27 await shareByVideoChannel(video, t)
23} 28}
24 29
30async function addVideoShares (shareUrls: string[], instance: VideoModel) {
31 await Bluebird.map(shareUrls, async shareUrl => {
32 try {
33 // Fetch url
34 const { body } = await doRequest({
35 uri: shareUrl,
36 json: true,
37 activityPub: true
38 })
39 if (!body || !body.actor) throw new Error('Body of body actor is invalid')
40
41 const actorUrl = body.actor
42 const actor = await getOrCreateActorAndServerAndModel(actorUrl)
43
44 const entry = {
45 actorId: actor.id,
46 videoId: instance.id,
47 url: shareUrl
48 }
49
50 await VideoShareModel.findOrCreate({
51 where: {
52 url: shareUrl
53 },
54 defaults: entry
55 })
56 } catch (err) {
57 logger.warn('Cannot add share %s.', shareUrl, { err })
58 }
59 }, { concurrency: CRAWL_REQUEST_CONCURRENCY })
60}
61
25export { 62export {
26 changeVideoChannelShare, 63 changeVideoChannelShare,
64 addVideoShares,
27 shareVideoByServerAndChannel 65 shareVideoByServerAndChannel
28} 66}
29 67