mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-22 18:07:31 -07:00
Merge branch 'develop' of codeberg.org:thatonecalculator/calckey into develop
This commit is contained in:
commit
57ef973cdc
1 changed files with 70 additions and 31 deletions
|
@ -232,8 +232,43 @@ const getFeed = async (acct: string) => {
|
|||
return user && await packFeed(user);
|
||||
};
|
||||
|
||||
// As the /@user[.json|.rss|.atom]/sub endpoint is complicated, we will use a regex to switch between them.
|
||||
const reUser = new RegExp(`^/@(?<user>[^/]+?)(?:\.(?<feed>json|rss|atom))?(?:/(?<sub>[^/]+))?$`);
|
||||
router.get(reUser, async (ctx, next) => {
|
||||
const groups = reUser.exec(ctx.originalUrl)?.groups;
|
||||
if (!groups) {
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.params = groups;
|
||||
|
||||
console.log(ctx, ctx.params)
|
||||
if (groups.feed) {
|
||||
if (groups.sub) {
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (groups.feed) {
|
||||
case 'json':
|
||||
await jsonFeed(ctx, next);
|
||||
break;
|
||||
case 'rss':
|
||||
await rssFeed(ctx, next);
|
||||
break;
|
||||
case 'atom':
|
||||
await atomFeed(ctx, next);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
await userPage(ctx, next);
|
||||
});
|
||||
|
||||
// Atom
|
||||
router.get('/@:user.atom', async ctx => {
|
||||
const atomFeed: Router.Middleware = async ctx => {
|
||||
const feed = await getFeed(ctx.params.user);
|
||||
|
||||
if (feed) {
|
||||
|
@ -242,10 +277,10 @@ router.get('/@:user.atom', async ctx => {
|
|||
} else {
|
||||
ctx.status = 404;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// RSS
|
||||
router.get('/@:user.rss', async ctx => {
|
||||
const rssFeed: Router.Middleware = async ctx => {
|
||||
const feed = await getFeed(ctx.params.user);
|
||||
|
||||
if (feed) {
|
||||
|
@ -254,10 +289,10 @@ router.get('/@:user.rss', async ctx => {
|
|||
} else {
|
||||
ctx.status = 404;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// JSON
|
||||
router.get('/@:user.json', async ctx => {
|
||||
const jsonFeed: Router.Middleware = async ctx => {
|
||||
const feed = await getFeed(ctx.params.user);
|
||||
|
||||
if (feed) {
|
||||
|
@ -266,19 +301,26 @@ router.get('/@:user.json', async ctx => {
|
|||
} else {
|
||||
ctx.status = 404;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//#region SSR (for crawlers)
|
||||
// User
|
||||
router.get(['/@:user', '/@:user/:sub'], async (ctx, next) => {
|
||||
const { username, host } = Acct.parse(ctx.params.user);
|
||||
const userPage: Router.Middleware = async (ctx, next) => {
|
||||
const userParam = ctx.params.user;
|
||||
const subParam = ctx.params.sub;
|
||||
const { username, host } = Acct.parse(userParam);
|
||||
|
||||
const user = await Users.findOneBy({
|
||||
usernameLower: username.toLowerCase(),
|
||||
host: host ?? IsNull(),
|
||||
isSuspended: false,
|
||||
});
|
||||
|
||||
if (user != null) {
|
||||
if (user === null) {
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
||||
const profile = await UserProfiles.findOneByOrFail({ userId: user.id });
|
||||
const meta = await fetchMeta();
|
||||
const me = profile.fields
|
||||
|
@ -287,22 +329,19 @@ router.get(['/@:user', '/@:user/:sub'], async (ctx, next) => {
|
|||
.map(field => field.value)
|
||||
: [];
|
||||
|
||||
await ctx.render('user', {
|
||||
const userDetail = {
|
||||
user, profile, me,
|
||||
avatarUrl: await Users.getAvatarUrl(user),
|
||||
sub: ctx.params.sub,
|
||||
sub: subParam,
|
||||
instanceName: meta.name || 'Calckey',
|
||||
icon: meta.iconUrl,
|
||||
themeColor: meta.themeColor,
|
||||
privateMode: meta.privateMode,
|
||||
});
|
||||
};
|
||||
|
||||
await ctx.render('user', userDetail);
|
||||
ctx.set('Cache-Control', 'public, max-age=15');
|
||||
} else {
|
||||
// リモートユーザーなので
|
||||
// モデレータがAPI経由で参照可能にするために404にはしない
|
||||
await next();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
router.get('/users/:user', async ctx => {
|
||||
const user = await Users.findOneBy({
|
||||
|
|
Loading…
Reference in a new issue