1
0
mirror of https://github.com/hotomoe/hotomoe synced 2024-12-21 10:08:07 +09:00
hotomoe/src/server/activitypub/with-user.ts

24 lines
538 B
TypeScript
Raw Normal View History

2018-04-02 13:44:32 +09:00
import parseAcct from '../../acct/parse';
2018-04-01 20:07:04 +09:00
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);
2018-04-01 22:24:44 +09:00
};