2024-03-10 23:48:14 +01:00
|
|
|
import { apiRoute, applyConfig } from "@api";
|
2024-04-07 07:30:49 +02:00
|
|
|
import { jsonResponse } from "@response";
|
2024-04-14 02:07:05 +02:00
|
|
|
import { and, count, eq, inArray } from "drizzle-orm";
|
|
|
|
|
import { db } from "~drizzle/db";
|
2024-04-17 08:36:01 +02:00
|
|
|
import { Notes } from "~drizzle/schema";
|
2024-04-17 06:09:21 +02:00
|
|
|
import { Note } from "~packages/database-interface/note";
|
2023-11-04 04:34:31 +01:00
|
|
|
|
|
|
|
|
export const meta = applyConfig({
|
2024-04-07 07:30:49 +02:00
|
|
|
allowedMethods: ["GET"],
|
|
|
|
|
auth: {
|
|
|
|
|
required: false,
|
|
|
|
|
},
|
|
|
|
|
ratelimits: {
|
|
|
|
|
duration: 60,
|
|
|
|
|
max: 500,
|
|
|
|
|
},
|
|
|
|
|
route: "/users/:uuid/outbox",
|
2023-11-04 04:34:31 +01:00
|
|
|
});
|
|
|
|
|
|
2024-03-10 23:48:14 +01:00
|
|
|
export default apiRoute(async (req, matchedRoute, extraData) => {
|
2024-04-07 07:30:49 +02:00
|
|
|
const uuid = matchedRoute.params.uuid;
|
|
|
|
|
const pageNumber = Number(matchedRoute.query.page) || 1;
|
|
|
|
|
const config = await extraData.configManager.getConfig();
|
|
|
|
|
const host = new URL(config.http.base_url).hostname;
|
2023-11-04 04:34:31 +01:00
|
|
|
|
2024-04-17 06:09:21 +02:00
|
|
|
const notes = await Note.manyFromSql(
|
|
|
|
|
and(
|
2024-04-17 08:36:01 +02:00
|
|
|
eq(Notes.authorId, uuid),
|
|
|
|
|
inArray(Notes.visibility, ["public", "unlisted"]),
|
2024-04-17 06:09:21 +02:00
|
|
|
),
|
|
|
|
|
undefined,
|
|
|
|
|
20,
|
|
|
|
|
20 * (pageNumber - 1),
|
|
|
|
|
);
|
2023-11-04 04:34:31 +01:00
|
|
|
|
2024-04-17 06:09:21 +02:00
|
|
|
const totalNotes = await db
|
2024-04-14 02:07:05 +02:00
|
|
|
.select({
|
|
|
|
|
count: count(),
|
|
|
|
|
})
|
2024-04-17 08:36:01 +02:00
|
|
|
.from(Notes)
|
2024-04-14 02:07:05 +02:00
|
|
|
.where(
|
|
|
|
|
and(
|
2024-04-17 08:36:01 +02:00
|
|
|
eq(Notes.authorId, uuid),
|
|
|
|
|
inArray(Notes.visibility, ["public", "unlisted"]),
|
2024-04-14 02:07:05 +02:00
|
|
|
),
|
|
|
|
|
);
|
2023-11-04 04:34:31 +01:00
|
|
|
|
2024-04-07 07:30:49 +02:00
|
|
|
return jsonResponse({
|
|
|
|
|
first: `${host}/users/${uuid}/outbox?page=1`,
|
|
|
|
|
last: `${host}/users/${uuid}/outbox?page=1`,
|
2024-04-17 06:09:21 +02:00
|
|
|
total_items: totalNotes,
|
2024-04-07 07:30:49 +02:00
|
|
|
// Server actor
|
2024-04-08 05:28:18 +02:00
|
|
|
author: new URL("/users/actor", config.http.base_url).toString(),
|
2024-04-08 05:30:11 +02:00
|
|
|
next:
|
2024-04-17 06:09:21 +02:00
|
|
|
notes.length === 20
|
2024-04-08 05:30:11 +02:00
|
|
|
? new URL(
|
|
|
|
|
`/users/${uuid}/outbox?page=${pageNumber + 1}`,
|
|
|
|
|
config.http.base_url,
|
|
|
|
|
).toString()
|
|
|
|
|
: undefined,
|
|
|
|
|
prev:
|
|
|
|
|
pageNumber > 1
|
|
|
|
|
? new URL(
|
|
|
|
|
`/users/${uuid}/outbox?page=${pageNumber - 1}`,
|
|
|
|
|
config.http.base_url,
|
|
|
|
|
).toString()
|
2024-04-07 07:30:49 +02:00
|
|
|
: undefined,
|
2024-04-17 06:09:21 +02:00
|
|
|
items: notes.map((note) => note.toLysand()),
|
2024-04-07 07:30:49 +02:00
|
|
|
});
|
2024-03-10 23:48:14 +01:00
|
|
|
});
|