Make cloud uploads work

This commit is contained in:
Rory&
2025-09-29 18:38:06 +02:00
parent d007acc64e
commit f20dff80ef
4 changed files with 116 additions and 135 deletions
@@ -32,6 +32,8 @@ import {
getRights,
uploadFile,
NewUrlUserSignatureData,
MessageCreateAttachment,
MessageCreateCloudAttachment,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
@@ -93,7 +95,8 @@ router.patch(
}
} else rights.hasThrow("SELF_EDIT_MESSAGES");
//@ts-expect-error Something is wrong with message_reference here, TS complains since "channel_id" is optional in MessageCreateSchema
// no longer necessary, somehow resolved by updating the type of `attachments`...?
// //@ts-expect-error Something is wrong with message_reference here, TS complains since "channel_id" is optional in MessageCreateSchema
const new_message = await handleMessage({
...message,
// TODO: should message_reference be overridable?
@@ -172,7 +175,7 @@ router.put(
async (req: Request, res: Response) => {
const { channel_id, message_id } = req.params;
const body = req.body as MessageCreateSchema;
const attachments: Attachment[] = [];
const attachments: (MessageCreateAttachment | MessageCreateCloudAttachment)[] = body.attachments ?? [];
const rights = await getRights(req.user_id);
rights.hasThrow("SEND_MESSAGES");
@@ -39,6 +39,8 @@ import {
uploadFile,
NewUrlSignatureData,
NewUrlUserSignatureData,
MessageCreateCloudAttachment,
MessageCreateAttachment,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
@@ -51,6 +53,8 @@ import {
MoreThanOrEqual,
} from "typeorm";
import { URL } from "url";
import fetch from "node-fetch-commonjs";
import { CloudAttachment } from "../../../../../util/entities/CloudAttachment";
const router: Router = Router();
@@ -296,7 +300,7 @@ router.post(
async (req: Request, res: Response) => {
const { channel_id } = req.params;
const body = req.body as MessageCreateSchema;
const attachments: Attachment[] = [];
const attachments: (Attachment | MessageCreateAttachment | MessageCreateCloudAttachment)[] = body.attachments ?? [];
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
@@ -364,6 +368,7 @@ router.post(
const embeds = body.embeds || [];
if (body.embed) embeds.push(body.embed);
console.log("messages/index.ts: attachments:", attachments);
const message = await handleMessage({
...body,
type: 0,