diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-14 17:38:41 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-19 10:53:16 +0100 |
commit | 50d6de9c286abcb34ff4234d56d9cbb803db7665 (patch) | |
tree | f1732b27edcd05c7877a8358b8312f1e38c287ed /server/lib/activitypub/process/misc.ts | |
parent | fadf619ad61a016c1c7fc53de5a8f398a4f77519 (diff) | |
download | PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.gz PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.zst PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.zip |
Begin moving video channel to actor
Diffstat (limited to 'server/lib/activitypub/process/misc.ts')
-rw-r--r-- | server/lib/activitypub/process/misc.ts | 52 |
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 @@ | |||
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' | ||
4 | import { VideoPrivacy } from '../../../../shared/models/videos' | 3 | import { VideoPrivacy } from '../../../../shared/models/videos' |
5 | import { doRequest } from '../../../helpers' | 4 | import { doRequest } from '../../../helpers' |
6 | import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos' | 5 | import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos' |
7 | import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers' | 6 | import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers' |
8 | import { AccountModel } from '../../../models/account/account' | ||
9 | import { VideoModel } from '../../../models/video/video' | 7 | import { VideoModel } from '../../../models/video/video' |
10 | import { VideoChannelModel } from '../../../models/video/video-channel' | 8 | import { VideoChannelModel } from '../../../models/video/video-channel' |
11 | import { VideoChannelShareModel } from '../../../models/video/video-channel-share' | ||
12 | import { VideoShareModel } from '../../../models/video/video-share' | 9 | import { VideoShareModel } from '../../../models/video/video-share' |
13 | import { getOrCreateAccountAndServer } from '../account' | 10 | import { getOrCreateActorAndServerAndModel } from '../actor' |
14 | |||
15 | function 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 | ||
28 | async function videoActivityObjectToDBAttributes ( | 12 | async 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 | ||
140 | async 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 | ||
166 | export { | 126 | export { |
167 | videoFileActivityUrlToDBAttributes, | 127 | videoFileActivityUrlToDBAttributes, |
168 | videoActivityObjectToDBAttributes, | 128 | videoActivityObjectToDBAttributes, |
169 | videoChannelActivityObjectToDBAttributes, | ||
170 | addVideoChannelShares, | ||
171 | addVideoShares | 129 | addVideoShares |
172 | } | 130 | } |