aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/actor.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/actor.ts')
-rw-r--r--server/lib/activitypub/actor.ts51
1 files changed, 31 insertions, 20 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts
index 0b21de0ca..9eabef4b0 100644
--- a/server/lib/activitypub/actor.ts
+++ b/server/lib/activitypub/actor.ts
@@ -1,6 +1,6 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { Transaction } from 'sequelize' 2import { Transaction } from 'sequelize'
3import * as url from 'url' 3import { URL } from 'url'
4import * as uuidv4 from 'uuid/v4' 4import * as uuidv4 from 'uuid/v4'
5import { ActivityPubActor, ActivityPubActorType } from '../../../shared/models/activitypub' 5import { ActivityPubActor, ActivityPubActorType } from '../../../shared/models/activitypub'
6import { ActivityPubAttributedTo } from '../../../shared/models/activitypub/objects' 6import { ActivityPubAttributedTo } from '../../../shared/models/activitypub/objects'
@@ -33,9 +33,9 @@ import {
33 MActorFull, 33 MActorFull,
34 MActorFullActor, 34 MActorFullActor,
35 MActorId, 35 MActorId,
36 MChannel, 36 MChannel
37 MChannelAccountDefault
38} from '../../typings/models' 37} from '../../typings/models'
38import { extname } from 'path'
39 39
40// Set account keys, this could be long so process after the account creation and do not block the client 40// Set account keys, this could be long so process after the account creation and do not block the client
41function setAsyncActorKeys <T extends MActor> (actor: T) { 41function setAsyncActorKeys <T extends MActor> (actor: T) {
@@ -121,13 +121,13 @@ async function getOrCreateActorAndServerAndModel (
121 121
122 if ((created === true || refreshed === true) && updateCollections === true) { 122 if ((created === true || refreshed === true) && updateCollections === true) {
123 const payload = { uri: actor.outboxUrl, type: 'activity' as 'activity' } 123 const payload = { uri: actor.outboxUrl, type: 'activity' as 'activity' }
124 await JobQueue.Instance.createJob({ type: 'activitypub-http-fetcher', payload }) 124 await JobQueue.Instance.createJobWithPromise({ type: 'activitypub-http-fetcher', payload })
125 } 125 }
126 126
127 // We created a new account: fetch the playlists 127 // We created a new account: fetch the playlists
128 if (created === true && actor.Account && accountPlaylistsUrl) { 128 if (created === true && actor.Account && accountPlaylistsUrl) {
129 const payload = { uri: accountPlaylistsUrl, accountId: actor.Account.id, type: 'account-playlists' as 'account-playlists' } 129 const payload = { uri: accountPlaylistsUrl, accountId: actor.Account.id, type: 'account-playlists' as 'account-playlists' }
130 await JobQueue.Instance.createJob({ type: 'activitypub-http-fetcher', payload }) 130 await JobQueue.Instance.createJobWithPromise({ type: 'activitypub-http-fetcher', payload })
131 } 131 }
132 132
133 return actorRefreshed 133 return actorRefreshed
@@ -215,20 +215,28 @@ async function fetchActorTotalItems (url: string) {
215 } 215 }
216} 216}
217 217
218async function getAvatarInfoIfExists (actorJSON: ActivityPubActor) { 218function getAvatarInfoIfExists (actorJSON: ActivityPubActor) {
219 if ( 219 const mimetypes = MIMETYPES.IMAGE
220 actorJSON.icon && actorJSON.icon.type === 'Image' && MIMETYPES.IMAGE.MIMETYPE_EXT[actorJSON.icon.mediaType] !== undefined && 220 const icon = actorJSON.icon
221 isActivityPubUrlValid(actorJSON.icon.url)
222 ) {
223 const extension = MIMETYPES.IMAGE.MIMETYPE_EXT[actorJSON.icon.mediaType]
224 221
225 return { 222 if (!icon || icon.type !== 'Image' || !isActivityPubUrlValid(icon.url)) return undefined
226 name: uuidv4() + extension, 223
227 fileUrl: actorJSON.icon.url 224 let extension: string
228 } 225
226 if (icon.mediaType) {
227 extension = mimetypes.MIMETYPE_EXT[icon.mediaType]
228 } else {
229 const tmp = extname(icon.url)
230
231 if (mimetypes.EXT_MIMETYPE[tmp] !== undefined) extension = tmp
229 } 232 }
230 233
231 return undefined 234 if (!extension) return undefined
235
236 return {
237 name: uuidv4() + extension,
238 fileUrl: icon.url
239 }
232} 240}
233 241
234async function addFetchOutboxJob (actor: Pick<ActorModel, 'id' | 'outboxUrl'>) { 242async function addFetchOutboxJob (actor: Pick<ActorModel, 'id' | 'outboxUrl'>) {
@@ -271,7 +279,10 @@ async function refreshActorIfNeeded <T extends MActorFull | MActorAccountChannel
271 279
272 if (statusCode === 404) { 280 if (statusCode === 404) {
273 logger.info('Deleting actor %s because there is a 404 in refresh actor.', actor.url) 281 logger.info('Deleting actor %s because there is a 404 in refresh actor.', actor.url)
274 actor.Account ? actor.Account.destroy() : actor.VideoChannel.destroy() 282 actor.Account
283 ? await actor.Account.destroy()
284 : await actor.VideoChannel.destroy()
285
275 return { actor: undefined, refreshed: false } 286 return { actor: undefined, refreshed: false }
276 } 287 }
277 288
@@ -337,14 +348,14 @@ function saveActorAndServerAndModelIfNotExist (
337 ownerActor?: MActorFullActor, 348 ownerActor?: MActorFullActor,
338 t?: Transaction 349 t?: Transaction
339): Bluebird<MActorFullActor> | Promise<MActorFullActor> { 350): Bluebird<MActorFullActor> | Promise<MActorFullActor> {
340 let actor = result.actor 351 const actor = result.actor
341 352
342 if (t !== undefined) return save(t) 353 if (t !== undefined) return save(t)
343 354
344 return sequelizeTypescript.transaction(t => save(t)) 355 return sequelizeTypescript.transaction(t => save(t))
345 356
346 async function save (t: Transaction) { 357 async function save (t: Transaction) {
347 const actorHost = url.parse(actor.url).host 358 const actorHost = new URL(actor.url).host
348 359
349 const serverOptions = { 360 const serverOptions = {
350 where: { 361 where: {
@@ -402,7 +413,7 @@ type FetchRemoteActorResult = {
402 support?: string 413 support?: string
403 playlists?: string 414 playlists?: string
404 avatar?: { 415 avatar?: {
405 name: string, 416 name: string
406 fileUrl: string 417 fileUrl: string
407 } 418 }
408 attributedTo: ActivityPubAttributedTo[] 419 attributedTo: ActivityPubAttributedTo[]