2019-09-26 22:50:34 +02:00
|
|
|
import * as Router from '@koa/router';
|
2018-09-18 06:08:27 +02:00
|
|
|
import config from '../../config';
|
2019-01-30 18:29:36 +01:00
|
|
|
import { renderActivity } from '../../remote/activitypub/renderer';
|
2018-09-18 06:08:27 +02:00
|
|
|
import renderOrderedCollection from '../../remote/activitypub/renderer/ordered-collection';
|
|
|
|
import { setResponseType } from '../activitypub';
|
|
|
|
import renderNote from '../../remote/activitypub/renderer/note';
|
2019-04-07 14:50:36 +02:00
|
|
|
import { Users, Notes, UserNotePinings } from '../../models';
|
2018-09-18 06:08:27 +02:00
|
|
|
|
2019-09-26 22:50:34 +02:00
|
|
|
export default async (ctx: Router.RouterContext) => {
|
2019-04-07 14:50:36 +02:00
|
|
|
const userId = ctx.params.user;
|
2018-09-18 06:08:27 +02:00
|
|
|
|
|
|
|
// Verify user
|
2019-04-07 14:50:36 +02:00
|
|
|
const user = await Users.findOne({
|
|
|
|
id: userId,
|
2018-09-18 06:08:27 +02:00
|
|
|
host: null
|
|
|
|
});
|
|
|
|
|
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 },
|
|
|
|
order: { id: 'DESC' }
|
|
|
|
});
|
2018-09-18 06:08:27 +02:00
|
|
|
|
2019-04-12 18:43:22 +02:00
|
|
|
const pinnedNotes = await Promise.all(pinings.map(pining =>
|
2021-02-13 07:33:38 +01:00
|
|
|
Notes.findOneOrFail(pining.noteId)));
|
2018-09-18 06:08:27 +02:00
|
|
|
|
|
|
|
const renderedNotes = await Promise.all(pinnedNotes.map(note => renderNote(note)));
|
|
|
|
|
|
|
|
const rendered = renderOrderedCollection(
|
|
|
|
`${config.url}/users/${userId}/collections/featured`,
|
2019-04-12 18:43:22 +02: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);
|
2020-05-15 14:37:09 +02:00
|
|
|
ctx.set('Cache-Control', 'public, max-age=180');
|
2018-09-18 06:08:27 +02:00
|
|
|
setResponseType(ctx);
|
|
|
|
};
|