aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/misc.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-27 14:44:51 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:53 +0100
commit4e50b6a1c9a3eb261e04ede73241648e6edf21d6 (patch)
treee1c6c121d561ffc1cf2996daec03a1e7f27f0a25 /server/lib/activitypub/process/misc.ts
parent74bb2cb8348d6794ed3a0e2ec94c8c9abdde82cf (diff)
downloadPeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.tar.gz
PeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.tar.zst
PeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.zip
Add shares forward and collection on videos/video channels
Diffstat (limited to 'server/lib/activitypub/process/misc.ts')
-rw-r--r--server/lib/activitypub/process/misc.ts57
1 files changed, 55 insertions, 2 deletions
diff --git a/server/lib/activitypub/process/misc.ts b/server/lib/activitypub/process/misc.ts
index eefbe2884..f20e588ab 100644
--- a/server/lib/activitypub/process/misc.ts
+++ b/server/lib/activitypub/process/misc.ts
@@ -1,13 +1,16 @@
1import * as magnetUtil from 'magnet-uri' 1import * as magnetUtil from 'magnet-uri'
2import { VideoTorrentObject } from '../../../../shared' 2import { VideoTorrentObject } from '../../../../shared'
3import { VideoChannelObject } from '../../../../shared/models/activitypub/objects/video-channel-object' 3import { VideoChannelObject } from '../../../../shared/models/activitypub/objects/video-channel-object'
4import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
4import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos' 5import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos'
6import { doRequest } from '../../../helpers/requests'
7import { database as db } from '../../../initializers'
5import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers/constants' 8import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers/constants'
6import { AccountInstance } from '../../../models/account/account-interface' 9import { AccountInstance } from '../../../models/account/account-interface'
7import { VideoChannelInstance } from '../../../models/video/video-channel-interface' 10import { VideoChannelInstance } from '../../../models/video/video-channel-interface'
8import { VideoFileAttributes } from '../../../models/video/video-file-interface' 11import { VideoFileAttributes } from '../../../models/video/video-file-interface'
9import { VideoAttributes, VideoInstance } from '../../../models/video/video-interface' 12import { VideoAttributes, VideoInstance } from '../../../models/video/video-interface'
10import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' 13import { getOrCreateAccountAndServer } from '../account'
11 14
12function videoChannelActivityObjectToDBAttributes (videoChannelObject: VideoChannelObject, account: AccountInstance) { 15function videoChannelActivityObjectToDBAttributes (videoChannelObject: VideoChannelObject, account: AccountInstance) {
13 return { 16 return {
@@ -97,10 +100,60 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoInstance, videoO
97 return attributes 100 return attributes
98} 101}
99 102
103async function addVideoShares (instance: VideoInstance, shares: string[]) {
104 for (const share of shares) {
105 // Fetch url
106 const json = await doRequest({
107 uri: share,
108 json: true
109 })
110 const actor = json['actor']
111 if (!actor) continue
112
113 const account = await getOrCreateAccountAndServer(actor)
114
115 const entry = {
116 accountId: account.id,
117 videoId: instance.id
118 }
119
120 await db.VideoShare.findOrCreate({
121 where: entry,
122 defaults: entry
123 })
124 }
125}
126
127async function addVideoChannelShares (instance: VideoChannelInstance, shares: string[]) {
128 for (const share of shares) {
129 // Fetch url
130 const json = await doRequest({
131 uri: share,
132 json: true
133 })
134 const actor = json['actor']
135 if (!actor) continue
136
137 const account = await getOrCreateAccountAndServer(actor)
138
139 const entry = {
140 accountId: account.id,
141 videoChannelId: instance.id
142 }
143
144 await db.VideoChannelShare.findOrCreate({
145 where: entry,
146 defaults: entry
147 })
148 }
149}
150
100// --------------------------------------------------------------------------- 151// ---------------------------------------------------------------------------
101 152
102export { 153export {
103 videoFileActivityUrlToDBAttributes, 154 videoFileActivityUrlToDBAttributes,
104 videoActivityObjectToDBAttributes, 155 videoActivityObjectToDBAttributes,
105 videoChannelActivityObjectToDBAttributes 156 videoChannelActivityObjectToDBAttributes,
157 addVideoChannelShares,
158 addVideoShares
106} 159}