diff --git a/src/api/middlewares/Route.ts b/src/api/middlewares/Route.ts
index 69c2b25e..2c21dc64 100644
--- a/src/api/middlewares/Route.ts
+++ b/src/api/middlewares/Route.ts
@@ -63,6 +63,7 @@ export interface RouteOptions {
required?: boolean;
description?: string;
values?: string[];
+ default?: unknown;
};
};
deprecated?: boolean;
diff --git a/src/api/routes_toplevel/_spacebar/api/v1/channels/#channel_id/attachments.ts b/src/api/routes_toplevel/_spacebar/api/v1/channels/#channel_id/attachments.ts
index b1a0d313..0b4183d6 100644
--- a/src/api/routes_toplevel/_spacebar/api/v1/channels/#channel_id/attachments.ts
+++ b/src/api/routes_toplevel/_spacebar/api/v1/channels/#channel_id/attachments.ts
@@ -1,6 +1,6 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
- Copyright (C) 2023 Spacebar and Spacebar Contributors
+ Copyright (C) 2026 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
@@ -20,7 +20,7 @@ import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server/HTTPError";
import { FindOptionsOrderValue, LessThan, MoreThan } from "typeorm";
import { route } from "@spacebar/api/middlewares";
-import { Attachment, Channel, Message } from "@spacebar/database";
+import { Attachment, Channel } from "@spacebar/database";
import { FieldErrors, getPermission } from "@spacebar/util";
import { AttachmentListResponse } from "@spacebar/schemas/api/spacebar/AttachmentListResponse";
@@ -40,13 +40,35 @@ router.get(
body: "APIErrorResponse",
},
},
+ query: {
+ sort_order: {
+ description: "Sort order for results",
+ type: "string",
+ values: ["asc", "desc"],
+ },
+ limit: {
+ description: "Max. amount of items to return",
+ type: "number",
+ default: 50,
+ },
+ after: {
+ description: "Get results after $ATTACHMENT_ID (depends on sort_order)",
+ type: "string",
+ default: "[start based on sort_order]",
+ },
+ },
}),
async (req: Request, res: Response) => {
const { channel_id } = req.params as { [key: string]: string };
+ let { sort_order, limit, after } = req.query as { [key: string]: string };
+
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
});
- const { sort_order, limit } = req.query;
+
+ sort_order ??= "desc";
+ limit ??= "50";
+ after ??= sort_order == "asc" ? "0" : (BigInt(channel.last_message_id ?? "-1") + 1n).toString();
const parsedLimit = Number(limit) || 50;
if (parsedLimit < 1 || parsedLimit > 100) throw new HTTPError("limit must be between 1 and 100", 422);
@@ -69,7 +91,7 @@ router.get(
const atts = await Attachment.find({
where: {
channel_id: req.params.channel_id as string,
- id: (sort_order == "asc" ? MoreThan : LessThan)((req.params.after as string) ?? "0"),
+ id: (sort_order == "asc" ? MoreThan : LessThan)(after ?? "0"),
},
order: {
id: sort_order as FindOptionsOrderValue,
diff --git a/src/database/entities/Attachment.ts b/src/database/entities/Attachment.ts
index 3648696f..f0163499 100644
--- a/src/database/entities/Attachment.ts
+++ b/src/database/entities/Attachment.ts
@@ -1,6 +1,6 @@
/*
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
- Copyright (C) 2023 Spacebar and Spacebar Contributors
+ Copyright (C) 2026 Spacebar and Spacebar Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
diff --git a/src/util/util/ipc/writer/UnixSocketWriter.ts b/src/util/util/ipc/writer/UnixSocketWriter.ts
index 0930e046..ae143f7e 100644
--- a/src/util/util/ipc/writer/UnixSocketWriter.ts
+++ b/src/util/util/ipc/writer/UnixSocketWriter.ts
@@ -21,7 +21,7 @@ import fs, { FSWatcher } from "node:fs";
import path from "node:path";
import { red } from "picocolors";
import { Gauge } from "prom-client";
-import { DateBuilder, sleep, Stopwatch } from "@spacebar/extensions";
+import { sleep, Stopwatch } from "@spacebar/extensions";
import { Event } from "@spacebar/util";
import { Monitoring } from "../../../monitoring/Monitoring";
import { ProcessLifecycle } from "../../ProcessLifecycle";
|