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