2022-02-27 02:07:39 +00:00
|
|
|
import Router from '@koa/router';
|
|
|
|
import config from '@/config/index.js';
|
|
|
|
import { renderActivity } from '@/remote/activitypub/renderer/index.js';
|
|
|
|
import renderOrderedCollection from '@/remote/activitypub/renderer/ordered-collection.js';
|
|
|
|
import { setResponseType } from '../activitypub.js';
|
|
|
|
import renderNote from '@/remote/activitypub/renderer/note.js';
|
|
|
|
import { Users, Notes, UserNotePinings } from '@/models/index.js';
|
2022-03-26 06:34:00 +00:00
|
|
|
import { IsNull } from 'typeorm';
|
2018-09-18 04:08:27 +00:00
|
|
|
|
2019-09-26 20:50:34 +00:00
|
|
|
export default async (ctx: Router.RouterContext) => {
|
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;
|
|
|
|
}
|
|
|
|
|
2019-05-12 00:37:00 +00:00
|
|
|
const pinings = await UserNotePinings.find({
|
|
|
|
where: { userId: user.id },
|
2021-12-09 14:58:30 +00:00
|
|
|
order: { id: 'DESC' },
|
2019-05-12 00:37:00 +00:00
|
|
|
});
|
2018-09-18 04:08:27 +00:00
|
|
|
|
2019-04-12 16:43:22 +00:00
|
|
|
const pinnedNotes = await Promise.all(pinings.map(pining =>
|
2022-03-26 06:34:00 +00:00
|
|
|
Notes.findOneByOrFail({ id: pining.noteId })));
|
2018-09-18 04:08:27 +00:00
|
|
|
|
|
|
|
const renderedNotes = await Promise.all(pinnedNotes.map(note => renderNote(note)));
|
|
|
|
|
|
|
|
const rendered = renderOrderedCollection(
|
|
|
|
`${config.url}/users/${userId}/collections/featured`,
|
2022-02-03 12:20:25 +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);
|
2020-05-15 12:37:09 +00:00
|
|
|
ctx.set('Cache-Control', 'public, max-age=180');
|
2018-09-18 04:08:27 +00:00
|
|
|
setResponseType(ctx);
|
|
|
|
};
|