2023-01-13 05:40:33 +01:00
|
|
|
import { IsNull } from "typeorm";
|
|
|
|
import config from "@/config/index.js";
|
|
|
|
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
|
|
|
import renderOrderedCollection from "@/remote/activitypub/renderer/ordered-collection.js";
|
|
|
|
import renderNote from "@/remote/activitypub/renderer/note.js";
|
|
|
|
import { Users, Notes, UserNotePinings } from "@/models/index.js";
|
|
|
|
import { checkFetch } from "@/remote/activitypub/check-fetch.js";
|
|
|
|
import { fetchMeta } from "@/misc/fetch-meta.js";
|
|
|
|
import { setResponseType } from "../activitypub.js";
|
|
|
|
import type Router from "@koa/router";
|
2018-09-18 06:08:27 +02:00
|
|
|
|
2019-09-26 22:50:34 +02:00
|
|
|
export default async (ctx: Router.RouterContext) => {
|
2021-07-20 18:45:41 +02:00
|
|
|
const verify = await checkFetch(ctx.req);
|
2023-01-03 18:12:26 +01:00
|
|
|
if (verify !== 200) {
|
2021-07-20 18:45:41 +02:00
|
|
|
ctx.status = verify;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
const userId = ctx.params.user;
|
2018-09-18 06:08:27 +02:00
|
|
|
|
2022-03-26 07:34:00 +01:00
|
|
|
const user = await Users.findOneBy({
|
2019-04-07 14:50:36 +02:00
|
|
|
id: userId,
|
2022-03-26 07:34:00 +01:00
|
|
|
host: IsNull(),
|
2022-03-25 05:11:52 +01:00
|
|
|
});
|
2018-09-18 06:08:27 +02:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
if (user == null) {
|
2018-09-18 06:08:27 +02:00
|
|
|
ctx.status = 404;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-12 02:37:00 +02:00
|
|
|
const pinings = await UserNotePinings.find({
|
|
|
|
where: { userId: user.id },
|
2023-01-13 05:40:33 +01:00
|
|
|
order: { id: "DESC" },
|
2019-05-12 02:37:00 +02:00
|
|
|
});
|
2018-09-18 06:08:27 +02:00
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
const pinnedNotes = await Promise.all(
|
|
|
|
pinings.map((pining) => Notes.findOneByOrFail({ id: pining.noteId })),
|
|
|
|
);
|
2018-09-18 06:08:27 +02:00
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
const renderedNotes = await Promise.all(
|
|
|
|
pinnedNotes.map((note) => renderNote(note)),
|
|
|
|
);
|
2018-09-18 06:08:27 +02:00
|
|
|
|
|
|
|
const rendered = renderOrderedCollection(
|
|
|
|
`${config.url}/users/${userId}/collections/featured`,
|
2023-01-13 05:40:33 +01:00
|
|
|
renderedNotes.length,
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
renderedNotes,
|
2018-09-18 06:08:27 +02:00
|
|
|
);
|
|
|
|
|
2019-01-30 18:29:36 +01:00
|
|
|
ctx.body = renderActivity(rendered);
|
2021-07-20 18:45:41 +02:00
|
|
|
|
|
|
|
const meta = await fetchMeta();
|
|
|
|
if (meta.secureMode || meta.privateMode) {
|
2023-01-13 05:40:33 +01:00
|
|
|
ctx.set("Cache-Control", "private, max-age=0, must-revalidate");
|
2021-07-20 18:45:41 +02:00
|
|
|
} else {
|
2023-01-13 05:40:33 +01:00
|
|
|
ctx.set("Cache-Control", "public, max-age=180");
|
2021-07-20 18:45:41 +02:00
|
|
|
}
|
2018-09-18 06:08:27 +02:00
|
|
|
setResponseType(ctx);
|
|
|
|
};
|