From 2a4c182920542189f1041a61e10a09a362a89fac Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Mon, 2 Mar 2026 10:28:19 -0600 Subject: [PATCH] more pk fixes --- src/api/routes/webhooks/#webhook_id/#token/index.ts | 1 + src/api/util/handlers/Message.ts | 1 + src/api/util/handlers/route.ts | 8 ++++---- src/util/entities/Attachment.ts | 8 +++++--- src/util/entities/Message.ts | 5 ----- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/api/routes/webhooks/#webhook_id/#token/index.ts b/src/api/routes/webhooks/#webhook_id/#token/index.ts index 556ee489f..a3056e879 100644 --- a/src/api/routes/webhooks/#webhook_id/#token/index.ts +++ b/src/api/routes/webhooks/#webhook_id/#token/index.ts @@ -66,6 +66,7 @@ router.post( }, route({ requestBody: "WebhookExecuteSchema", + stripNulls: true, query: { wait: { type: "boolean", diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts index b96dfc9f9..ca3034a3e 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts @@ -773,6 +773,7 @@ export async function postHandleMessage(message: Message) { const linkMatches = content?.match(LINK_REGEX) || []; message.clean_data(); const data = { ...message.toJSON() }; + console.log(message); const currentNormalizedUrls = new Set(); for (const link of linkMatches) { diff --git a/src/api/util/handlers/route.ts b/src/api/util/handlers/route.ts index 175015246..fbaebf84d 100644 --- a/src/api/util/handlers/route.ts +++ b/src/api/util/handlers/route.ts @@ -52,7 +52,7 @@ export interface RouteOptions { body?: string; }; }; - stripNulls?: stripNulls; + stripNulls?: stripNulls | true; event?: EVENT | EVENT[]; summary?: string; description?: string; @@ -75,7 +75,6 @@ export interface RouteOptions { // }; } export function stripNull(obj: object) { - console.log(Object.entries(obj)); for (const [key, value] of Object.entries(obj)) { if (value instanceof Object || (value && !value.__proto__)) { stripNull(value); @@ -137,11 +136,11 @@ export function route(opts: RouteOptions) { if (validate && !ignoredRequestSchemas.includes(opts.requestBody!)) { if (opts.stripNulls) { - followNullPath(req.body, opts.stripNulls); + if (opts.stripNulls === true) stripNull(req.body); + else followNullPath(req.body, opts.stripNulls); } const valid = validate(req.body); if (!valid) { - console.log(JSON.stringify(req.body)); const fields: Record = {}; validate.errors?.forEach( (x) => @@ -151,6 +150,7 @@ export function route(opts: RouteOptions) { }), ); if (process.env.LOG_VALIDATION_ERRORS) console.log(`[VALIDATION ERROR] ${req.method} ${req.originalUrl} - SCHEMA='${opts.requestBody}' -`, validate?.errors); + if (process.env.LOG_VALIDATION_ERROR_BODY) console.log(JSON.stringify(req.body)); throw FieldErrors(fields, validate.errors!); } } diff --git a/src/util/entities/Attachment.ts b/src/util/entities/Attachment.ts index c6858eb8e..f3e11bc5c 100644 --- a/src/util/entities/Attachment.ts +++ b/src/util/entities/Attachment.ts @@ -68,9 +68,11 @@ export class Attachment extends BaseClass { url: getUrlSignature(new NewUrlSignatureData({ ...data, url: this.url })) .applyToUrl(this.url) .toString(), - proxy_url: getUrlSignature(new NewUrlSignatureData({ ...data, url: this.proxy_url })) - .applyToUrl(this.proxy_url) - .toString(), + proxy_url: this.proxy_url + ? getUrlSignature(new NewUrlSignatureData({ ...data, url: this.proxy_url })) + .applyToUrl(this.proxy_url) + .toString() + : this.proxy_url, }; } } diff --git a/src/util/entities/Message.ts b/src/util/entities/Message.ts index 885e51c40..bcac2b0cb 100644 --- a/src/util/entities/Message.ts +++ b/src/util/entities/Message.ts @@ -134,17 +134,14 @@ export class Message extends BaseClass { mention_everyone?: boolean; @JoinTable({ name: "message_user_mentions" }) - @JsonRemoveEmpty @ManyToMany(() => User) mentions: User[]; @JoinTable({ name: "message_role_mentions" }) - @JsonRemoveEmpty @ManyToMany(() => Role) mention_roles: Role[]; @JoinTable({ name: "message_channel_mentions" }) - @JsonRemoveEmpty @ManyToMany(() => Channel) mention_channels: Channel[]; @@ -156,11 +153,9 @@ export class Message extends BaseClass { cascade: true, orphanedRowAction: "delete", }) - @JsonRemoveEmpty attachments?: Attachment[]; @Column({ type: "simple-json" }) - @JsonRemoveEmpty embeds: Embed[]; @Column({ type: "simple-json" })