summaryrefslogtreecommitdiff
path: root/src/server/activitypub/with-user.ts
blob: bdbbefb4296981b15228d2910b0d2cbef47211f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import parseAcct from '../../acct/parse';
import User from '../../models/user';

export default (redirect, respond) => async (req, res, next) => {
	const { username, host } = parseAcct(req.params.user);
	if (host !== null) {
		return res.sendStatus(422);
	}

	const user = await User.findOne({
		usernameLower: username.toLowerCase(),
		host: null
	});
	if (user === null) {
		return res.sendStatus(404);
	}

	if (username !== user.username) {
		return res.redirect(redirect(user.username));
	}

	return respond(user, req, res, next);
};