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 <T extends MActor> (actor: T) {
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 })
}
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<ActorModel, 'id' | 'outboxUrl'>) {