diff options
Diffstat (limited to 'server/lib/activitypub/process/misc.ts')
-rw-r--r-- | server/lib/activitypub/process/misc.ts | 57 |
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 @@ | |||
1 | import * as magnetUtil from 'magnet-uri' | 1 | import * as magnetUtil from 'magnet-uri' |
2 | import { VideoTorrentObject } from '../../../../shared' | 2 | import { VideoTorrentObject } from '../../../../shared' |
3 | import { VideoChannelObject } from '../../../../shared/models/activitypub/objects/video-channel-object' | 3 | import { VideoChannelObject } from '../../../../shared/models/activitypub/objects/video-channel-object' |
4 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' | ||
4 | import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos' | 5 | import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos' |
6 | import { doRequest } from '../../../helpers/requests' | ||
7 | import { database as db } from '../../../initializers' | ||
5 | import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers/constants' | 8 | import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers/constants' |
6 | import { AccountInstance } from '../../../models/account/account-interface' | 9 | import { AccountInstance } from '../../../models/account/account-interface' |
7 | import { VideoChannelInstance } from '../../../models/video/video-channel-interface' | 10 | import { VideoChannelInstance } from '../../../models/video/video-channel-interface' |
8 | import { VideoFileAttributes } from '../../../models/video/video-file-interface' | 11 | import { VideoFileAttributes } from '../../../models/video/video-file-interface' |
9 | import { VideoAttributes, VideoInstance } from '../../../models/video/video-interface' | 12 | import { VideoAttributes, VideoInstance } from '../../../models/video/video-interface' |
10 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' | 13 | import { getOrCreateAccountAndServer } from '../account' |
11 | 14 | ||
12 | function videoChannelActivityObjectToDBAttributes (videoChannelObject: VideoChannelObject, account: AccountInstance) { | 15 | function 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 | ||
103 | async 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 | |||
127 | async 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 | ||
102 | export { | 153 | export { |
103 | videoFileActivityUrlToDBAttributes, | 154 | videoFileActivityUrlToDBAttributes, |
104 | videoActivityObjectToDBAttributes, | 155 | videoActivityObjectToDBAttributes, |
105 | videoChannelActivityObjectToDBAttributes | 156 | videoChannelActivityObjectToDBAttributes, |
157 | addVideoChannelShares, | ||
158 | addVideoShares | ||
106 | } | 159 | } |