X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Factor.ts;h=9eabef4b0b175da39173af1825a62435256f7cc8;hb=9d94e5d7b96332d628ed835c67c2986289ead9b2;hp=3f6edc070cadb9a929c86e5d988a574c21eeba08;hpb=7cd1b12c19d0589d1d692ed0571ca0800f028aea;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index 3f6edc070..9eabef4b0 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts @@ -35,6 +35,7 @@ import { MActorId, MChannel } from '../../typings/models' +import { extname } from 'path' // Set account keys, this could be long so process after the account creation and do not block the client function setAsyncActorKeys (actor: T) { @@ -175,8 +176,8 @@ async function updateActorAvatarInstance (actor: MActorDefault, info: AvatarInfo if (!info.name) return actor if (actor.Avatar) { - // Don't update the avatar if the filename did not change - if (actor.Avatar.fileUrl === info.fileUrl) return actor + // Don't update the avatar if the file URL did not change + if (info.fileUrl && actor.Avatar.fileUrl === info.fileUrl) return actor try { await actor.Avatar.destroy({ transaction: t }) @@ -215,19 +216,27 @@ async function fetchActorTotalItems (url: string) { } function getAvatarInfoIfExists (actorJSON: ActivityPubActor) { - if ( - actorJSON.icon && actorJSON.icon.type === 'Image' && MIMETYPES.IMAGE.MIMETYPE_EXT[actorJSON.icon.mediaType] !== undefined && - isActivityPubUrlValid(actorJSON.icon.url) - ) { - const extension = MIMETYPES.IMAGE.MIMETYPE_EXT[actorJSON.icon.mediaType] - - return { - name: uuidv4() + extension, - fileUrl: actorJSON.icon.url - } + const mimetypes = MIMETYPES.IMAGE + const icon = actorJSON.icon + + if (!icon || icon.type !== 'Image' || !isActivityPubUrlValid(icon.url)) return undefined + + let extension: string + + if (icon.mediaType) { + extension = mimetypes.MIMETYPE_EXT[icon.mediaType] + } else { + const tmp = extname(icon.url) + + if (mimetypes.EXT_MIMETYPE[tmp] !== undefined) extension = tmp } - return undefined + if (!extension) return undefined + + return { + name: uuidv4() + extension, + fileUrl: icon.url + } } async function addFetchOutboxJob (actor: Pick) {