Adding components v2 support#1518
Conversation
| if (!URL.canParse(media.url)) throw new HTTPError("media URL must be a URI"); | ||
| const url = new URL(media.url); | ||
| if (!["http", "https", "attachment"].includes(url.protocol)) throw new HTTPError("invalid media protocol"); | ||
| } |
There was a problem hiding this comment.
I need some help finishing this function along with enabling the signing of the URLs where ever that happens
|
One thing we should look into is how this handles media from url sources, so there's not a tonne of duped media |
|
though, I think pk won't work in threads for obvious reasons |
|
still debugging pluralkit |
src/api/routes/interactions/#interaction_id/#interaction_token/callback.ts
Outdated
Show resolved
Hide resolved
| }); | ||
| OrmUtils.mergeDeep(user.settings || {}, body); | ||
| Member.update({ id: req.user_id, guild_id: req.params.guild_id as string }, user); | ||
| user.save(); |
There was a problem hiding this comment.
I'm not certain what this does anymore tbh
There was a problem hiding this comment.
Wait, why was it updated like that? It wasn't using the primary key
There was a problem hiding this comment.
*as in the old way
src/api/util/handlers/Message.ts
Outdated
| if (Object.keys(media).length > 1) throw new HTTPError("no, you can't send those"); | ||
| if (!URL.canParse(media.url)) throw new HTTPError("media URL must be a URI"); |
There was a problem hiding this comment.
??? what do these even mean?
There was a problem hiding this comment.
the unfurled media object can't have extra keys, and the url provided must be a valid uri
There was a problem hiding this comment.
can you make the first error more clear then?
| proxy_url: this.proxy_url | ||
| ? getUrlSignature(new NewUrlSignatureData({ ...data, url: this.proxy_url })) | ||
| .applyToUrl(this.proxy_url) | ||
| .toString() | ||
| : this.proxy_url, |
There was a problem hiding this comment.
This is wrong: this will never fall back to proxy_url as it should always be set, and it should always be signed regardless
There was a problem hiding this comment.
There was some siutation where this wasn't the case and this fixed it.
and it does seem to be optional
https://docs.discord.food/resources/components#unfurled-media-item-object
| @@ -145,11 +153,9 @@ export class Message extends BaseClass { | |||
| cascade: true, | |||
| orphanedRowAction: "delete", | |||
| }) | |||
| @JsonRemoveEmpty | |||
| attachments?: Attachment[]; | |||
|
|
|||
| @Column({ type: "simple-json" }) | |||
| @JsonRemoveEmpty | |||
There was a problem hiding this comment.
why did you remove these...?
There was a problem hiding this comment.
It's incorrect
https://docs.discord.food/resources/message#message-object
attachments can't be undefined nor can embeds
| @@ -586,14 +825,10 @@ export async function postHandleMessage(message: Message) { | |||
| if (data.embeds != undefined) { | |||
| data.embeds = data.embeds?.filter((embed) => embed.type === "rich"); | |||
| } | |||
| const author = data.author?.toPublicUser(); | |||
| const event = { | |||
| event: "MESSAGE_UPDATE", | |||
| channel_id: message.channel_id, | |||
| data: { | |||
| ...data, | |||
| author, | |||
| }, | |||
| data, | |||
There was a problem hiding this comment.
doesnt this change remove inserting the author?
There was a problem hiding this comment.
Pretty sure it gets added earlier, but it's definatly there as plularkit would've thrown a fit about it.

This will add components v2 support.
this also increases conformity to the API to make pluralkit happy, and implements two new interaction types, allows nulls in certain spots instead of undefined's and various other fixes. it was a goal to get pluralkit working for Emma and those who wanted it.