Feed (#3698)
* wip * Implement feed * Update feed.ts * Update index.ts * Update feed.ts
This commit is contained in:
committed by
GitHub
parent
2a8f984db7
commit
1395cf89ce
@ -10,6 +10,7 @@ import * as favicon from 'koa-favicon';
|
||||
import * as views from 'koa-views';
|
||||
|
||||
import docs from './docs';
|
||||
import packFeed from './feed';
|
||||
import User from '../../models/user';
|
||||
import parseAcct from '../../misc/acct/parse';
|
||||
import config from '../../config';
|
||||
@ -82,6 +83,52 @@ router.use('/docs', docs.routes());
|
||||
// URL preview endpoint
|
||||
router.get('/url', require('./url-preview'));
|
||||
|
||||
const getFeed = async (acct: string) => {
|
||||
const { username, host } = parseAcct(acct);
|
||||
const user = await User.findOne({
|
||||
usernameLower: username.toLowerCase(),
|
||||
host
|
||||
});
|
||||
|
||||
return user && await packFeed(user);
|
||||
};
|
||||
|
||||
// Atom
|
||||
router.get('/@:user.atom', async ctx => {
|
||||
const feed = await getFeed(ctx.params.user);
|
||||
|
||||
if (feed) {
|
||||
ctx.set('Content-Type', 'application/atom+xml; charset=utf-8');
|
||||
ctx.body = feed.atom1();
|
||||
} else {
|
||||
ctx.status = 404;
|
||||
}
|
||||
});
|
||||
|
||||
// RSS
|
||||
router.get('/@:user.rss', async ctx => {
|
||||
const feed = await getFeed(ctx.params.user);
|
||||
|
||||
if (feed) {
|
||||
ctx.set('Content-Type', 'application/rss+xml; charset=utf-8');
|
||||
ctx.body = feed.rss2();
|
||||
} else {
|
||||
ctx.status = 404;
|
||||
}
|
||||
});
|
||||
|
||||
// JSON
|
||||
router.get('/@:user.json', async ctx => {
|
||||
const feed = await getFeed(ctx.params.user);
|
||||
|
||||
if (feed) {
|
||||
ctx.set('Content-Type', 'application/json; charset=utf-8');
|
||||
ctx.body = feed.json1();
|
||||
} else {
|
||||
ctx.status = 404;
|
||||
}
|
||||
});
|
||||
|
||||
//#region for crawlers
|
||||
// User
|
||||
router.get('/@:user', async (ctx, next) => {
|
||||
|
Reference in New Issue
Block a user