2019-09-27 05:50:34 +09:00
|
|
|
import * as Router from '@koa/router';
|
2021-03-23 17:43:07 +09:00
|
|
|
import config from '@/config';
|
2019-01-31 02:29:36 +09:00
|
|
|
import { renderActivity } from '../../remote/activitypub/renderer';
|
2018-09-18 13:08:27 +09:00
|
|
|
import renderOrderedCollection from '../../remote/activitypub/renderer/ordered-collection';
|
|
|
|
import { setResponseType } from '../activitypub';
|
|
|
|
import renderNote from '../../remote/activitypub/renderer/note';
|
2019-04-07 21:50:36 +09:00
|
|
|
import { Users, Notes, UserNotePinings } from '../../models';
|
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,
|
2018-09-18 13:08:27 +09:00
|
|
|
host: null
|
|
|
|
});
|
|
|
|
|
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 },
|
|
|
|
order: { id: 'DESC' }
|
|
|
|
});
|
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);
|
|
|
|
};
|