diff options
author | Chocobozzz <me@florianbigard.com> | 2022-11-23 16:23:22 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-11-23 16:23:22 +0100 |
commit | 5800f354ccd4845d0b4bc212a0c53a0ff40edf82 (patch) | |
tree | 4a5bc5f2e027a53f66fc9fc4618ffac8f51076f7 | |
parent | 3299c9e124a2c1879ec24dc5635d3fb7014b7245 (diff) | |
download | PeerTube-5800f354ccd4845d0b4bc212a0c53a0ff40edf82.tar.gz PeerTube-5800f354ccd4845d0b4bc212a0c53a0ff40edf82.tar.zst PeerTube-5800f354ccd4845d0b4bc212a0c53a0ff40edf82.zip |
Filter out invalid images from peertube
-rw-r--r-- | server/lib/activitypub/actors/shared/object-to-model-attributes.ts | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/server/lib/activitypub/actors/shared/object-to-model-attributes.ts b/server/lib/activitypub/actors/shared/object-to-model-attributes.ts index f6a78c457..d854bf2b5 100644 --- a/server/lib/activitypub/actors/shared/object-to-model-attributes.ts +++ b/server/lib/activitypub/actors/shared/object-to-model-attributes.ts | |||
@@ -35,31 +35,33 @@ function getImagesInfoFromObject (actorObject: ActivityPubActor, type: ActorImag | |||
35 | ? actorObject.icons || actorObject.icon | 35 | ? actorObject.icons || actorObject.icon |
36 | : actorObject.image | 36 | : actorObject.image |
37 | 37 | ||
38 | return normalizeIconOrImage(iconsOrImages).map(iconOrImage => { | 38 | return normalizeIconOrImage(iconsOrImages) |
39 | const mimetypes = MIMETYPES.IMAGE | 39 | .map(iconOrImage => { |
40 | const mimetypes = MIMETYPES.IMAGE | ||
40 | 41 | ||
41 | if (iconOrImage.type !== 'Image' || !isActivityPubUrlValid(iconOrImage.url)) return undefined | 42 | if (iconOrImage.type !== 'Image' || !isActivityPubUrlValid(iconOrImage.url)) return undefined |
42 | 43 | ||
43 | let extension: string | 44 | let extension: string |
44 | 45 | ||
45 | if (iconOrImage.mediaType) { | 46 | if (iconOrImage.mediaType) { |
46 | extension = mimetypes.MIMETYPE_EXT[iconOrImage.mediaType] | 47 | extension = mimetypes.MIMETYPE_EXT[iconOrImage.mediaType] |
47 | } else { | 48 | } else { |
48 | const tmp = getLowercaseExtension(iconOrImage.url) | 49 | const tmp = getLowercaseExtension(iconOrImage.url) |
49 | 50 | ||
50 | if (mimetypes.EXT_MIMETYPE[tmp] !== undefined) extension = tmp | 51 | if (mimetypes.EXT_MIMETYPE[tmp] !== undefined) extension = tmp |
51 | } | 52 | } |
52 | 53 | ||
53 | if (!extension) return undefined | 54 | if (!extension) return undefined |
54 | 55 | ||
55 | return { | 56 | return { |
56 | name: buildUUID() + extension, | 57 | name: buildUUID() + extension, |
57 | fileUrl: iconOrImage.url, | 58 | fileUrl: iconOrImage.url, |
58 | height: iconOrImage.height, | 59 | height: iconOrImage.height, |
59 | width: iconOrImage.width, | 60 | width: iconOrImage.width, |
60 | type | 61 | type |
61 | } | 62 | } |
62 | }) | 63 | }) |
64 | .filter(i => !!i) | ||
63 | } | 65 | } |
64 | 66 | ||
65 | function getActorDisplayNameFromObject (actorObject: ActivityPubActor) { | 67 | function getActorDisplayNameFromObject (actorObject: ActivityPubActor) { |