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