1
0
Fork 0

Filter out invalid images from peertube

This commit is contained in:
Chocobozzz 2022-11-23 16:23:22 +01:00
parent 3299c9e124
commit 5800f354cc
No known key found for this signature in database
GPG key ID: 583A612D890159BE

View file

@ -35,31 +35,33 @@ function getImagesInfoFromObject (actorObject: ActivityPubActor, type: ActorImag
? actorObject.icons || actorObject.icon ? actorObject.icons || actorObject.icon
: actorObject.image : actorObject.image
return normalizeIconOrImage(iconsOrImages).map(iconOrImage => { return normalizeIconOrImage(iconsOrImages)
const mimetypes = MIMETYPES.IMAGE .map(iconOrImage => {
const mimetypes = MIMETYPES.IMAGE
if (iconOrImage.type !== 'Image' || !isActivityPubUrlValid(iconOrImage.url)) return undefined if (iconOrImage.type !== 'Image' || !isActivityPubUrlValid(iconOrImage.url)) return undefined
let extension: string let extension: string
if (iconOrImage.mediaType) { if (iconOrImage.mediaType) {
extension = mimetypes.MIMETYPE_EXT[iconOrImage.mediaType] extension = mimetypes.MIMETYPE_EXT[iconOrImage.mediaType]
} else { } else {
const tmp = getLowercaseExtension(iconOrImage.url) const tmp = getLowercaseExtension(iconOrImage.url)
if (mimetypes.EXT_MIMETYPE[tmp] !== undefined) extension = tmp if (mimetypes.EXT_MIMETYPE[tmp] !== undefined) extension = tmp
} }
if (!extension) return undefined if (!extension) return undefined
return { return {
name: buildUUID() + extension, name: buildUUID() + extension,
fileUrl: iconOrImage.url, fileUrl: iconOrImage.url,
height: iconOrImage.height, height: iconOrImage.height,
width: iconOrImage.width, width: iconOrImage.width,
type type
} }
}) })
.filter(i => !!i)
} }
function getActorDisplayNameFromObject (actorObject: ActivityPubActor) { function getActorDisplayNameFromObject (actorObject: ActivityPubActor) {