'image/png': '.png',
'image/jpg': '.jpg',
'image/jpeg': '.jpg'
- }
+ },
+ EXT_MIMETYPE: null as { [ id: string ]: string }
},
VIDEO_CAPTIONS: {
MIMETYPE_EXT: {
}
}
MIMETYPES.AUDIO.EXT_MIMETYPE = invert(MIMETYPES.AUDIO.MIMETYPE_EXT)
+MIMETYPES.IMAGE.EXT_MIMETYPE = invert(MIMETYPES.IMAGE.MIMETYPE_EXT)
// ---------------------------------------------------------------------------
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) {
}
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
+
+ const extension = icon.mediaType
+ ? mimetypes.MIMETYPE_EXT[icon.mediaType]
+ : extname(icon.url)
- return undefined
+ if (!extension) return undefined
+
+ return {
+ name: uuidv4() + extension,
+ fileUrl: icon.url
+ }
}
async function addFetchOutboxJob (actor: Pick<ActorModel, 'id' | 'outboxUrl'>) {