Fix
This commit is contained in:
		
							parent
							
								
									f3f6dce60b
								
							
						
					
					
						commit
						8afdb5aef9
					
				
					 1 changed files with 7 additions and 15 deletions
				
			
		| 
						 | 
					@ -1,37 +1,29 @@
 | 
				
			||||||
import * as express from 'express';
 | 
					import * as express from 'express';
 | 
				
			||||||
import context from '../../remote/activitypub/renderer/context';
 | 
					import context from '../../remote/activitypub/renderer/context';
 | 
				
			||||||
import render from '../../remote/activitypub/renderer/note';
 | 
					import render from '../../remote/activitypub/renderer/note';
 | 
				
			||||||
import parseAcct from '../../acct/parse';
 | 
					 | 
				
			||||||
import Post from '../../models/post';
 | 
					import Post from '../../models/post';
 | 
				
			||||||
import User from '../../models/user';
 | 
					import User from '../../models/user';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const app = express();
 | 
					const app = express();
 | 
				
			||||||
app.disable('x-powered-by');
 | 
					app.disable('x-powered-by');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app.get('/@:user/:post', async (req, res, next) => {
 | 
					app.get('/posts/:post', async (req, res, next) => {
 | 
				
			||||||
	const accepted = req.accepts(['html', 'application/activity+json', 'application/ld+json']);
 | 
						const accepted = req.accepts(['html', 'application/activity+json', 'application/ld+json']);
 | 
				
			||||||
	if (!(['application/activity+json', 'application/ld+json'] as any[]).includes(accepted)) {
 | 
						if (!(['application/activity+json', 'application/ld+json'] as any[]).includes(accepted)) {
 | 
				
			||||||
		return next();
 | 
							return next();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const { username, host } = parseAcct(req.params.user);
 | 
						const post = await Post.findOne({
 | 
				
			||||||
	if (host !== null) {
 | 
							_id: req.params.post
 | 
				
			||||||
		return res.sendStatus(422);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	const user = await User.findOne({
 | 
					 | 
				
			||||||
		usernameLower: username.toLowerCase(),
 | 
					 | 
				
			||||||
		host: null
 | 
					 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	if (user === null) {
 | 
						if (post === null) {
 | 
				
			||||||
		return res.sendStatus(404);
 | 
							return res.sendStatus(404);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const post = await Post.findOne({
 | 
						const user = await User.findOne({
 | 
				
			||||||
		_id: req.params.post,
 | 
							_id: post.userId
 | 
				
			||||||
		userId: user._id
 | 
					 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	if (post === null) {
 | 
						if (user === null) {
 | 
				
			||||||
		return res.sendStatus(404);
 | 
							return res.sendStatus(404);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue