aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/initializers/constants.ts4
-rw-r--r--server/lib/activitypub/actor.ts27
2 files changed, 18 insertions, 13 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index cb1c6f2ae..311d371a7 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -422,7 +422,8 @@ const MIMETYPES = {
422 'image/png': '.png', 422 'image/png': '.png',
423 'image/jpg': '.jpg', 423 'image/jpg': '.jpg',
424 'image/jpeg': '.jpg' 424 'image/jpeg': '.jpg'
425 } 425 },
426 EXT_MIMETYPE: null as { [ id: string ]: string }
426 }, 427 },
427 VIDEO_CAPTIONS: { 428 VIDEO_CAPTIONS: {
428 MIMETYPE_EXT: { 429 MIMETYPE_EXT: {
@@ -438,6 +439,7 @@ const MIMETYPES = {
438 } 439 }
439} 440}
440MIMETYPES.AUDIO.EXT_MIMETYPE = invert(MIMETYPES.AUDIO.MIMETYPE_EXT) 441MIMETYPES.AUDIO.EXT_MIMETYPE = invert(MIMETYPES.AUDIO.MIMETYPE_EXT)
442MIMETYPES.IMAGE.EXT_MIMETYPE = invert(MIMETYPES.IMAGE.MIMETYPE_EXT)
441 443
442// --------------------------------------------------------------------------- 444// ---------------------------------------------------------------------------
443 445
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts
index 3f6edc070..8c5c618fc 100644
--- a/server/lib/activitypub/actor.ts
+++ b/server/lib/activitypub/actor.ts
@@ -35,6 +35,7 @@ import {
35 MActorId, 35 MActorId,
36 MChannel 36 MChannel
37} from '../../typings/models' 37} from '../../typings/models'
38import { extname } from 'path'
38 39
39// 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
40function setAsyncActorKeys <T extends MActor> (actor: T) { 41function setAsyncActorKeys <T extends MActor> (actor: T) {
@@ -215,19 +216,21 @@ async function fetchActorTotalItems (url: string) {
215} 216}
216 217
217function getAvatarInfoIfExists (actorJSON: ActivityPubActor) { 218function getAvatarInfoIfExists (actorJSON: ActivityPubActor) {
218 if ( 219 const mimetypes = MIMETYPES.IMAGE
219 actorJSON.icon && actorJSON.icon.type === 'Image' && MIMETYPES.IMAGE.MIMETYPE_EXT[actorJSON.icon.mediaType] !== undefined && 220 const icon = actorJSON.icon
220 isActivityPubUrlValid(actorJSON.icon.url) 221
221 ) { 222 if (!icon || icon.type !== 'Image' || !isActivityPubUrlValid(icon.url)) return undefined
222 const extension = MIMETYPES.IMAGE.MIMETYPE_EXT[actorJSON.icon.mediaType] 223
223 224 const extension = icon.mediaType
224 return { 225 ? mimetypes.MIMETYPE_EXT[icon.mediaType]
225 name: uuidv4() + extension, 226 : extname(icon.url)
226 fileUrl: actorJSON.icon.url
227 }
228 }
229 227
230 return undefined 228 if (!extension) return undefined
229
230 return {
231 name: uuidv4() + extension,
232 fileUrl: icon.url
233 }
231} 234}
232 235
233async function addFetchOutboxJob (actor: Pick<ActorModel, 'id' | 'outboxUrl'>) { 236async function addFetchOutboxJob (actor: Pick<ActorModel, 'id' | 'outboxUrl'>) {