Use id in uri instead of username
This commit is contained in:
@ -5,7 +5,7 @@ import { createHttp } from '../../queue';
|
||||
|
||||
const app = express.Router();
|
||||
|
||||
app.post('/@:user/inbox', bodyParser.json({
|
||||
app.post('/users/:user/inbox', bodyParser.json({
|
||||
type() {
|
||||
return true;
|
||||
}
|
||||
|
@ -4,23 +4,25 @@ import renderNote from '../../remote/activitypub/renderer/note';
|
||||
import renderOrderedCollection from '../../remote/activitypub/renderer/ordered-collection';
|
||||
import config from '../../config';
|
||||
import Note from '../../models/note';
|
||||
import withUser from './with-user';
|
||||
import User from '../../models/user';
|
||||
|
||||
const app = express.Router();
|
||||
|
||||
app.get('/@:user/outbox', withUser(username => {
|
||||
return `${config.url}/@${username}/inbox`;
|
||||
}, async (user, req, res) => {
|
||||
app.get('/users/:user/outbox', async (req, res) => {
|
||||
const userId = req.params.user;
|
||||
|
||||
const user = await User.findOne({ _id: userId });
|
||||
|
||||
const notes = await Note.find({ userId: user._id }, {
|
||||
limit: 20,
|
||||
sort: { _id: -1 }
|
||||
});
|
||||
|
||||
const renderedNotes = await Promise.all(notes.map(note => renderNote(note)));
|
||||
const rendered = renderOrderedCollection(`${config.url}/@${user.username}/inbox`, user.notesCount, renderedNotes);
|
||||
const rendered = renderOrderedCollection(`${config.url}/users/${userId}/inbox`, user.notesCount, renderedNotes);
|
||||
rendered['@context'] = context;
|
||||
|
||||
res.json(rendered);
|
||||
}));
|
||||
});
|
||||
|
||||
export default app;
|
||||
|
@ -1,18 +1,19 @@
|
||||
import * as express from 'express';
|
||||
import context from '../../remote/activitypub/renderer/context';
|
||||
import render from '../../remote/activitypub/renderer/key';
|
||||
import config from '../../config';
|
||||
import withUser from './with-user';
|
||||
import User from '../../models/user';
|
||||
|
||||
const app = express.Router();
|
||||
|
||||
app.get('/@:user/publickey', withUser(username => {
|
||||
return `${config.url}/@${username}/publickey`;
|
||||
}, (user, req, res) => {
|
||||
app.get('/users/:user/publickey', async (req, res) => {
|
||||
const userId = req.params.user;
|
||||
|
||||
const user = await User.findOne({ _id: userId });
|
||||
|
||||
const rendered = render(user);
|
||||
rendered['@context'] = context;
|
||||
|
||||
res.json(rendered);
|
||||
}));
|
||||
});
|
||||
|
||||
export default app;
|
||||
|
@ -1,26 +1,19 @@
|
||||
import * as express from 'express';
|
||||
import config from '../../config';
|
||||
import context from '../../remote/activitypub/renderer/context';
|
||||
import render from '../../remote/activitypub/renderer/person';
|
||||
import withUser from './with-user';
|
||||
import User from '../../models/user';
|
||||
|
||||
const app = express.Router();
|
||||
|
||||
app.get('/users/:user', async (req, res) => {
|
||||
const userId = req.params.user;
|
||||
|
||||
const user = await User.findOne({ _id: userId });
|
||||
|
||||
const respond = withUser(username => `${config.url}/@${username}`, (user, req, res) => {
|
||||
const rendered = render(user);
|
||||
rendered['@context'] = context;
|
||||
|
||||
res.json(rendered);
|
||||
});
|
||||
|
||||
const app = express.Router();
|
||||
|
||||
app.get('/@:user', (req, res, next) => {
|
||||
const accepted = req.accepts(['html', 'application/activity+json', 'application/ld+json']);
|
||||
|
||||
if ((['application/activity+json', 'application/ld+json'] as any[]).includes(accepted)) {
|
||||
respond(req, res, next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
export default app;
|
||||
|
@ -1,23 +0,0 @@
|
||||
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);
|
||||
};
|
Reference in New Issue
Block a user