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