mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-15 03:13:09 +02:00
987168b863
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import * as Router from 'koa-router';
|
|
import config from '../../config';
|
|
import { renderActivity } from '../../remote/activitypub/renderer';
|
|
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';
|
|
import { ensure } from '../../prelude/ensure';
|
|
|
|
export default async (ctx: Router.IRouterContext) => {
|
|
const userId = ctx.params.user;
|
|
|
|
// Verify user
|
|
const user = await Users.findOne({
|
|
id: userId,
|
|
host: null
|
|
});
|
|
|
|
if (user == null) {
|
|
ctx.status = 404;
|
|
return;
|
|
}
|
|
|
|
const pinings = await UserNotePinings.find({ userId: user.id });
|
|
|
|
const pinnedNotes = await Promise.all(pinings.map(pining =>
|
|
Notes.findOne(pining.noteId).then(ensure)));
|
|
|
|
const renderedNotes = await Promise.all(pinnedNotes.map(note => renderNote(note)));
|
|
|
|
const rendered = renderOrderedCollection(
|
|
`${config.url}/users/${userId}/collections/featured`,
|
|
renderedNotes.length, undefined, undefined, renderedNotes
|
|
);
|
|
|
|
ctx.body = renderActivity(rendered);
|
|
ctx.set('Cache-Control', 'private, max-age=0, must-revalidate');
|
|
setResponseType(ctx);
|
|
};
|