aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/misc.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/process/misc.ts')
-rw-r--r--server/lib/activitypub/process/misc.ts52
1 files changed, 5 insertions, 47 deletions
diff --git a/server/lib/activitypub/process/misc.ts b/server/lib/activitypub/process/misc.ts
index a775c858a..a9c6f913c 100644
--- a/server/lib/activitypub/process/misc.ts
+++ b/server/lib/activitypub/process/misc.ts
@@ -1,29 +1,13 @@
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'
4import { VideoPrivacy } from '../../../../shared/models/videos' 3import { VideoPrivacy } from '../../../../shared/models/videos'
5import { doRequest } from '../../../helpers' 4import { doRequest } from '../../../helpers'
6import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos' 5import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos'
7import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers' 6import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers'
8import { AccountModel } from '../../../models/account/account'
9import { VideoModel } from '../../../models/video/video' 7import { VideoModel } from '../../../models/video/video'
10import { VideoChannelModel } from '../../../models/video/video-channel' 8import { VideoChannelModel } from '../../../models/video/video-channel'
11import { VideoChannelShareModel } from '../../../models/video/video-channel-share'
12import { VideoShareModel } from '../../../models/video/video-share' 9import { VideoShareModel } from '../../../models/video/video-share'
13import { getOrCreateAccountAndServer } from '../account' 10import { getOrCreateActorAndServerAndModel } from '../actor'
14
15function videoChannelActivityObjectToDBAttributes (videoChannelObject: VideoChannelObject, account: AccountModel) {
16 return {
17 name: videoChannelObject.name,
18 description: videoChannelObject.content,
19 uuid: videoChannelObject.uuid,
20 url: videoChannelObject.id,
21 createdAt: new Date(videoChannelObject.published),
22 updatedAt: new Date(videoChannelObject.updated),
23 remote: true,
24 accountId: account.id
25 }
26}
27 11
28async function videoActivityObjectToDBAttributes ( 12async function videoActivityObjectToDBAttributes (
29 videoChannel: VideoChannelModel, 13 videoChannel: VideoChannelModel,
@@ -120,13 +104,13 @@ async function addVideoShares (instance: VideoModel, shares: string[]) {
120 uri: share, 104 uri: share,
121 json: true 105 json: true
122 }) 106 })
123 const actor = json['actor'] 107 const actorUrl = json['actor']
124 if (!actor) continue 108 if (!actorUrl) continue
125 109
126 const account = await getOrCreateAccountAndServer(actor) 110 const actor = await getOrCreateActorAndServerAndModel(actorUrl)
127 111
128 const entry = { 112 const entry = {
129 accountId: account.id, 113 actorId: actor.id,
130 videoId: instance.id 114 videoId: instance.id
131 } 115 }
132 116
@@ -137,36 +121,10 @@ async function addVideoShares (instance: VideoModel, shares: string[]) {
137 } 121 }
138} 122}
139 123
140async function addVideoChannelShares (instance: VideoChannelModel, shares: string[]) {
141 for (const share of shares) {
142 // Fetch url
143 const json = await doRequest({
144 uri: share,
145 json: true
146 })
147 const actor = json['actor']
148 if (!actor) continue
149
150 const account = await getOrCreateAccountAndServer(actor)
151
152 const entry = {
153 accountId: account.id,
154 videoChannelId: instance.id
155 }
156
157 await VideoChannelShareModel.findOrCreate({
158 where: entry,
159 defaults: entry
160 })
161 }
162}
163
164// --------------------------------------------------------------------------- 124// ---------------------------------------------------------------------------
165 125
166export { 126export {
167 videoFileActivityUrlToDBAttributes, 127 videoFileActivityUrlToDBAttributes,
168 videoActivityObjectToDBAttributes, 128 videoActivityObjectToDBAttributes,
169 videoChannelActivityObjectToDBAttributes,
170 addVideoChannelShares,
171 addVideoShares 129 addVideoShares
172} 130}